Bayesian optimisation of elites¶
Use qdpy.algorithms.BOPElites to decide where to spend the
next expensive evaluation. The example uses a cheap stand-in, a
two-variable quadratic cost with a product descriptor. Its archive
keeps the best genuine evaluation per descriptor cell.
Run from the repository root after installing the base package.
python examples/bop_elites.py
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Fit Gaussian processes for both quality and descriptors.
"""Run a small Bayesian search with genuine evaluations and a fixed grid."""
from qdpy.algorithms import BOPElites
from qdpy.containers import Grid
from qdpy.simple import run
def evaluate(candidate):
"""Return the raw cost and the product descriptor."""
x, y = candidate
return ((x - 0.2) ** 2 + (y - 0.4) ** 2,), (x * y,)
if __name__ == "__main__":
unit = (0.0, 1.0)
archive = Grid(shape=4, fitness_domain=((0, 2),), features_domain=(unit,))
search = BOPElites(
archive, budget=24, dimension=2, ind_domain=unit, quality_floor=-2,
initial_samples=8, candidate_pool=16, restarts=2,
)
result = run(search, evaluate, seed=42)
print(f"Evaluations: {result.evaluations}")
print(f"Finite observations: {search.n_observations}")
print(f"Occupied cells: {archive.filled_bins}/{len(archive.solutions)}")
for cell, entries in archive.solutions.items():
if entries:
elite = entries[0]
print(f"Cell {cell}: descriptor {elite.features[0]:.4f}, raw cost {elite.fitness.values[0]:.4f}")
The first eight proposals here come from a scrambled Sobol sequence.
The default warm-up is ten proposals per decision variable, so set
initial_samples below the budget when you want a shorter run to
reach the modelled phase. Once the search has enough observations, it
fits separate fixed Matérn Gaussian processes for the objective and
each descriptor. Acquisition combines the expected improvement in each
cell with the predicted probability of landing there. The runner
evaluates one proposal at a time and updates the models with its result.
Use the printed cell entries to check the measured descriptor and cost
of each elite. n_observations counts finite measurements, including
points with descriptors outside the grid. A failed call spends one
attempt and the search remembers that genome. Set quality_floor
in signed units. For a declared raw minimisation range of [0, 2],
use -2 as the empty-cell floor.
For a second descriptor, return two descriptor values from the
evaluator and give the grid a two-axis shape and one interval per axis.
candidate_pool and restarts control the amount of work spent
searching each acquisition function. Compare both attempted evaluations
and wall time when tuning these settings. See Differentiable, Bayesian, and high-dimensional QD pilots
for a comparison with Sobol and MAP-Elites.