CMA-MAE with a best-only result grid¶
A CMA-MAE run maintains a search threshold for each cell and a result grid with the best genuine evaluation in each cell. The Rastrigin example prints both the threshold and the raw fitness values for the cell containing the best result.
Install the cma extra and run the script from the repository root.
python examples/cma_mae.py
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Run a small CMA-MAE search with the optional cma extra.
"""Run a small CMA-MAE search with the optional cma extra."""
from qdpy.algorithms import CMAMAE
from qdpy.benchmarks import illumination_rastrigin_normalised
from qdpy.containers import Grid
from qdpy.simple import run
if __name__ == "__main__":
unit = (0.0, 1.0)
grid = Grid(shape=(4, 4), fitness_domain=(unit,), features_domain=(unit, unit))
search = CMAMAE(
grid, budget=24, x0=[0.5, 0.5, 0.5], sigma0=0.1, batch_size=4,
threshold_min=-1.0, learning_rate=0.1, ind_domain=unit,
)
result = run(search, illumination_rastrigin_normalised, seed=0)
cell = grid.index_grid(result.best)
representative = search.search_elites[cell]
print(f"Evaluations: {result.evaluations}")
print(f"Occupied cells: {grid.filled_bins}/{len(grid.solutions)}")
print(f"Threshold at cell {cell} (signed quality): {search.threshold(cell):.4f}")
print(f"Best raw fitness in cell: {result.best.fitness.values[0]:.4f}")
print(f"Search representative's raw fitness in cell: {representative.fitness.values[0]:.4f}")
qdpy.algorithms.CMAMAE ranks a generation by improvement over
each cell’s threshold at the start of that generation. A qualifying
group moves the threshold toward its mean quality, following Appendix H.
The best qualifying member becomes the search representative for its
cell. Use search.search_elites for those representatives and
grid.solutions for the best results accumulated over the run.
In the example run, the printed search representative has a higher raw
cost than the best result in the same cell.
Set threshold_min in signed, weighted quality units. The evaluator
returns the raw Rastrigin cost between zero and one. A minimisation
weight of -1 converts cost 0.4 into quality -0.4. At a
threshold of -0.6, that candidate gains 0.2 and can become a
search representative. A lower cost already in that cell stays in the
result grid. Increasing learning_rate makes thresholds respond more
quickly to qualifying values.
For your evaluator, set x0 to a point within the decision bounds with
at least two coordinates. Set sigma0 in the units of that vector. A
short final generation updates the archive and thresholds. Covariance
adaptation requires a full generation. See Dominated Novelty Search
for an example of manual batching.