Skip to content

Commit

Permalink
Improve acq_max seeding of L-BFGS-B optimization (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptapping authored Dec 7, 2023
1 parent 11a0c6a commit 8cf4531
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion bayes_opt/bayesian_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,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.target.argmax()])

return self._space.array_to_params(suggestion)

Expand Down
17 changes: 14 additions & 3 deletions bayes_opt/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import json


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):
"""
A function to find the maximum of the acquisition function
It uses a combination of random sampling (cheap) and the 'L-BFGS-B'
optimization method. First by sampling `n_warmup` (1e5) points at random,
and then running L-BFGS-B from `n_iter` (250) random starting points.
and then running L-BFGS-B from `n_iter` (10) random starting points.
Parameters
----------
Expand Down Expand Up @@ -40,6 +40,9 @@ def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000
:param n_iter:
number of times to run scipy.minimize
:param y_max_params:
Function parameters that produced the maximum known value given by `y_max`.
Returns
-------
:return: x_max, The arg max of the acquisition function.
Expand Down Expand Up @@ -87,7 +90,15 @@ 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]))
# Add the best candidate from the random sampling to the seeds so that the
# optimization algorithm can try to walk up to that particular local maxima
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 8cf4531

Please sign in to comment.