SheffieldML / GPyOpt

Gaussian Process Optimization using GPy
BSD 3-Clause "New" or "Revised" License
929 stars 261 forks source link

True best value in Bayesian Optimization #349

Open lewisscola opened 4 years ago

lewisscola commented 4 years ago

Hi, I have some questions about the true best value in BO. my code is listed as below:

%pylab inline
import GPyOpt
from numpy.random import seed
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
import math
import seaborn as sns

func = GPyOpt.objective_examples.experiments1d.forrester() 
domain =[{'name': 'var1', 'type': 'continuous', 'domain': (0,1)}]

myBopt1 = GPyOpt.methods.BayesianOptimization(f=func.f,             
                                             domain=domain, 
                                             acquisition_type='EI',)

# Run the optimization
max_iter = 40     # evaluation budget
max_time = 60     # time budget 
eps      = 10e-6  # Minimum allows distance between the las two observations

myBopt1.run_optimization(max_iter, max_time, eps)  
myBopt1.plot_acquisition()
print("Value of (x,y) that minimize the objective:"+str(myBopt1.x_opt))    
print("Mninimum value of the objective: "+str(myBopt1.fx_opt)) 

image

Then I plot the predicted best value of BO (myBopt1.Y[:i]) and the final best value of BO( myBopt1.Y)

best1 = myBopt1.Y
best2 = [(min(myBopt1.Y[:i])) for i in range(1, len(myBopt1.Y))]
plt.plot(range(len(best1)), best1)
plt.xlabel('iterations')
plt.ylabel('myBopt1.Y')
plt.show()

image

plt.plot(range(len(best2)), best2)
plt.xlabel('iterations')
plt.ylabel('myBopt1.Y[:i]')
plt.show()

image

My question is why the final best values do not converge as the predicted best values do? Why the final best values fluctuate? What is the relation between myBopt1.fx_opt and myBopt1.Y?

apaleyes commented 4 years ago

Well, Y is not sorted by values, it is a chronologically ordered list of function outputs. Apparently the optimization process converged pretty quickly, but as it kept running it was probing more and more regions with uncertainty.

The min approach you used for best2 is the correct way to find current min value. As you can see, there is no fluctuations there. That is also how fx_opt is computed

lewisscola commented 4 years ago

Thank you for your reply and help!

I still have a question about the issue above. image image As you can see from the images above, The true best value Y fluctuates in the first 10 iterations, so why is the true best value Y does not continuously decrease as the iteration increase? I mean why the minimum value of the function is not decreased continuously?(For example, if BO already find a minimum value f1, why the BO will find a minimum value f2, which f2>f1?)

apaleyes commented 4 years ago

That's how BO works, It explores the fuction. Just because we've hit a local minimum at X1, doesn't mean there isn't anything better elsewhere. You need to probe certain amount of points before you are certain how how the function looks and where the global minimum is.

lewisscola commented 4 years ago

Thank you very much for your explanation!

Then, I am wondering how should we select the stopping criteria for BO. Could you explain when should we stop the iterations? Is there any quantitative method that can demonstrate stopping criteria?

apaleyes commented 4 years ago

That is highly case dependent. Sometimes you want to stop when new Ys don't change much, sometimes you have a budget in terms of time or number of calls to the objective.

This issue turns into a 101 on bayes opt. Do consider a proper tutorial, e.g. this one from Peter Frazier, one of the experts in the field.

lewisscola commented 4 years ago

Thank you for your explanation!

I'm thinking if the acquisition value can demonstrate stopping criteria because the acquisition value will decrease when iteration increases.

Could you tell me how to plot acquisition value change as iteration increases in GpyOpt?

apaleyes commented 4 years ago

For how to plot acquisition and similar functions, see GPyOpt tutorials. Plotting funciton is used here, for example.

It isn't a good stopping criterion on its own, because acquisition isn't designed to tell you objective minimum - its designed to balance exploration and exploitation. Two points can value the same for different reasons.

lewisscola commented 4 years ago

Do you mean by using the codemyBopt.plot_acquisition()? Is there any way to plot acquisition value vs iterations? like the below image image

Thank you very much!

apaleyes commented 4 years ago

i don't think there is a built-in function for that. your best bet is to do the plotting yourself for that

lewisscola commented 4 years ago

Could you tell me how to plot it by myself? I try this code, but it doesn't work. image

LilyEvansHogwarts commented 4 years ago

The acquisition function value can be got by myBopt1.acquisition.acquisition_function(x). For more details about the acquisition function, I think you can read the code in GpyOpt/GPyOpt/acquisitions folder.

lewisscola commented 4 years ago

Thank you so much for your help! @LilyEvansHogwarts