Multiple descriptors and CMA-based search ========================================= The examples on this page use four independent searches. Each receives new archives and a private seed. Evaluators return measurements and the search updates archives in the calling process. Install ``qdpy[cma]`` for Dynamic CMA-ME, DDS-KDE, and CMA-MEGA (ES). Multi-descriptor MAP-Elites Success uses the base package. .. _multi-bd-mes: Multi-descriptor MAP-Elites Success ------------------------------------ Use :func:`qdpy.algorithms.multi_bd_mes` when one evaluation supplies several views of behavior. For example, one navigation run can yield both its endpoint and the centroid of the path it followed. Define a success condition such as reaching a goal. Each descriptor view has its own Grid or CVTGrid, and the same evaluation can enter several archives. Fitness compares elites of equal success status. A successful candidate can replace an unsuccessful one even when its shaping fitness is lower. Parent selection favours successful elites in the current view. .. code-block:: python from qdpy.algorithms import multi_bd_mes from qdpy.containers import Grid archives = { name: Grid(shape=8, features_domain=((0., 1.),), fitness_domain=((0., 1.),), fitness_weights=(1.,)) for name in ("distance", "balance") } def evaluate(genome): left, right = genome distance = (left + right) / 2 balance = 1 - abs(left - right) return distance > .75, (distance,), {"distance": (distance,), "balance": (balance,)} result = multi_bd_mes(archives, evaluate, dimension=2, budget=64, seed=7) print(result.attempts, result.successful_evaluations, result.admissions) The implementation uses a steady-state loop, round-robin view selection, and bounded Gaussian mutation. Each stored elite has a ``success`` named score. Declare the success criterion and descriptor views in your evaluator. The reference uses a model to propose these functions. `Garrabé, Khoramshahi, and Doncieux (2026 preprint) `__. .. _dynamic-cma-me: Dynamic CMA-ME -------------- :func:`qdpy.algorithms.dynamic_cma_me` probes the least recently checked elite for a change in fitness or descriptors. When a probe detects a shift, it refreshes the incumbents of the cells targeted by the new offspring. If an incumbent moves to another occupied cell, it also refreshes that cell's incumbent. The search stages those measurements before committing them. If a refresh fails or exhausts the remaining budget, that generation leaves the archive as it was. The attempts still count toward the budget. .. code-block:: python from qdpy.algorithms import dynamic_cma_me from qdpy.containers import Grid archive = Grid(shape=(6, 6), features_domain=((0., 1.),) * 2, fitness_domain=((0., 1.),)) def evaluate(genome, tick): centre = .25 if tick < 32 else .75 cost = sum((x - centre) ** 2 for x in genome) / len(genome) return (cost,), genome[:2] result = dynamic_cma_me(archive, evaluate, x0=[.5] * 4, budget=93, batch_size=8, seed=7) print(result.offspring_attempts, result.detection_attempts, result.refresh_attempts) Use a deterministic evaluator at each tick. Each generation freezes its tick at the current number of spent attempts. Probe and refresh calls share that tick. The implementation uses one improvement emitter and passes only a complete offspring population to CMA. Use ``refresh=False`` for the matched static control. Audit both archives at the same final tick and keep audit calls separate from search. `Gallotta, Liapis, and Yannakakis (2024) `__. .. _dds-kde: Density Descent Search with a kernel density estimate ------------------------------------------------------ :func:`qdpy.algorithms.dds_kde` ranks new solutions by descriptor density using a Gaussian kernel and a bounded reservoir of past descriptors. The results grid reports discoveries. CMA and the reservoir update independently of admission to that grid. Supply constant fitness to isolate diversity in a comparison. Bandwidth is in descriptor units, so use comparable scales for distinct axes. .. code-block:: python from qdpy.algorithms import dds_kde from qdpy.containers import Grid archive = Grid(shape=(8, 8), features_domain=((0., 1.),) * 2, fitness_domain=((0., 1.),), fitness_weights=(1.,)) result = dds_kde(archive, lambda genome: ((1.,), genome[:2]), x0=[.5] * 4, budget=128, bandwidth=.1, reservoir_size=64, batch_size=12, seed=7) print(result.attempts, result.reservoir_size, archive.filled_bins) The Gaussian estimate scores a population against the prior reservoir. Reservoir sampling adds the current population after ranking. Valid descriptors can inform the estimate even if their result falls outside the reporting grid. This is the KDE variant from `Lee et al. (2024) `__. For the continuous normalizing flow variant on the same CMA scheduler, see :ref:`portfolio-codesign-density`. .. _cma-mega-es: CMA-MEGA with ES gradient estimates ------------------------------------ :func:`qdpy.algorithms.cma_mega_es` estimates fitness and descriptor gradients from the same set of mirrored perturbations. It samples linear combinations of the normalised gradients and adapts its coefficient distribution using archive improvement. As in the authors' reference configuration, centre and perturbation measurements can enter the archive. A bounded search clips candidates to its declared genome bounds. Failed measurements count toward the budget. A pair enters the gradient estimate only if both perturbations returned valid measurements. .. code-block:: python from qdpy.algorithms import cma_mega_es from qdpy.containers import Grid archive = Grid(shape=(6, 6), features_domain=((0., 1.),) * 2, fitness_domain=((0., 1.),)) def evaluate(genome): cost = sum((x - .25) ** 2 for x in genome) / len(genome) return (cost,), genome[:2] result = cma_mega_es(archive, evaluate, x0=[.5] * 4, budget=93, es_samples=8, batch_size=12, seed=7) print(result.centre_attempts, result.perturbation_attempts, result.offspring_attempts) The reported total includes all three phases. DDS-KDE and CMA-MEGA (ES) also accept a caller-owned executor exposing ordered ``map``. For process workers, define the evaluator at module scope. See `Tjanaka et al. (2022) `__ for the algorithm and original RL experiments. Reproduce the CPU comparisons ----------------------------- From the repository root, use the installed QDpy package to run the example with three seeds and 388 candidate calls per search. .. code-block:: sh python -m pip install ".[cma]" python -m examples.descriptor_cma --output build/descriptor-cma/results.json To run the navigation comparison with the base package, pass ``--studies success``. The dynamic comparison reports an independent final-tick audit. The density comparison uses identical reporting grids and constant quality. The gradient comparison counts the perturbation cost for both ES methods. The default budget fits ME-ES initialization and whole generations exactly. The following values are medians over seeds 7, 13, and 23. All 36 trials spent 388 search calls each. A second run reproduced every saved record. .. list-table:: :header-rows: 1 * - Study - New method - Baselines * - Navigation, successful endpoint cells - Multi-descriptor MES 7 - Single-grid MES 7, MAP-Elites 1 * - Shifting sphere, final archive freshness - Dynamic CMA-ME 54.8% - Static CMA-ME 38.7%, Dynamic MAP-Elites 64.9% * - Constant quality, coverage - DDS-KDE 96.9% - Novelty search 78.1%, CMA-MAE 100.0% * - Rastrigin, QD score - CMA-MEGA (ES) 43.23 - ME-ES 6.54, CMA-MAE 40.00 Multi-descriptor MES found a successful endpoint on all three seeds. Single-grid MES did so on two. Dynamic CMA-ME spent a median of 23 probes and 78 refresh calls. Dynamic MAP-Elites spent a median of 184 refresh calls and had higher final freshness on this task. The saved results include corrected coverage and QD scores from the independent audit. :download:`Download the per-seed results `. .. autofunction:: qdpy.algorithms.multi_bd_mes .. autofunction:: qdpy.algorithms.dynamic_cma_me .. autofunction:: qdpy.algorithms.dds_kde .. autofunction:: qdpy.algorithms.cma_mega_es