Few-shot priors, basin search, and semantic trade-offs¶
FAERY learns starting genomes for related tasks. HillVallEA finds distinct optima from fitness measurements alone. QDEvo keeps several objective trade-offs within clusters of similar heuristics.
Learn a reusable prior with FAERY¶
Separate training tasks from held-out tasks. Supply an evaluator that reports fitness, descriptors, and whether the candidate solved the task. A candidate can solve the task even if its archive cell is full.
from examples.few_shot_qd import evaluate_design, mutate_design, task_grid
from qdpy.algorithms import FAERY
search = FAERY(task_grid, mutate_design, task_budget=36, offspring=3, seed=11)
initial = ((.2, .4, .1), (.8, .4, .7), (.5, .5, .9))
training = ((.24, .30), (.28, .51), (.81, .35), (.74, .54))
learned = search.fit(initial, training, evaluate_design, generations=5)
transfer = search.adapt(learned.prior, (.77, .34), evaluate_design, 18, seed=22)
print(learned.evaluations, transfer.first_success, transfer.evaluations)
Each outer generation tests the prior and its mutated candidates in the same inner search on each selected training task. Successful genomes credit their originating prior index. Direct successes have depth zero, and each mutation adds one. Pareto selection favors a higher count of distinct successes and a lower mean depth.
The paper uses novelty and fitness in its experimental inner loop.
QDpy uses mutation-only MAP-Elites with a caller-supplied grid per
task. The inner budget counts initial genomes and offspring. Set
success_limit to stop producing offspring once enough distinct
successes have been measured. Initial genomes are always measured.
The history records each candidate’s count and mean depth.
A held-out adaptation starts with a fresh archive and its own budget.
Salehi, Coninx, and Doncieux, Few-shot Quality-Diversity Optimization.
Find distinct optima from fitness alone¶
HillVallEA uses the existing cma extra. Install it with either
pip install "qdpy[cma]" or uv pip install "qdpy[cma]".
from examples.few_shot_qd import basin_cost
from qdpy.algorithms import HillVallEA
search = HillVallEA(((0., 1.),) * 2, maximise=False,
initial_samples=32, fitness_tolerance=.002, seed=11)
result = search.run(basin_cost, 540)
print(result.peaks, result.best)
print(result.samples, result.probes, result.local_evaluations)
The search sorts sampled points by fitness. For each point, it probes
toward nearby, better-ranked points. A probe worse than both endpoints
signals separation. The search then refines each newly discovered
cluster with a local optimizer and checks whether the result belongs
to an existing basin. Use fitness_tolerance to set the quality gap
allowed among retained basin representatives. The best measured point
is available separately, including when the budget ends mid-comparison.
QDpy normalizes decision coordinates to a unit box and uses CMA-ES for local refinement. The paper compares CMSA and AMaLGaM variants. Sampling, local refinement, and line probes all spend the same budget. The finite line tests give a heuristic estimate of basin membership. Maree, Alderliesten, Thierens, and Bosman, Real-Valued Evolutionary Multi-Modal Optimization driven by Hill-Valley Clustering.
Keep local trade-offs between similar heuristics¶
The scheduling example returns two minimization objectives, tardiness and the number of priority terms evaluated. It measures semantic similarity through the resulting job orders on a fixed set of cases.
import numpy as np
from examples.few_shot_qd import schedule, schedule_metrics, schedule_proposal
from qdpy.algorithms import QDEvo
cases = [(np.array([4, 1, 3, 2]), np.array([2., 5., 3., 6.]))]
def embed(rule):
return np.argsort(schedule(rule, cases[0])[0]) - 1.5
search = QDEvo(propose=schedule_proposal, embed=embed,
evaluate=lambda rule: schedule_metrics(rule, cases),
fitness_weights=(-1., -1.), similarity=.85, seed=11)
stats = search.run(20, initial=((0, 1, 0), (0, 0, 1), (1, 1, 1)))
print(stats.evaluations)
for cluster in search.clusters:
print([(entry.heuristic, entry.objectives) for entry in cluster])
A candidate joins the first cluster where its cosine similarity to
every retained member meets the threshold. Pareto dominance determines
survival within that cluster. Global dominance permits a distinct
cluster to retain a different heuristic. Set similarity=-1 to
compare against one global front. The proposer receives the parents’
measured objectives and normalized embeddings.
Use a separate audit to compare retained heuristics on unseen instances.
This implementation covers semantic survival and parent selection. Caller callbacks supply proposals and embeddings. The preprint uses code embeddings and a model-driven reflection loop. The example uses behavioral embeddings and seeded variation over a fixed rule grammar. QDEvo preprint. See Reflect on QDEvo parent measurements for a model that proposes revisions from measured parent performance.
Run the comparisons¶
python -m examples.few_shot_qd transfer
python -m examples.few_shot_qd basins
python -m examples.few_shot_qd semantic
The Few-shot priors, basin search, and semantic trade-offs page lists the measured budgets and results.