Skip to content

Commit 8cf4531

Browse files
authored
Improve acq_max seeding of L-BFGS-B optimization (#297)
1 parent 11a0c6a commit 8cf4531

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

bayes_opt/bayesian_optimization.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ def suggest(self, utility_function):
229229
constraint=self.constraint,
230230
y_max=self._space._target_max(),
231231
bounds=self._space.bounds,
232-
random_state=self._random_state)
232+
random_state=self._random_state,
233+
y_max_params=self._space.params[self._space.target.argmax()])
233234

234235
return self._space.array_to_params(suggestion)
235236

bayes_opt/util.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import json
77

88

9-
def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000, n_iter=10):
9+
def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000, n_iter=10, y_max_params=None):
1010
"""
1111
A function to find the maximum of the acquisition function
1212
1313
It uses a combination of random sampling (cheap) and the 'L-BFGS-B'
1414
optimization method. First by sampling `n_warmup` (1e5) points at random,
15-
and then running L-BFGS-B from `n_iter` (250) random starting points.
15+
and then running L-BFGS-B from `n_iter` (10) random starting points.
1616
1717
Parameters
1818
----------
@@ -40,6 +40,9 @@ def acq_max(ac, gp, y_max, bounds, random_state, constraint=None, n_warmup=10000
4040
:param n_iter:
4141
number of times to run scipy.minimize
4242
43+
:param y_max_params:
44+
Function parameters that produced the maximum known value given by `y_max`.
45+
4346
Returns
4447
-------
4548
:return: x_max, The arg max of the acquisition function.
@@ -87,7 +90,15 @@ def adjusted_ac(x):
8790

8891
# Explore the parameter space more thoroughly
8992
x_seeds = random_state.uniform(bounds[:, 0], bounds[:, 1],
90-
size=(n_iter, bounds.shape[0]))
93+
size=(1+n_iter+int(not y_max_params is None),
94+
bounds.shape[0]))
95+
# Add the best candidate from the random sampling to the seeds so that the
96+
# optimization algorithm can try to walk up to that particular local maxima
97+
x_seeds[0] = x_max
98+
if not y_max_params is None:
99+
# Add the provided best sample to the seeds so that the optimization
100+
# algorithm is aware of it and will attempt to find its local maxima
101+
x_seeds[1] = y_max_params
91102

92103
for x_try in x_seeds:
93104
# Find the minimum of minus the acquisition function

0 commit comments

Comments
 (0)