-
Notifications
You must be signed in to change notification settings - Fork 45
674 bug discrete variables in doe #742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dlinzner-bcs
wants to merge
3
commits into
main
Choose a base branch
from
674-bug-discrete-variables-in-doe
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import importlib.util | ||
| import re | ||
| import sys | ||
| import warnings | ||
| from copy import copy | ||
| from itertools import combinations | ||
| from typing import List, Optional, Tuple, Union, cast | ||
|
|
@@ -22,7 +23,11 @@ | |
| NonlinearInequalityConstraint, | ||
| ) | ||
| from bofire.data_models.domain.api import Domain, Inputs | ||
| from bofire.data_models.features.api import CategoricalInput, NumericalInput | ||
| from bofire.data_models.features.api import ( | ||
| CategoricalInput, | ||
| DiscreteInput, | ||
| NumericalInput, | ||
| ) | ||
| from bofire.data_models.features.continuous import ContinuousInput | ||
| from bofire.data_models.strategies.api import RandomStrategy as RandomStrategyDataModel | ||
| from bofire.strategies.doe.doe_problem import ( | ||
|
|
@@ -78,9 +83,20 @@ def formula_str_to_fully_continuous( | |
| pattern = r"\b" + re.escape(cat_input.key) + r"\b" | ||
| formula = re.sub(pattern, "(" + f"{one_hot_terms}" + ")", formula) | ||
|
|
||
| return str( | ||
| Formula(formula) | ||
| formula = Formula( | ||
| formula | ||
| ) # formula casting for expansion of terms like (a+b)*(c+d) | ||
| for _input in inputs.get([DiscreteInput]): | ||
| for k in range( | ||
| 2, 99 | ||
| ): # arbitrary upper bound on number of levels of discrete input | ||
| if (len(_input.values) <= k) and (_input.key + f" ** {k}" in formula.root): | ||
| warnings.warn( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so now it gives a warning but continues. i guess that is fine. alternatively we could throw a value error I guess |
||
| f"Discrete input {_input.key} with {len(_input.values)} levels cannot represent a term of order {k} or higher.", | ||
| UserWarning, | ||
| ) | ||
| break | ||
| return str(formula) | ||
|
|
||
|
|
||
| def get_formula_from_string( | ||
|
|
@@ -92,8 +108,7 @@ def get_formula_from_string( | |
|
|
||
| Args: | ||
| model_type (str or Formula): A formula containing all model terms. | ||
| domain (Domain): A domain that nests necessary information on | ||
| how to translate a problem to a formula. Contains a problem. | ||
| inputs (Inputs, optional): The inputs to be used in the formula. Defaults to None. If the model_type is a string describing a model type (e.g. "linear"), inputs must be provided to determine the formula. If the model_type is already a formula, inputs are not necessary and ignored if provided. | ||
| rhs_only (bool): The function returns only the right hand side of the formula if set to True. | ||
|
|
||
| Returns: | ||
|
|
@@ -239,8 +254,11 @@ def quadratic_terms( | |
| A string describing the model that was given as string or keyword. | ||
|
|
||
| """ | ||
| _inputs = list(inputs.get([ContinuousInput])) + [ | ||
| input for input in inputs.get([DiscreteInput]) if len(input.values) > 2 | ||
| ] | ||
|
|
||
| formula = "".join(["{" + input.key + "**2} + " for input in inputs]) | ||
| formula = "".join(["{" + input.key + "**2} + " for input in _inputs]) | ||
| return formula | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add sth like len(_input.values)+1 instead of 99 which is arbitary?