I just started to use GPy and GPyOpt. I aim to design an iterative process to find the position of x where the y is the maximum. The dummy x-array spans from 0 to 100 with a 0.5 step. The dummy y-array is the function of x-array. The true function is y = -x**2 + 50*x + 5, so the ymax is when x = 25.0.
I started it by randomly assign 5 points to x-array (with corresponding 5 y-values), and run the Bayesian Optimization to let it recommend next position to sample. I can use convenient myBopt.plot_acquistion() to generate a plot. An example plot is as below.
Questions:
(1) what does the Gaussian-like peak and the vertical line mean? what do they suggest? I assume the center of the Gaussian peak is the suggested next position to sample, is this correct?
(2) how to retrieve the center position of the Gaussian peak? I tried to print out a number of things from myBopt, but couldn't find it anywhere (if I figure out how to get this number, I can append it to the original list to start another BO and find the next position, until convergence).
(3) Is there any way to retrieve the raw data for plotting the acquisition function plot? This must have been saved somewhere.
(4) I generate also the convergence plot (under the acquisition plot), I really couldn't understand it well. Can someone kindly explain it to me?
Thanks.
import GPyOpt
import GPy
from numpy.random import seed
import numpy as np
import matplotlib.pyplot as plt
import random
N = 5
x_array = np.arange(0,100,0.5)
x_random = np.array(sorted(random.sample(x_array, N)))
y_random = (-x_random**2 + 50*x_random + 5) # y = -x**2 + 50*x + 5
## x_feed and y_feed are the matrices that will be fed into Bayesian Optimization
x_feed = x_random[:, None] # (200, 1)
y_feed = y_random[:, None] # (200, 1)
##creat the objective function
class max_number(object):
def __init__(self, x_feed, y_feed):
self.x_feed = x_feed
self.y_feed = y_feed
def f(self, x):
return np.dot(1.0*(x_feed == x).sum(axis = 1), y_feed)[:, None]
func = max_number(x_feed, y_feed)
domain = [{'name' : 'guess_number',
'type' : 'bandit',
'domain': x_feed}]
seed(123)
myBopt = GPyOpt.methods.BayesianOptimization(f = func.f,
domain = domain,
acquisition_type = 'EI',
maximize = True,
exact_feval = False,
initial_design_numdata = 5,
verbosity = True)
max_iter = 50
myBopt.run_optimization(max_iter)
myBopt.plot_acquisition()
print 'x random initial points {}'.format(x_random)
print 'y random initial points {}'.format(y_random)
print 'myBopt.X {}'.format(myBopt.X)
print 'myBopt.x_opt {}'.format(myBopt.x_opt)
print 'myBopt.Y {}'.format(myBopt.Y)
print 'myBopt.Y_best {}'.format(myBopt.Y_best)
print 'myBopt.Y_new {}'.format(myBopt.Y_new)
print 'myBopt.suggest_next_locations {}'.format(myBopt.suggest_next_locations())
Quite a few questions. An advice for future, it is much better suited to the format of SO to have a post per question. But for now:
The vertical red line signifies the last point that the acquisition function suggested to run the function at. The bell-like curve is a part of the whole acquisition function plot (notice red line extends to the whole
y = 0
line) - it just plots the acquisition function so you can have a visual understanding where it is most likely to suggest the next point.You would need to do the optimization of the acquisition function yourself. Alternatively you could use
BO.suggest_next_locations
. Checkout tutorial notebooks, there is an example of the latter.I recommend going through the source code of
plot_acquisition
, it is very clear what data is used and how it is accessed.I think these plots have very self-descriptive titles. Plot on the left shows distance between two consecutive calls to the objective function. Over time you would expect it to shrink, as the optimization finds the optimum. Plot on the right shows the best value of
y
found so far. Over time you would expect it to flatten out.