Example 10: expected improvement on a fixed grid¶
Script: examples/example10_optim_EI_gridsearch.py
Purpose¶
The script runs a one-dimensional Bayesian optimization loop on a fixed candidate grid. Expected improvement (EI) is evaluated at all grid points, and the grid point with maximal EI is evaluated next. EI is the classical criterion used in efficient global optimization [4].
What is computed¶
posterior mean and variance on the fixed grid.
current observed minimum.
EI values computed as
expected_improvement(-z_best, -zpm, zpv).posterior excursion probabilities relative to the current observed minimum.
one new objective evaluation per sequential step.
Main objects¶
gpmpcontrib.optim.expectedimprovement.ExpectedImprovementGridSearchgpmpcontrib.samplingcriteria.expected_improvementgpmpcontrib.samplingcriteria.excursion_probability
Outputs¶
Run python examples/example10_optim_EI_gridsearch.py from the repository
root to execute the example. Regenerate the static figure with
cd docs && python make_example_results.py.
Top panel: current GP posterior and observations after two sequential additions. Middle panel: EI on the fixed candidate grid, shown on a log scale. Peaks occur where posterior uncertainty and possible improvement are both present. Lower panel: excursion probability associated with the sign convention used by the EI computation.¶
Source excerpt¶
import numpy as np
import matplotlib.pyplot as plt
import gpmp as gp
import gpmp.num as gnp
import gpmpcontrib as gpc
import gpmpcontrib.optim.expectedimprovement as ei
import gpmpcontrib.samplingcriteria as sampcrit
# -- define a mono-objective problem
problem = gpc.ComputerExperiment(
1, # dim of search space
[[-1], [1]], # search box
single_function=gp.misc.testfunctions.twobumps, # test function
)
# -- create initial dataset
nt = 2000
xt = gp.misc.designs.regulargrid(problem.input_dim, nt, problem.input_box)
zt = problem(xt)
ni = 3
ind = [100, 1000, 1600]
xi = xt[ind]
# -- initialize a model and the ei algorithm
model = gpc.Model_ConstantMean_Maternp_REML(
"GP1d",
output_dim=problem.output_dim,
mean_specification={"type": "constant"},
covariance_specification={"p": 2},
)
eialgo = ei.ExpectedImprovementGridSearch(problem, model, xt)