-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Description
I met an error when executing the code shown in the Basic tour of the Bayesian Optimization package part. My code is the same as the demo, except the parameters for maximize() method.
def black_box_function(x, y):
return -x ** 2 - (y - 1) ** 2 + 1
from bayes_opt import BayesianOptimization
pbounds = {'x': (2, 4), 'y': (-3, 3)}
optimizer = BayesianOptimization(
f=black_box_function,
pbounds=pbounds,
random_state=1,
)
optimizer.maximize(
init_points=1,
n_iter=5,
)
print(optimizer.max)
As you can see, I set the parameters as 1 and 5 respectively, and I got the output as well as the error like this:
| iter | target | x | y |
-------------------------------------------------
| 1 | -7.135 | 2.834 | 1.322 |
Traceback (most recent call last):
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/bayes_opt/bayesian_optimization.py", line 169, in maximize
x_probe = next(self._queue)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/bayes_opt/bayesian_optimization.py", line 26, in __next__
raise StopIteration("Queue is empty, no more objects to retrieve.")
StopIteration: Queue is empty, no more objects to retrieve.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "tmp.py", line 91, in <module>
n_iter=5,
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/bayes_opt/bayesian_optimization.py", line 171, in maximize
x_probe = self.suggest(util)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/bayes_opt/bayesian_optimization.py", line 124, in suggest
self._gp.fit(self._space.params, self._space.target)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/sklearn/gaussian_process/_gpr.py", line 234, in fit
self.kernel_.bounds))]
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/sklearn/gaussian_process/_gpr.py", line 503, in _constrained_optimization
bounds=bounds)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/optimize/_minimize.py", line 600, in minimize
callback=callback, **options)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 335, in _minimize_lbfgsb
f, g = func_and_grad(x)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/optimize/lbfgsb.py", line 285, in func_and_grad
f = fun(x, *args)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 326, in function_wrapper
return function(*(wrapper_args + args))
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/optimize/optimize.py", line 64, in __call__
fg = self.fun(x, *args)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/sklearn/gaussian_process/_gpr.py", line 225, in obj_func
theta, eval_gradient=True, clone_kernel=False)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/sklearn/gaussian_process/_gpr.py", line 476, in log_marginal_likelihood
alpha = cho_solve((L, True), y_train) # Line 3
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/scipy/linalg/decomp_cholesky.py", line 196, in cho_solve
b1 = asarray_chkfinite(b)
File "/home/ljy/anaconda3/envs/tt/lib/python3.6/site-packages/numpy/lib/function_base.py", line 496, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs
It looks something wrong with suggest() fucntion.
And of course, if I set the two hyper-parameters as 2 and 3 respectively, it works well and does optimize to a good result, the output is like this then.
| iter | target | x | y |
-------------------------------------------------
| 1 | -7.135 | 2.834 | 1.322 |
| 2 | -7.78 | 2.0 | -1.186 |
| 3 | -7.11 | 2.218 | -0.7867 |
| 4 | -12.4 | 3.66 | 0.9608 |
| 5 | -6.999 | 2.23 | -0.7392 |
=================================================
So I'm not sure why I can't set init_points to be smaller, or there are some principles about these two parameters that I haven't understood.
nerai, AlbertoMQ, ShengdingHu, qysnn, baichen318 and 1 more
Metadata
Metadata
Assignees
Labels
No labels