Skip to content

Commit

Permalink
Merge branch 'master' into pydocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
till-m committed Dec 10, 2023
2 parents 6aca15d + 8cf4531 commit 84bd38c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bayes_opt/bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def suggest(self, utility_function):
constraint=self.constraint,
y_max=self._space._target_max(),
bounds=self._space.bounds,
random_state=self._random_state)
random_state=self._random_state,
y_max_params=self._space.params[self._space.max()['params']])

return self._space.array_to_params(suggestion)

Expand Down
14 changes: 12 additions & 2 deletions bayes_opt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from scipy.optimize import minimize


def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000, n_iter=10):
def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000, n_iter=10, y_max_params=None):
"""Find the maximum of the acquisition function.
It uses a combination of random sampling (cheap) and the 'L-BFGS-B'
Expand Down Expand Up @@ -44,6 +44,9 @@ def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000
n_iter : int, default=10
Points to run L-BFGS-B optimization from.
y_max_params : np.array
Function parameters that produced the maximum known value given by `y_max`.
Returns
-------
Parameters maximizing the acquisition function.
Expand Down Expand Up @@ -101,7 +104,14 @@ def adjusted_ac(x):

# Explore the parameter space more thoroughly
x_seeds = random_state.uniform(bounds[:, 0], bounds[:, 1],
size=(n_iter, bounds.shape[0]))
size=(1+n_iter+int(not y_max_params is None),
bounds.shape[0]))

x_seeds[0] = x_max
if not y_max_params is None:
# Add the provided best sample to the seeds so that the optimization
# algorithm is aware of it and will attempt to find its local maxima
x_seeds[1] = y_max_params

for x_try in x_seeds:
# Find the minimum of minus the acquisition function
Expand Down

0 comments on commit 84bd38c

Please sign in to comment.