diff --git a/bayes_opt/bayesian_optimization.py b/bayes_opt/bayesian_optimization.py index da0702a8d..258c02fd9 100644 --- a/bayes_opt/bayesian_optimization.py +++ b/bayes_opt/bayesian_optimization.py @@ -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) diff --git a/bayes_opt/util.py b/bayes_opt/util.py index d8a4f9077..417e307f7 100644 --- a/bayes_opt/util.py +++ b/bayes_opt/util.py @@ -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' @@ -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. @@ -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