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())