-
Notifications
You must be signed in to change notification settings - Fork 74
Multi-fidelity surrogate models #721
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
base: dev/mfbo
Are you sure you want to change the base?
Changes from all commits
995cbf8
686fc86
18ec63e
d3d0c2f
585ad16
e4b28a7
eca58ef
88db97f
32a0ffd
b3fdbf1
adef8ce
700c9d4
af34847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,10 @@ | |
| from baybe.constraints.base import Constraint | ||
| from baybe.parameters import TaskParameter | ||
| from baybe.parameters.base import Parameter | ||
| from baybe.parameters.fidelity import ( | ||
| CategoricalFidelityParameter, | ||
| NumericalDiscreteFidelityParameter, | ||
| ) | ||
| from baybe.searchspace.continuous import SubspaceContinuous | ||
| from baybe.searchspace.discrete import ( | ||
| MemorySize, | ||
|
|
@@ -48,6 +52,29 @@ class SearchSpaceType(Enum): | |
| """Flag for hybrid search spaces resp. compatibility with hybrid search spaces.""" | ||
|
|
||
|
|
||
| class SearchSpaceTaskType(Enum): | ||
| """Enum class for different types of task and/or fidelity subspaces.""" | ||
|
|
||
| SINGLETASK = "SINGLETASK" | ||
|
jpenn2023 marked this conversation as resolved.
|
||
| """Flag for search spaces with a single task, meaning no task parameter.""" | ||
|
|
||
| CATEGORICALMULTITASK = "CATEGORICALMULTITASK" | ||
| """Flag for search spaces with a categorical task parameter.""" | ||
|
|
||
|
|
||
| class SearchSpaceFidelityType(Enum): | ||
| """Enum class for different types of task and/or fidelity subspaces.""" | ||
|
|
||
| SINGLEFIDELITY = "SINGLEFIDELITY" | ||
| """Flag for search spaces with a single fidelity, meaning no fidelity parameter.""" | ||
|
|
||
| NUMERICALDISCRETEMULTIFIDELITY = "NUMERICALDISCRETEMULTIFIDELITY" | ||
| """Flag for search spaces with a discrete numerical (ordered) fidelity parameter.""" | ||
|
|
||
| CATEGORICALMULTIFIDELITY = "CATEGORICALMULTIFIDELITY" | ||
| """Flag for search spaces with a categorical (unordered) fidelity parameter.""" | ||
|
|
||
|
|
||
| @define | ||
| class SearchSpace(SerialMixin): | ||
| """Class for managing the overall search space. | ||
|
|
@@ -258,15 +285,32 @@ def _task_parameter(self) -> TaskParameter | None: | |
| if not params: | ||
| return None | ||
|
|
||
| assert len(params) == 1 # currently ensured by parameter validation step | ||
| return params[0] | ||
|
|
||
| @property | ||
| def _fidelity_parameter( | ||
| self, | ||
| ) -> NumericalDiscreteFidelityParameter | CategoricalFidelityParameter | None: | ||
| """The (single) fidelity parameter of the space, if it exists.""" | ||
| # Currently private, see comment above | ||
| fidelity_parameters = ( | ||
| NumericalDiscreteFidelityParameter, | ||
| CategoricalFidelityParameter, | ||
| ) | ||
|
|
||
| params = [p for p in self.parameters if isinstance(p, fidelity_parameters)] | ||
|
|
||
| if not params: | ||
| return None | ||
|
|
||
| return params[0] | ||
|
|
||
| @property | ||
| def task_idx(self) -> int | None: | ||
| """The column index of the task parameter in computational representation.""" | ||
| """Column index of the task parameter in computational representation.""" | ||
| if (task_param := self._task_parameter) is None: | ||
| return None | ||
| # TODO[11611]: The current approach has three limitations: | ||
| # TODO [11611]: The current approach has three limitations: | ||
| # 1. It matches by column name and thus assumes that the parameter name | ||
| # is used as the column name. | ||
| # 2. It relies on the current implementation detail that discrete parameters | ||
|
|
@@ -275,6 +319,14 @@ def task_idx(self) -> int | None: | |
| # --> Fix this when refactoring the data | ||
| return cast(int, self.discrete.comp_rep.columns.get_loc(task_param.name)) | ||
|
|
||
| @property | ||
| def fidelity_idx(self) -> int | None: | ||
| """Column index of the fidelity parameter in computational representation.""" | ||
| if (fidelity_param := self._fidelity_parameter) is None: | ||
| return None | ||
| # See TODO [11611] above | ||
|
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. Please remove the number and directly refer to the corresponding function, that is, have it as |
||
| return cast(int, self.discrete.comp_rep.columns.get_loc(fidelity_param.name)) | ||
|
|
||
| @property | ||
| def n_tasks(self) -> int: | ||
| """The number of tasks encoded in the search space.""" | ||
|
|
@@ -287,6 +339,54 @@ def n_tasks(self) -> int: | |
| return 1 | ||
| return len(task_param.values) | ||
|
|
||
| @property | ||
| def n_fidelities(self) -> int: | ||
| """The number of fidelities encoded in the search space.""" | ||
| # See TODO [16932] above | ||
|
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. Please remove the number and directly refer to the corresponding function, that is, have it as |
||
| if (fidelity_param := self._fidelity_parameter) is None: | ||
| # When there are no task parameters, we effectively have a single task | ||
| return 1 | ||
| return len(fidelity_param.values) | ||
|
|
||
| @property | ||
| def task_type(self) -> SearchSpaceTaskType: | ||
| """Return the task type of the search space.""" | ||
| task_parameters = (p for p in self.parameters if isinstance(p, TaskParameter)) | ||
|
|
||
| if len(task_parameters) == 0: | ||
| return SearchSpaceTaskType.SINGLETASK | ||
| elif len(task_parameters) == 1: | ||
| return SearchSpaceTaskType.CATEGORICALMULTITASK | ||
| else: | ||
| raise NotImplementedError( | ||
| "BayBE does not currently support search" | ||
| "spaces with multiple task parameters." | ||
| ) | ||
|
|
||
| def fidelity_type(self) -> SearchSpaceFidelityType: | ||
|
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. Shouldn't this also be a property? |
||
| """Return the fidelity type of the search space.""" | ||
| fidelity_parameters = ( | ||
| CategoricalFidelityParameter, | ||
| NumericalDiscreteFidelityParameter, | ||
| ) | ||
|
|
||
| fidelity_parameters = ( | ||
| p for p in self.parameters if isinstance(p, fidelity_parameters) | ||
| ) | ||
|
|
||
| if len(fidelity_parameters) == 0: | ||
| return SearchSpaceFidelityType.SINGLEFIDELITY | ||
| elif len(fidelity_parameters) == 1: | ||
| if isinstance(fidelity_parameters[0], CategoricalFidelityParameter): | ||
| return SearchSpaceFidelityType.CATEGORICALMULTIFIDELITY | ||
| if isinstance(fidelity_parameters[0], NumericalDiscreteFidelityParameter): | ||
| return SearchSpaceFidelityType.NUMERICALDISCRETEMULTIFIDELITY | ||
| else: | ||
| raise NotImplementedError( | ||
| "BayBE does not currently support search" | ||
| "spaces with multiple fidelity parameters." | ||
| ) | ||
|
|
||
| def get_comp_rep_parameter_indices(self, name: str, /) -> tuple[int, ...]: | ||
| """Find a parameter's column indices in the computational representation. | ||
|
|
||
|
|
@@ -386,7 +486,7 @@ def transform( | |
|
|
||
| @property | ||
| def constraints_augmentable(self) -> tuple[Constraint, ...]: | ||
| """The searchspace constraints that can be considered during augmentation.""" | ||
| """The search space constraints that can be considered during augmentation.""" | ||
| return tuple(c for c in self.constraints if c.eval_during_augmentation) | ||
|
|
||
| def get_parameters_by_name(self, names: Sequence[str]) -> tuple[Parameter, ...]: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.