bayesian-optimization / BayesianOptimization

A Python implementation of global optimization with gaussian processes.
https://bayesian-optimization.github.io/BayesianOptimization/index.html
MIT License
7.95k stars 1.55k forks source link

The next best guess does not match the real sample point. #528

Closed linghuix closed 1 month ago

linghuix commented 1 month ago

Describe the bug

I noticed the next best guess from utility function does not match the real one.

To Reproduce

I used the same code as shown in the document https://bayesian-optimization.github.io/BayesianOptimization/1.5.1/visualization.html

Expected behavior A clear and concise description of what you expected to happen.

The next best guess from ucb utility function should match the real sample point. The code doesn't explore around x=-0.2 . If there is a high peak at that point, the code will miss it.

Screenshots If applicable, add screenshots to help explain your problem. image image image image

Environment (please complete the following information):

linghuix commented 1 month ago

I forget to attach this figure. It is obvious that the next best guess has highest value but optimizer doesn't choose it. There could be something wrong here. image

I compared my results with the document and found the different happens from 4th step. Code is exactly the same, quite wired. image

till-m commented 1 month ago

Hi @linghuix,

If I run the notebook I don't observe this phenomenon. Are you sure you're running exactly that notebook, with nothing changed?

NB: Sometimes the GP fitting process fails (usually due to little data), which can then cause this can happen. However, I don't think that's the case here.

linghuix commented 1 month ago

Thanks for your reply.

After I carefully compared my code with that notebook, I noticed the only difference is that I used optimizer.maximize(init_points=0, n_iter=1) instead of optimizer.maximize(init_points=0, n_iter=1, acquisition_function=acq_function).

I am curious that what the default acq function is if I donot pass one. Also, in the Visulazation Document, the following code does not specify the acq function. Is it a typo? image

till-m commented 1 month ago

the plot shows UCB with kappa=5. The definition of that is in plot_gp, see attached screenshot. Screenshot 2024-10-15 at 13 38 20

I am curious that what the default acq function is if I donot pass one. Also, in the Visulazation Document, the following code does not specify the acq function. Is it a typo?

It should be UCB with kappa=2.576, see here.

linghuix commented 1 month ago

Thanks for your reply. It helps a lot.