Dynamic mutation and learned novelty¶
Use dynamic mutation when the archive already has meaningful descriptors. Use TAXONS or STAX when the evaluator has observations that could define behavior. BR-NS learns to recognize observed behaviors with a predictor. QD-DualDICE-JS trains policies to visit different states and take different actions over complete episodes.
Adapt Gaussian mutation during MAP-Elites¶
DynamicMutationMAPElites is a native ask/tell algorithm for a Grid
or CVTGrid with a single elite per cell. The evaluator reports ordinary
fitness and descriptors. [Nordmoen2018]
from qdpy.algorithms import DynamicMutationMAPElites
from qdpy.containers import Grid
archive = Grid(
shape=(12, 12), fitness_domain=((0., 1.),),
features_domain=((0., 1.), (0., 1.)),
)
def evaluate(genome):
loss = sum((x - .5) ** 2 for x in genome)
return (1. / (1. + loss),), tuple(genome[:2])
search = DynamicMutationMAPElites(
archive, budget=600, dimension=6, mode="coverage",
sigma_start=.24, sigma_stop=.02, optimisation_task="maximisation",
seed=11,
)
search.optimise(evaluate)
print(archive.filled_bins, search.scheduled_sigma)
Use mode="coverage" to interpolate from the initial to the final
standard deviation as the occupied fraction rises. Set
coverage_target below one when only part of the archive is
reachable. Choose mode="anneal" to use completed evaluations divided
by the nominal budget. With mode="self_adaptive", each descendant
multiplies its parent’s scale by log-normal noise, subject to the
sigma_stop floor. Set mode="fixed" to use sigma_start throughout.
The dynamic_mutation_sigma score records the proposal’s scale
before conversion to physical genome coordinates. The default native
batch size of one lets the next proposal see each result. A wider batch
uses the feedback that has arrived when each suggestion is made.
Tune the fixed baseline on seeds independent of the comparison.
Learn an outcome space with TAXONS¶
TAXONS trains an autoencoder from measured observations. For each generation it chooses latent nearest-neighbor novelty or reconstruction error with equal probability. QDpy uses a dense encoder, bounded training and novelty caches, and elitist parent-plus-child survival. The published experiments used a convolutional encoder and duplicated the best policies into the weakest population slots. [Paolo2020]
from qdpy.algorithms import TAXONS
def evaluate(genome, rollout_seed):
reward, frames = simulate(genome, seed=rollout_seed)
return reward, frames[-1]
search = TAXONS(dimension=6, latent_size=3, training_capacity=128, seed=11)
stats = search.run(evaluate, budget=256)
for row in search.novelty_archive:
print(search.encode(row.observation), row.genome)
Install PyTorch for this workflow. Return a fixed-shape numeric array
scaled to [-1, 1], such as a final image or a sampled and padded
trajectory. Reward is retained in the records for reporting. The
search uses the two exploration criteria. Call encode after the
search to compare every retained observation in the same representation.
An interrupted generation resumes from its cached measurements
on the next call to run.
Exploit sparse rewards with STAX¶
STAX uses Pareto selection on novelty and reconstruction error. Discoveries above a reward threshold seed local emitters that retain parents by reward. The scheduler probes the queued emitters and prioritizes established emitters by novelty and measured improvement. It divides work between exploration and exploitation batches. [Paolo2024]
from qdpy.algorithms import STAX
search = STAX(
dimension=6, latent_size=3, reward_threshold=0.,
emitter_budget=16, bootstrap_calls=4, seed=11,
)
stats = search.run(evaluate, budget=512)
print(stats.exploration_evaluations, stats.bootstrap_evaluations,
stats.emitter_evaluations)
print([row.reward for row in search.reward_archive])
The evaluator reports the same observations as in TAXONS. Use actual task reward for the emitter and keep any hand-designed audit descriptors in a reporting callback. QDpy uses bounded queues, fixed mutation strength, and an archive of recent rewarding discoveries and emitter improvements. It recomputes latent novelty using the current encoder and reuses cached observations for training. Report the evaluation and optimizer counts separately.
Score novelty with a frozen target¶
BR-NS measures the squared difference between a frozen random embedding and a predictor trained on observations from prior generations. It scores the parents and children before fitting on the new children. The live population and pending generation bound the observation memory. QDpy initializes both networks directly on the supplied observation shape. [Salehi2021]
from qdpy.algorithms import BRNS
search = BRNS(dimension=6, embedding_size=32, seed=11)
stats = search.run(evaluate, budget=512)
candidate = search.population[0]
print(search.novelty(candidate.observation), stats.model_updates)
The current novelty score may change after a fit. Use a separate reporting archive during evaluation to track which behaviors were measured. A familiar observation can become novel again as the predictor learns from later generations.
Train policies with diverse state and action visitation¶
QD-DualDICE-JS estimates discounted occupancy ratios for pairs of policies. Each pair fits a potential and a density-ratio network with the DualDICE saddle objective. The ratios give a Jensen–Shannon kernel and a pseudo-reward for its derivative. The Stein update combines reward gradients and kernel repulsion across members, using the same pre-update policies for all contributions. [Gangwani2021]
from qdpy.rl import PolicyConfig, QDDualDICEConfig, QDDualDICEJS
trainer = QDDualDICEJS(
make_environment, population_size=3, policy=PolicyConfig((32,)),
config=QDDualDICEConfig(gamma=.9, episodes_per_update=8),
max_episode_steps=64, seed=11,
)
stats = trainer.train(8_192)
print(stats.env_steps, stats.estimator_steps, trainer.last_divergences)
for index, actor in enumerate(trainer.policies()):
actor.save(f"ensemble-{index}.npz")
Install qdpy[rl] for this workflow. Use numeric Box observations and
bounded Box, Discrete, or unmasked MultiDiscrete actions. A completed
episode contributes its discounted trajectory and the residual mass of a
common absorbing state. A budget-cut prefix counts toward the real step
budget. Completed episodes from that call remain in the current panel.
The published experiments used clipped PPO gradients. QDpy uses
discounted Monte Carlo score-function gradients for the task reward
and the ratio pseudo-reward. The estimator uses both directional
ratios and clips estimated divergences to their theoretical range.
last_divergences describes the ensemble immediately before its
last actor update. Set diversity_weight=0. for a control that keeps
the reward kernel and skips its repulsive gradient. Estimator work
grows with the number of directed policy pairs, so start with a
small ensemble. Actor files use the existing
CategoricalPolicy.load or ContinuousPolicy.load API.
Reproduce the CPU comparisons¶
The example script prints
one JSON record for each method and seed.
python -I examples/learned_exploration.py mutation
python -I examples/learned_exploration.py learned
python -I examples/learned_exploration.py dice
The commands use seeds 11, 22, 33, 44, and 55. The fixed mutation strength is tuned separately for each function on seeds 173, 231, and 317. The sparse-reward example maps observations to a shared audit grid using true endpoints. SERENE receives those endpoints as descriptors. The learned searches receive only the observations.
With 600 evaluations, tuned fixed mutation gave the highest mean QD score on all three landscapes. Self-adaptation filled more cells on Ackley (96.2 versus 91.4) and Rosenbrock (95.8 versus 91.8).
Landscape |
Tuned fixed |
Coverage |
Annealed |
Inherited |
|---|---|---|---|---|
Rastrigin |
1.252 |
0.872 |
0.973 |
1.204 |
Ackley |
11.452 |
8.020 |
8.683 |
11.086 |
Rosenbrock |
3.377 |
2.631 |
2.743 |
3.038 |
With 480 evaluator calls on the sparse task, STAX averaged 19.6 rewarding cells and a rewarding QD score of 9.90. SERENE averaged 19.4 cells and 9.62. TAXONS and BR-NS covered more audit cells in total than STAX and reached 15.8 and 13.6 rewarding cells, respectively.
The two-step policy fixture has two routes to the same maximum return. At 1,440 steps, adding Stein repulsion increased exact mean pairwise Jensen–Shannon divergence from 0.012 to 0.084. Mean expected return fell from 0.961 to 0.840. Before the last actor update, the ratio model estimated mean divergence at 0.137 on the repulsive run, with an exact value of 0.082 on the same policies. These means describe small seeded CPU fixtures. The JSON includes the cost and audit values for each run.