0

I have a set of samples and their corresponding target values. Below is the visualization:

enter image description here

I am trying to use Bayesian optimization to find the sample with maximum target value. My question is if someone knows a python package that does this. I was looking at BayesianOptimization package and it seems that it can perform optimization over an interval, but not necessarily only among the samples.


Edit: Here is a sample code:

import matplotlib.pyplot as plt
import numpy as np
from bayes_opt import BayesianOptimization

mean = (1, 2)
cov = [[1, 0], [0, 1]]
my_x, my_y = np.random.multivariate_normal(mean, cov, 1000).T
cmap_data = -my_x ** 2 - (my_y - 1) ** 2 + 1

search = []
def black_box_function(x, y):
    a = np.hstack((x, y))
    search.append(a)

    plt.scatter(my_x, my_y, marker='.', s=1, c=np.array(cmap_data))
    plt.axis('equal')
    # plt.scatter(np.array(search)[:, 0], np.array(search)[:, 1], marker='.', s=20, c='black')

    plt.plot(np.array(search)[:, 0], np.array(search)[:, 1], marker='.', c='black', linewidth=0.5)

    plt.show()

    return -x ** 2 - (y - 1) ** 2 + 1

# -- optimization
pbounds = {'x': (min(my_x), max(my_x)), 'y': (min(my_y), max(my_y))}

optimizer = BayesianOptimization(
    f=black_box_function,
    pbounds=pbounds,
    random_state=1,
)

for i in range(1000):
    optimizer.probe(
    params=[my_x[i], my_y[i]],
    lazy=True,
)

optimizer.maximize(
    init_points=0,
    n_iter=0,
)

But it seems optimizer.probe just evaluates the values (to be used in future iterations), and it is not an actual iteration of optimization.

Blade
  • 984
  • 3
  • 12
  • 34

0 Answers0