Skip to content

Commit

Permalink
Make 'n_threshold_inactive_parameters_generator' an attribute of botorch
Browse files Browse the repository at this point in the history
recommender
  • Loading branch information
Waschenbacher committed Jul 12, 2024
1 parent 9d28b49 commit f68ce4f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ _ `_optional` subpackage for managing optional dependencies
`DiscreteCardinalityConstraint`/`ContinuousCardinalityConstraint` subclasses
- Uniform sampling mechanism for continuous spaces with cardinality constraints
- Enable `ContinuousCardinalityConstraint` in `BotorchRecommender`
- Attribute `n_threshold_inactive_parameters_generator` added to `BotorchRecommender`
- Properties `combinatorial_zero_parameters` and
`combinatorial_counts_zero_parameters` in both `ContinuousCardinalityConstraint`and
`SubspaceContinuous`
Expand Down
21 changes: 13 additions & 8 deletions baybe/recommenders/pure/bayesian/botorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from attr.converters import optional
from attrs import define, field
from attrs.validators import ge, instance_of

from baybe.constraints import ContinuousCardinalityConstraint
from baybe.exceptions import NoMCAcquisitionFunctionError
Expand All @@ -27,12 +28,6 @@
if TYPE_CHECKING:
from torch import Tensor

N_THRESHOLD_INACTIVE_PARAMETERS_GENERATOR: int = 10
"""This threshold controls which inactive parameters generator is chosen. There are
two mechanisms:
* Iterating the combinatorial list of all possible inactive parameters,
* Iterate a fixed number of randomly generated inactive parameter configurations."""


@define(kw_only=True)
class BotorchRecommender(BayesianRecommender):
Expand Down Expand Up @@ -70,6 +65,16 @@ class BotorchRecommender(BayesianRecommender):
"""Percentage of discrete search space that is sampled when performing hybrid search
space optimization. Ignored when ``hybrid_sampler="None"``."""

n_threshold_inactive_parameters_generator: int = field(
default=10, validator=[instance_of(int), ge(1)]
)
"""Threshold used for checking which inactive parameters generator is used when
cardinality constraints are present. When the size of the combinatorial list of
all possible inactive parameters is larger than the threshold, a fixed number of
randomly generated inactive parameter configurations are used and the best
optimum among them is recommended; Otherwise, we find the best one by iterating the
combinatorial list of all possible inactive parameters """

@sampling_percentage.validator
def _validate_percentage( # noqa: DOC101, DOC103
self, _: Any, value: float
Expand Down Expand Up @@ -240,11 +245,11 @@ def append_recommendation_for_inactive_parameters_setting(
# Below we start recommendation
if (
subspace_continuous.n_combinatorial_inactive_parameters
> N_THRESHOLD_INACTIVE_PARAMETERS_GENERATOR
> self.n_threshold_inactive_parameters_generator
):
# When the combinatorial list is too large, randomly set some parameters
# inactive.
for _ in range(N_THRESHOLD_INACTIVE_PARAMETERS_GENERATOR):
for _ in range(self.n_threshold_inactive_parameters_generator):
inactive_params_sample = tuple(
subspace_continuous._sample_inactive_parameters(1)[0]
)
Expand Down

0 comments on commit f68ce4f

Please sign in to comment.