Metric archives, peer exchange, and structured variation¶
Use medoid niches for custom descriptor distances, peer archives for search with limited communication, and CMA-MEGA when you can measure analytic derivatives. The tour example builds a shortlist under a common cost ceiling. See Metric archives, peer exchange, and structured variation for the matched CPU runs.
Medoid MAP-Elites¶
A descriptor can be a set of capabilities, a sequence, or another object with a meaningful distance. Fit the archive on a reference panel of descriptors. Each medoid is an actual reference object. The search keeps the best measured candidate nearest to each medoid.
from examples.metric_peer_search import evaluate_set, jaccard, mutate_set, propose_set
from qdpy.algorithms import MedoidArchive, MedoidMAPElites
import numpy as np
panel = np.random.default_rng(701)
reference = [propose_set(panel) for _ in range(120)]
archive = MedoidArchive.fit(reference, 12, jaccard)
initial = np.random.default_rng(11)
for _ in range(16):
genome = propose_set(initial)
fitness, descriptor = evaluate_set(genome)
archive.add(genome, fitness, descriptor)
search = MedoidMAPElites(archive, propose=propose_set, mutate=mutate_set, seed=11)
search.optimise(evaluate_set, budget=176)
for cell, elite in archive.cells.items():
print(cell, elite.fitness, elite.descriptor)
The example uses immutable sets and Jaccard distance. Supply a finite
symmetric distance that returns zero for identical objects. The first
medoid wins an exact nearest-neighbor tie, and equal fitness keeps the
incumbent. Pass maximize=False to minimize the scalar fitness.
The genome is passed to mutation as stored, so use immutable genome
and descriptor values. You can also pass predefined medoids to
MedoidArchive(medoids, distance).
The example charges the 16 starting measurements separately. A broad
start helps when mutations from one elite tend to stay in its niche.
Fitting uses deterministic PAM build and swap passes on a dense distance matrix. Keep the reference panel small or supply fixed medoids when computing pairwise distances is expensive. Reference descriptors are separate from the candidate evaluation budget. For comparisons against rectangular or CVT archives, score distance to a common held-out descriptor panel. This is a CVT-inspired QDpy extension using Vassiliades, Chatzilygeroudis, and Mouret and Schubert and Rousseeuw.
Decentralized MAP-Elites¶
Each peer breeds from its own archive. Peers periodically offer copies of measured elites to their neighbors. A migrant competes under the same cell and objective rules as local candidates. The evaluator and archive geometry are shared across peers.
from examples.metric_peer_search import peer_grid, peer_measurement, peer_mutation, peer_proposal
from qdpy.algorithms import DecentralizedMAPElites
search = DecentralizedMAPElites(
peer_grid(), 6, propose=peer_proposal, mutate=peer_mutation,
topology="ring", local_batch_size=2, exchange_period=3, seed=11,
)
union = search.optimise(peer_measurement, budget=240, message_budget=48)
print(search.peer_evaluations, search.messages, search.migrant_admissions)
print(union.filled_bins, [local.filled_bins for local in search.archives])
The geometry is an empty scalar Grid or CVTGrid with one elite
per cell. Callers can vary initialization and mutation by peer.
budget counts exact calls. message_budget counts one message per
elite sent along a directed edge, including rejected migrants. Use
zero messages for isolated search and topology="complete" for
all-to-all contacts. In each exchange, senders read the same
pre-exchange state, so a new migrant can travel only one hop. The
reporting union is built independently after the search.
This QDpy variant simulates the contact graph in one process. An
optional evaluation executor can run local measurements in parallel,
with results committed in proposal order. Pass seeded=True for
evaluate(genome, seed). Use shared evaluation conditions when
comparing measurements across peers. See Hart, Steyven, and Paechter,
GECCO 2018.
CMA-MEGA with Adam¶
Install the cma extra for analytic CMA-MEGA. Provide the objective
gradient in the first row of a GradientEvaluation Jacobian, then
one row per descriptor. The centre result also competes in the
archive. Offspring need ordinary fitness and descriptor measurements.
from examples.metric_peer_search import gradient_design, gradient_measurement
from qdpy.algorithms import CMAMEGA
from qdpy.containers import Grid
grid = Grid(shape=(10, 8), features_domain=((-1., 1.), (-.31, .31)),
fitness_domain=((-1., 1.),), fitness_weights=(1.,))
search = CMAMEGA(
grid, budget=360, x0=(0.,) * 12, sigma0=.18, batch_size=8,
gradient_evaluate=gradient_design, step_size=.12, ind_domain=(-1., 1.), seed=11,
)
search.optimise(gradient_measurement)
print(grid.filled_bins, search.nb_evaluations, search.gradient_evaluations)
As in the paper, first rank new cells by objective and then
same-cell updates by their improvement. The coefficient distribution
learns from the ranked branches. Adam applies their weighted
displacement to the centre, and its moments reset when the emitter
restarts. Set centre_optimizer="gradient" for the plain update.
The total budget includes every attempted centre Jacobian and offspring
measurement. A final partial branch batch can update the grid.
Manual control uses ask_dqd(), tell_dqd(result), ask_batch(),
and tell_batch(results) in that order. An optional decision interval
clips centre steps and offspring. See
Fontaine and Nikolaidis, NeurIPS 2021.
Entropy-based evolution of tours¶
To produce alternatives for a routing problem, start from a feasible tour and supply a symmetric cost matrix and a cost ceiling. The search uses high-order entropy to diversify consecutive route segments while keeping every stored tour feasible.
from examples.metric_peer_search import routing_case, tour_cost
from qdpy.algorithms import EntropyTourSearch
distances, optimum, setup_calls = routing_case()
ceiling = 1.27 * tour_cost(distances, optimum)
search = EntropyTourSearch(distances, ceiling, 8, segment_length=3, seed=11)
result = search.run([optimum], budget=320)
print(result.entropy, result.evaluations, setup_calls)
for entry in result.tours:
print(entry.cost, entry.tour)
A tour lists each vertex once and returns to its first vertex
implicitly. Rotations and reversed tours identify the same cycle.
segment_length=3 counts two-edge segments, including those across
the closing edge, in both directions. The search tries both uniform
2-opt and a 2-opt move biased toward frequent segments. It grows
the portfolio until full, then compares the children with their
parent using changes to the segment counts. Every measured initial
tour and offspring uses a budget slot.
The example computes an exact optimum by enumeration on eight vertices. For larger instances, pass any feasible starting tour from your solver and choose an explicit ceiling. The underlying method is described by Nikfarjam et al., GECCO 2021.