# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # ACML2020 Tutorial: Recent Advances in Bayesian Optimization
# # http://vu-nguyen.org/BayesOptTutorial_ACML20
#
# # Dr <NAME> <EMAIL>
#
# # Demo Batch Bayes Opt using the same example of demo 2D

from mini_bo import BayesOpt,visualization,functions
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import gridspec

# # Select the function Beale to be optimized and visualize it

myfunction=functions.beale()
visualization.plot_original_function(myfunction)

# # Set up the BO class
#

# Specify the acquisition function and set up the BO class -- similar to the case of sequential BO
#acq_name='ucb' 
acq_name='ei'
bo=BayesOpt(myfunction.func,myfunction.bounds,acq_name=acq_name,verbose=1)

# # Initialize BO using 3 initial observations

bo.init(n_init_points=3)
visualization.plot_bo_2d(bo)

# # Select a batch of points B=3 (green stars)

xt=bo.select_next_point(B=3)
print("the next point is \n",xt)
visualization.plot_bo_2d(bo)

# # Continue selecting a next batch of point B=2 (green stars)

xt=bo.select_next_point(B=2)
print("the next point is \n",xt)
visualization.plot_bo_2d(bo)

# # We can also select a single point B=1 (green stars)

xt=bo.select_next_point(B=1)
print("the next point is \n",xt)
visualization.plot_bo_2d(bo)

# # Plot the optimization performance

# +
fig=plt.figure(figsize=(7, 4))
myYbest=[bo.Y_ori[:idx+1].max() for idx,val in enumerate(bo.Y_ori)]
plt.plot(range(len(myYbest)),myYbest,linewidth=2,color='m',linestyle='-',marker='o')

plt.xlabel('Iteration',fontsize=14)
plt.ylabel('Best Found Value',fontsize=14)
plt.title('Performance',fontsize=16)

StarcoderdataJupyterScriptsDedupFiltered