Feasible Pareto fronts, analytic gradients, and diverse breeding¶
All four methods work with the base installation. Start with the small examples below and see Feasible fronts, gradients, and diverse breeding for their results.
python -m examples.feasible_diversity mome
python -m examples.feasible_diversity gradient
python -m examples.feasible_diversity nslc
python -m examples.feasible_diversity breeder
Each method supports optimise(evaluate) and explicit generations with
ask_batch() and tell_batch(results). Report one result per proposal in
proposal order. For the last manual batch, request only the remaining
number of evaluations. Use None for a failed measurement. Every attempted
slot counts, including failed ones. With a seeded search and a reproducible
evaluator, generation commits are independent of worker completion order.
FeasibleMOME¶
A design can trade off several objectives and still have hard design
limits. Return one named score per inequality, using residuals of the
form g(x) <= 0. Keep objective units and directions in the
ParetoGrid. Normalize constraints in the evaluator if their units
differ, because infeasible candidates compete using the sum of positive
residuals.
from qdpy.algorithms import FeasibleMOME
from qdpy.containers import ParetoGrid
grid = ParetoGrid(
shape=(12,), features_domain=((0., 1.),),
fitness_domain=((0., 2.), (0., 2.)), fitness_weights=(-1., 1.),
max_items_per_bin=5, truncation="crowding",
)
def evaluate(genome):
length, reinforcement, thickness = genome
target = .18 + .55 * (.55 * length + .45 * reinforcement)
offset = thickness - target
mass = .2 + .45 * reinforcement + .4 * thickness + .1 * length
stiffness = .22 + .65 * reinforcement + .33 * thickness - .13 * (length - .45)**2
return (mass, stiffness), (length,), {"thin": -.021 - offset, "thick": offset - .021}
search = FeasibleMOME(
grid, budget=320, dimension=3, batch_size=4,
constraint_names=("thin", "thick"), infeasible_parent_probability=.45,
iso_sigma=.065, line_sigma=.16, seed=11,
)
while search.nb_evaluations < search.budget:
size = min(search.batch_size, search.budget - search.nb_evaluations)
search.tell_batch([evaluate(genome) for genome in search.ask_batch(size)])
print(grid.filled_bins, grid.qd_hypervolume((2., 0.)), len(search.infeasible_elites))
The first weight minimizes mass and the second maximizes stiffness.
grid contains the feasible fronts used for coverage and hypervolume.
search.infeasible_elites exposes the separate least-violation breeder for
each cell that saw an infeasible candidate. A near-feasible breeder can help
cross a constraint boundary or populate a new cell. Set
infeasible_parent_probability=0. for a feasibility-only parent pool.
The manual loop lets you inspect both pools when a tight budget produces
no feasible elite. In that case optimise() raises when it tries to
return the best feasible candidate.
FeasibleMOME is a QDpy composition of local MOME fronts and feasibility-first comparison. See Pierrot et al., GECCO 2022 and Deb et al., 2002.
OMG-MEGA¶
When an evaluator already has analytic or autodiff gradients, return the fitness derivative in the first Jacobian row and one derivative per descriptor in the following rows. Each row has one column per gene.
from qdpy.algorithms import GradientEvaluation, OMGMEGA
from qdpy.containers import Grid
grid = Grid(shape=(8, 8), features_domain=((0., 1.),) * 2,
fitness_domain=((0., 1.),), fitness_weights=(1.,))
def evaluate(genome):
x, y, z = genome
quality = 1. - .30 * (x - .55)**2 - .20 * (y - .5)**2 - .5 * (z - .7)**2
jacobian = [[-.6 * (x - .55), -.4 * (y - .5), .7 - z],
[1., 0., 0.], [0., 1., 0.]]
return GradientEvaluation(quality, (x, y), jacobian)
search = OMGMEGA(grid, budget=352, dimension=3, batch_size=8, sigma=.16, seed=11)
search.optimise(evaluate)
print(grid.filled_bins, search.gradient_evaluations)
The search keeps a normalized gradient basis for each elite. It samples a parent and draws Gaussian coefficients along that parent’s basis. The absolute objective coefficient favors improvement in the configured direction, and signed descriptor coefficients perturb both ways along each descriptor. A zero gradient row contributes zero. Decision bounds clip the proposed genome. For a cost, use a negative fitness weight and supply the derivative of the original cost.
Every evaluation supplies its own Jacobian. Compare both the number of
candidate evaluations and Jacobian calls when benchmarking against
CMA-MAEGA or derivative-free search. Use a parentless, one-elite
Grid or CVTGrid with regular fitness and descriptors. See
Fontaine and Nikolaidis, NeurIPS 2021.
Two-descriptor NS–NSLC¶
Separate a descriptor that helps find new behaviors from the descriptor you use to compare the quality of neighboring behaviors. In the maze example the exploration descriptor is the endpoint, while the reporting descriptor describes the route’s average vertical position and turning frequency.
from examples.feasible_diversity import measure_route
from qdpy.algorithms import MultiDescriptorNSLC
def evaluate(genome):
fitness, route_style, endpoint, _ = measure_route(genome)
return fitness, route_style, {"exploration": endpoint}
search = MultiDescriptorNSLC(
budget=576, dimension=18, population_size=24, batch_size=12,
reference_capacity=48, k=6, sigma=.16, seed=11,
optimisation_task="maximisation",
)
search.optimise(evaluate)
print(search.best().fitness.values, search.reference_sizes)
The exploration score and ordinary features each have a fixed length, and the two lengths can differ. Scale coordinates within a view to set their relative importance in Euclidean distances. The search keeps one bounded novelty memory per view. It ranks the combined parent and offspring population on exploration novelty, reporting novelty, and the fraction of reporting neighbors with worse fitness. Pareto rank and crowding determine survival and parent tournaments. The search returns an unstructured population. Build a reporting grid separately if you want coverage in a specific geometry. Pairwise descriptor distances and dominance comparisons make the method best suited to modest population and memory sizes.
This QDpy variant uses bounded real-valued genomes, bounded novelty memories, and optional caller-supplied mutation. See Pugh, Soros, and Stanley, 2016, Section 4.2.4.
MAP-Elites with Passive Genetic Diversity¶
In a deceptive niche, reaching a new cell can require several mutations that first lower fitness. MEPGD keeps the best candidate for reporting and gives a different-genome non-improver a chance to become a parent through a second breeding slot in that cell.
from examples.feasible_diversity import deceptive_path
from qdpy.algorithms import MEPGD
from qdpy.containers import Grid
from qdpy.phenotype import Features, Fitness, Individual
def mutate(parent, rng):
direction = int(rng.choice((-1, 1)))
return (max(0., min(1., parent[0] + direction / 8.)),)
grid = Grid(shape=(6,), features_domain=((0., 1.),),
fitness_domain=((0., 1.),), fitness_weights=(1.,))
search = MEPGD(grid, budget=191, dimension=1, mutate=mutate, seed=11)
fitness, features = deceptive_path((0.,))
grid.add(Individual([0.], fitness=Fitness(fitness, weights=(1.,)), features=Features(features)))
search.optimise(deceptive_path)
print(grid.filled_bins, grid.best.fitness.values, search.auxiliary_admissions)
The example adds a measured starting elite before the first proposal.
That measurement is counted separately. By default a non-improver has a
30% chance to occupy or overwrite the second slot. Parent selection
samples an occupied cell uniformly and picks either slot with equal
probability when both are present. Use search.breeding_slots to inspect
second-slot occupants and grid to compute the usual archive metrics.
Setting replacement_probability=0. gives a single-slot comparison.
See Pugh, Soros, and Stanley, 2016, Section 4.3.2.