MAP-Elites with Iso+LineDD¶
Find low-cost Rastrigin solutions across the first two coordinates of a
three-variable genome. qdpy.algorithms.IsoLineMAPElites draws
uniformly from the decision bounds while the archive is empty. Once the
archive has elites, it draws parents from those elites.
Run from the repository root after installing the base package.
python examples/isoline_map_elites.py
The grid divides the two descriptors into four bins per axis. Each cell
keeps the lowest measured cost it has seen. Compare the printed number of
occupied cells with the best raw fitness. The last line maps the best
genome’s descriptors back to a cell with grid.index_grid(best).
# SPDX-License-Identifier: LGPL-3.0-or-later
## @file
# @brief Run a small MAP-Elites search with Iso+LineDD variation.
"""Run a small MAP-Elites search with Iso+LineDD variation."""
from qdpy.algorithms import IsoLineMAPElites
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 = IsoLineMAPElites(
grid, budget=24, dimension=3, ind_domain=unit, batch_size=4,
iso_sigma=0.01, line_sigma=0.2,
)
result = run(search, illumination_rastrigin_normalised, seed=42)
best = result.best
descriptors = tuple(round(float(value), 4) for value in best.features)
print(f"Evaluations: {result.evaluations}")
print(f"Occupied cells: {grid.filled_bins}/{len(grid.solutions)}")
print(f"Best raw fitness: {best.fitness.values[0]:.4f}")
print(f"Best descriptors: {descriptors}, cell {grid.index_grid(best)}")
iso_sigma sets the scale of independent Gaussian steps in genome
units. line_sigma scales one random coefficient multiplying the
difference between the two parents. This coefficient is shared by every
coordinate. If the parents are identical, the independent step still
produces variation. The search clips offspring to ind_domain.
To vary just the independent step, set line_sigma=0. You can also use
the operator directly with two parent vectors and a local random number
generator.
import numpy as np
from qdpy.tools import iso_line_dd
child = iso_line_dd(
[0.3, 0.6], [0.7, 0.4], bounds=(0.0, 1.0),
iso_sigma=0.01, line_sigma=0.2, rng=np.random.default_rng(42),
)