Skip to content

Commit

Permalink
Fix bug when using EI with constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
roussel-ryan committed Jan 29, 2025
1 parent 7baa79c commit a0a0cf3
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion xopt/generators/bayesian/expected_improvement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from botorch.acquisition import (
ScalarizedPosteriorTransform,
LogExpectedImprovement,
qLogExpectedImprovement,
qLogExpectedImprovement, FixedFeatureAcquisitionFunction,
)

from xopt.generators.bayesian.bayesian_generator import (
Expand All @@ -23,6 +23,33 @@ class ExpectedImprovementGenerator(BayesianGenerator):
+ formatted_base_docstring()
)

def get_acquisition(self, model):
"""
Returns a function that can be used to evaluate the acquisition function.
Overwrites base `get_acqusition` method.
"""
if model is None:
raise ValueError("model cannot be None")

# get base acquisition function
acq = self._get_acquisition(model)

# apply fixed features if specified in the generator
if self.fixed_features is not None:
# get input dim
dim = len(self.model_input_names)
columns = []
values = []
for name, value in self.fixed_features.items():
columns += [self.model_input_names.index(name)]
values += [value]

acq = FixedFeatureAcquisitionFunction(
acq_function=acq, d=dim, columns=columns, values=values
)

return acq

def _get_acquisition(self, model):
objective = self._get_objective()
best_f = self._get_best_f(self.data, objective)
Expand All @@ -35,6 +62,7 @@ def _get_acquisition(self, model):
best_f=best_f,
sampler=sampler,
objective=objective,
constraints=self._get_constraint_callables()
)
else:
# analytic acquisition function for single candidate generation with
Expand Down

0 comments on commit a0a0cf3

Please sign in to comment.