Search across age layers, decoders, and learned behaviors ========================================================= These examples use age to move between feature spaces, decode one genome in several ways, and learn behavior from sensor predictions or recorded trajectories. The last example generates optimization benchmarks with varied local-optima networks. .. _layered-illumination-alme: Move lineages through age layers -------------------------------- Age-Layered MAP-Elites gives each archive a separate descriptor space. An immigrant starts at age zero. Its descendants inherit its birth evaluation, so they mature on the same schedule. At a layer's age limit, a surviving candidate moves to the next archive using cached measurements. The destination applies ordinary local competition. [Pozzuoli2023]_ .. code-block:: python from qdpy.algorithms import age_layered_map_elites from qdpy.containers import Grid young = Grid(shape=(8,), features_domain=((0., 1.),), fitness_domain=((0., 1.),)) mature = Grid(shape=(8,), features_domain=((0., 1.),), fitness_domain=((0., 1.),)) def evaluate(genome): x, y = genome return 1. - (x - y)**2, ((x,), (y,)) result = age_layered_map_elites( (young, mature), evaluate, sample=lambda rng: rng.random(2), mutate=mutate, max_ages=(22,), budget=192, immigrant_interval=6, seed=11, ) The evaluator returns a descriptor vector for every layer. Define one increasing age limit for each layer except the last. QDpy ages lineages by evaluator calls and samples uniformly over populated layers before sampling a parent. Cache measurements only when the evaluation is stationary. Compare the finished archives using one common geometry and match both the measurement budget and total storage capacity. .. _layered-illumination-decoders: Try several feasible decodings ------------------------------ A route-order genome can produce different feasible routes under different decoders. The same search can also choose among mutation operators with several selection rules. [Urquhart2023]_ .. code-block:: python from qdpy.algorithms import multi_decoder_map_elites result = multi_decoder_map_elites( archive, evaluate_routes, sample=random_tour, emitters=(swap_visits, reverse_segment), decoders=(sequential_capacity_split, first_fit_capacity_split), budget=200, rule="ucb1", seed=11, ) for elite in result.archive: decoder_index, *genome = elite routes = (sequential_capacity_split, first_fit_capacity_split)[decoder_index](tuple(genome)) A decoder returns a phenotype or ``None``. Its call consumes one budget slot either way. The evaluator receives only decoded phenotypes. Each proposal visits the configured decoder panel and rotates the order between proposals. A final partial panel respects the hard budget. The saved genome begins with its decoder index. The runner supports round robin, UCB1, and decaying epsilon. Its bandit credit is the fraction of attempted decodings admitted to the grid. .. _layered-illumination-surprise: Evolve actors and predictors together ------------------------------------- Minimize Surprise MAP-Elites rates a controller–predictor pair by how accurately the predictor anticipates observed sensors after the actor takes an action. The array for each rollout has time on its first axis. Additional axes can represent agents and sensors. Fitness is the lowest mean prediction accuracy over the fixed seed panel. Descriptors come from the observed signals. [Kaiser2022]_ .. code-block:: python from qdpy.algorithms import minimize_surprise_map_elites result = minimize_surprise_map_elites( archive, run_actor_predictor, describe=final_sensor_means, sample=initial_weights, mutate=mutate_weights, budget=144, repeats=3, seed=11, ) Normalize sensors and predictions to ``[0, 1]``. Return arrays with matching shapes and use actual next observations as targets. Average behavior descriptors over repeats. Test prediction on fresh reset seeds and inspect which distinct behaviors survived. The example uses four interacting agents with small analytic actors and predictors. .. _layered-illumination-pga: Teach PGA-AURORA from trajectories ---------------------------------- PGA-AURORA combines genetic variation and replay-based TD3 gradients with an unstructured repertoire. An autoencoder first fits on the random policies' trajectories, then refits periodically on retained trajectories and rebuilds the archive from cached data. [Chalumeau2023]_ .. code-block:: python from qdpy.rl import PGAAURORA search = PGAAURORA( make_environment, latent_size=2, initial_policies=16, training_period=16, max_episode_steps=40, seed=11, ) stats = search.train(5_000) print(stats.env_steps, stats.encoder_updates, stats.pg_offspring) search.best_policy().save("pga-aurora.npz") The default encoder flattens a fixed-size trajectory and reuses QDpy's dense autoencoder. The paper uses a recurrent encoder. The default pads short episodes with their last observation. Supply ``trajectory(episode)`` to select sensors and return a fixed two-axis array scaled to ``[-1, 1]``. If several evaluation episodes are requested, their aligned traces are averaged. An incomplete policy contributes replay in PGA mode and stays out of the representation fit. Set ``gradient=False`` to run the genetic control using the same archive and encoder schedule. .. _layered-illumination-adahome: Allocate Ada-HOME operators from admission feedback --------------------------------------------------- Ada-HOME adjusts the genetic and policy-gradient slots in each PGA generation. Genetic offspring can copy whole weights from a donor. A second replay buffer stores complete episodes from admitted policies, so the ordinary ring can continue receiving all measured transitions. [Li2026]_ .. code-block:: python from qdpy.rl import AdaHOME search = AdaHOME( make_environment, archive, descriptor=describe_episode, batch_size=9, swap_probability=.1, elite_fraction=.25, elite_capacity=4096, seed=11, ) stats = search.train(10_000) print(stats.operator_trials, stats.operator_successes, stats.elite_replay_size) QDpy uses UCB1 with one credit for each admitted candidate, plus a separate greedy actor slot. Cutoff policies are excluded from bandit feedback and elite replay. The accessible paper abstract establishes the three mechanisms. The credit rule, crossover mask, and replay sampling described here define the QDpy variant. Use ``adaptive=False`` to hold the allocation fixed. Set ``swap_probability=0.`` and ``elite_fraction=0.`` to switch off crossover and elite replay for a matched PGA control. .. _layered-illumination-lon: Generate landscapes from sampled escape networks ------------------------------------------------ A Max-Set of Gaussians uses the pointwise maximum of several peaks on a unit box. A dominated center points to the Gaussian that wins there. Following these links assigns each component to a visible local optimum. Sample points in a ball around every visible center and estimate the probability that a perturbation lands in each basin. This construction is specific to max-Gaussian landscapes. [Mizuta2026]_ .. code-block:: python from qdpy.benchmarks import generate_local_optima_benchmarks suite = generate_local_optima_benchmarks( dimension=2, peaks=14, budget=100, samples=48, seed=11, ) landscape, network = suite.landscapes[0], suite.networks[0] print(landscape((.4, .6)), network.nodes, network.transitions) The graph descriptors are node count, improving-edge density, sink count, mean shortest path to the optimum among reachable nodes, mean shortest path to a sink, incoming probability at the optimum, mean incoming probability across sinks, and the fraction assigned to the optimum by strongest improving edges. The generator searches Gaussian heights and widths at fixed Sobol centers. It records all measured instances alongside a bounded novelty archive. Use ``novelty=False`` for a random control at the same instance budget. Keep network probes separate from the budgets of solvers tested on these landscapes. .. _layered-illumination-results: Reproduce the CPU comparisons ----------------------------- The :download:`example script <../examples/layered_illumination.py>` writes one JSON row per method and seed. PGA-AURORA and Ada-HOME use the existing ``rl`` extra. .. code-block:: console python examples/layered_illumination.py layers --seeds 11 22 33 44 55 python examples/layered_illumination.py decoders --seeds 11 22 33 44 55 python examples/layered_illumination.py predict --seeds 11 22 33 44 55 python examples/layered_illumination.py pga --seeds 11 22 33 44 55 python examples/layered_illumination.py adaptive --seeds 11 22 33 44 55 python examples/layered_illumination.py landscapes --seeds 11 22 33 44 55 On the two-axis analytic example, ALME made 11.2 successful promotions and filled 11.0 cells in the common audit grid on average. The joint-grid control filled 16.0 at the same 192 evaluations and 16 archive slots. The two-decoder routing variants and the single-decoder control each evaluated 200 decoded routes per seed. Both multi-decoder variants averaged 5.4 cells and a best distance of 4.167. Single-decoder search averaged 6.2 cells and a best distance of 4.205. The evolved actor–predictor pairs reduced mean held-out sensor error from 0.0252 to 0.0191 against random pairs. Both methods covered all 12 sensor bins with 432 search rollouts and 36 audit rollouts per seed. At 360 search transitions, PGA-AURORA averaged 2.2 cells and an 8.43 score in the independently measured endpoint archive. Genetic AURORA averaged 2.2 cells and 9.23. PGA given endpoint descriptors averaged 6.8 cells and 22.60. This small fixture uses different numbers of archived policies at audit time, and the JSON records those audit costs. On the same fixture, Ada-HOME averaged an audited score of 23.59 versus 22.60 for fixed PGA. Fixed allocation with crossover and the second replay buffer scored highest at this budget, with 24.70. At 100 generated landscapes, novelty search averaged 42.6 distinct network signatures versus 38.4 for random generation. Each signature uses the node count, sink count, and binned optimum-funnel fraction. Novelty search averaged 24,086 basin probes versus 22,925 for random generation because probe work scales with the number of visible peaks. .. [Pozzuoli2023] `Increasing Features in MAP-Elites Using an Age-Layered Population Structure `__. .. [Urquhart2023] `Improving the Size and Quality of MAP-Elites Containers via Multiple Emitters and Decoders for Urban Logistics `__. .. [Kaiser2022] `Minimize Surprise MAP-Elites `__. .. [Chalumeau2023] `Neuroevolution is a Competitive Alternative to Reinforcement Learning for Skill Discovery `__. .. [Li2026] `Enhancing Quality-Diversity with Adaptive Heterogeneous Operator Allocation `__. .. [Mizuta2026] `Novelty-Based Generation of Continuous Landscapes with Diverse Local Optima Networks `__.