Benchmarks and search operators¶
Benchmark evaluators¶
An analytic function such as the sphere or Rastrigin computes objective
values. The associated QD benchmark supplies genome bounds, the objective
direction, and compatible archive domains. Its evaluator returns objective
values, a genome prefix as the descriptors, and named scores. The
perf score is the first objective. Set nb_features to the number
of coordinates the archive should use and supply at least that many genome
coordinates.
from qdpy.benchmarks import NormalisedRastriginBenchmark
from qdpy.containers import Grid
benchmark = NormalisedRastriginBenchmark(nb_features=2)
archive = Grid(
shape=(4, 4),
fitness_domain=benchmark.fitness_domain,
features_domain=benchmark.features_domain,
)
fitness, descriptors, scores = benchmark.fn([0.5, 0.5, 0.5])
The fitness and both descriptors fit the grid’s declared domains. Use
benchmark.ind_domain and benchmark.default_task when building
the optimiser. Powell requires a positive multiple of four genome
coordinates. The benchmark regression tests check reference values for the
corrected equations. See QDpy release notes for the numerical changes.
- class qdpy.benchmarks.Benchmark(fn: Callable, ind_domain: Tuple[float, float], fitness_domain: Sequence[Tuple[float, float]], features_domain: Sequence[Tuple[float, float]], default_task: str = 'minimisation')[source]¶
Describe an evaluator and compatible search and archive domains.
- Parameters:
fn – Evaluation callable used by the search.
ind_domain – Common lower and upper genome coordinate bounds.
fitness_domain – One interval per returned objective.
features_domain – One interval per returned behaviour descriptor.
default_task – The optimisation direction for the benchmark.
- class qdpy.benchmarks.SphereBenchmark(nb_features: int = 2)[source]¶
Minimise the sum of squared genome coordinates.
- class qdpy.benchmarks.WeightedSphereBenchmark(nb_features: int = 2)[source]¶
Minimise squared coordinates weighted by their one-based coordinate indexes.
- class qdpy.benchmarks.RotatedHyperEllipsoidBenchmark(nb_features: int = 2)[source]¶
Minimise the sum of squared prefix norms.
- class qdpy.benchmarks.RosenbrockBenchmark(nb_features: int = 2)[source]¶
Minimise Rosenbrock’s function with its curved valley toward the all-ones genome.
- class qdpy.benchmarks.NormalisedRastriginBenchmark(nb_features: int = 2)[source]¶
Minimise Rastrigin with genome coordinates and output scaled to the unit interval.
- class qdpy.benchmarks.RastriginBenchmark(nb_features: int = 2)[source]¶
Minimise the multimodal Rastrigin objective on its native coordinate domain.
- qdpy.benchmarks.illumination_planar_arm(genome)[source]¶
Return maximising fitness and two Cartesian descriptors in [0, 1].
The finite one-dimensional genome encodes relative joint angles. Coordinates are clipped to [0, 1] and mapped to [-pi, pi]. The sum of the link lengths is one. Fitness is one minus twice the population standard deviation of the normalized joint angles. This rescales the objective of the QDax Arm task to [0, 1].
- class qdpy.benchmarks.SchwefelBenchmark(nb_features: int = 2)[source]¶
Minimise Schwefel on the full coordinate range from -500 to 500.
- class qdpy.benchmarks.SmallSchwefelBenchmark(nb_features: int = 2)[source]¶
Minimise Schwefel on the narrowed coordinate range from -100 to 100.
- class qdpy.benchmarks.GriewangkBenchmark(nb_features: int = 2)[source]¶
Minimise the Griewangk sum-and-product objective.
- class qdpy.benchmarks.SumOfPowersBenchmark(nb_features: int = 2)[source]¶
Minimise absolute coordinate powers with exponents increasing from two.
- class qdpy.benchmarks.AckleyBenchmark(nb_features: int = 2)[source]¶
Minimise the Ackley objective using its default coefficients.
- class qdpy.benchmarks.StyblinskiTangBenchmark(nb_features: int = 2)[source]¶
Minimise the separable Styblinski–Tang polynomial.
- class qdpy.benchmarks.LevyBenchmark(nb_features: int = 2)[source]¶
Minimise the Lévy objective including its distinct final-coordinate term.
- class qdpy.benchmarks.Perm0dbBenchmark(nb_features: int = 2)[source]¶
Minimise the Perm 0, d, beta objective with reciprocal-index optima.
- class qdpy.benchmarks.PermdbBenchmark(nb_features: int = 2)[source]¶
Minimise the Perm d, beta objective with one-based index optima.
- class qdpy.benchmarks.TridBenchmark(nb_features: int = 2)[source]¶
Minimise the Trid objective with a fitness domain that admits negative values.
- class qdpy.benchmarks.ZakharovBenchmark(nb_features: int = 2)[source]¶
Minimise the Zakharov objective with one-based weights in its mixed terms.
- class qdpy.benchmarks.DixonPriceBenchmark(nb_features: int = 2)[source]¶
Minimise the Dixon–Price objective over adjacent coordinate pairs.
- class qdpy.benchmarks.PowellBenchmark(nb_features: int = 2)[source]¶
Minimise Powell over complete groups of four genome coordinates.
- class qdpy.benchmarks.MichalewiczBenchmark(nb_features: int = 2)[source]¶
Minimise the Michalewicz objective with its default steepness parameter.
- class qdpy.benchmarks.WavyBenchmark(nb_features: int = 2)[source]¶
Minimise the Wavy objective, combining cosine and a Gaussian envelope.
- class qdpy.benchmarks.Trigonometric02Benchmark(nb_features: int = 2)[source]¶
Minimise the second trigonometric test function with its optimum at 0.9 per coordinate.
- class qdpy.benchmarks.QingBenchmark(nb_features: int = 2)[source]¶
Minimise Qing with coordinate magnitudes given by square roots of one-based indexes.
- class qdpy.benchmarks.SmallQingBenchmark(nb_features: int = 2)[source]¶
Minimise Qing on the narrowed coordinate range from -4 to 4.
Candidate generation and variation¶
Sobol utilities return a deterministic sequence of nonzero quasi-random points. The mutation operators modify the supplied genome in place. Pass a copy when starting from an archived candidate.
- qdpy.hdsobol.gen_sobol_vectors(num, dim)[source]¶
Return the requested number of Sobol points, skipping the origin.
SciPy generates the unscrambled 32-bit Joe–Kuo sequence. Requests for zero points return an empty array with the requested width.
- Parameters:
num – Number of points, from zero through 2**32 - 1.
dim – Number of coordinates, from one through 21,201.
- Returns:
Floating-point array of shape (num, dim).
- Raises:
ValueError – If the requested count or dimension is outside the supported range.
- qdpy.hdsobol.gen_sobol_randn(num)[source]¶
Transform one-dimensional Sobol points into quasi-normal samples.
Applying the inverse standard-normal CDF to the origin-free sequence gives finite samples with no random generator state.
- qdpy.tools.sel_roulette(collection: Sequence[Any]) Sequence[Any][source]¶
Select a member by its sum of raw objective values.
The supplied values should define valid nonnegative roulette probabilities. A total of zero falls back to a uniform choice.
- qdpy.tools.sel_grid_roulette(collection: Sequence[Any]) Sequence[Any][source]¶
Select a grid member and use its cell for roulette selection.
The first draw is uniform over stored entries, so cells with more members are visited more often. The second draw applies roulette weights to the chosen cell’s population.
- qdpy.tools.mut_gaussian(individual: MutableSequence[Any], mu: float, sigma: float, mut_pb: float, bounds: Sequence[float] | None = None) MutableSequence[Any][source]¶
Add Gaussian noise to selected coordinates in place.
- Parameters:
individual – Mutable genome to vary.
mu – Mean of the perturbation.
sigma – Standard deviation of the perturbation.
mut_pb – Per-coordinate selection probability.
bounds – Optional common lower and upper clipping bounds.
- Returns:
The same mutated genome object.
- qdpy.tools.mut_polynomial_bounded(individual: MutableSequence[Any], eta: float, low: float, up: float, mut_pb: float, *, rng=None) MutableSequence[Any][source]¶
Apply bounded polynomial mutation to selected coordinates in place.
Use a strictly ordered interval and start with a genome inside its bounds. The operator uses Deb’s polynomial distribution and clips the mutated coordinates to that interval.
- Parameters:
individual – Mutable genome to vary.
eta – Distribution index controlling typical change size.
low – Lower bound shared by the coordinates.
up – Upper bound shared by the coordinates.
mut_pb – Per-coordinate selection probability.
rng – Optional random generator. Defaults to Python’s random module.
- Returns:
The same mutated genome object.
Local-optima-network landscapes¶
- class qdpy.benchmarks.MaxGaussianLandscape(centers: tuple[tuple[float, ...], ...], heights: tuple[float, ...], scales: tuple[float, ...])[source]¶
Keep distinct center rows, positive heights, and positive standard deviations.
- qdpy.benchmarks.local_optima_network(landscape, *, samples=64, radius=None, seed=0)[source]¶
Follow dominated center chains, then assign sampled escape points without local search.
- class qdpy.benchmarks.LocalOptimaNetwork(nodes: tuple[int, ...], transitions: tuple[tuple[float, ...], ...], optimum: int, descriptors: tuple[float, ...], basin_probes: int)[source]¶
Transition rows include returns to the original optimum and sum to one.
- qdpy.benchmarks.generate_local_optima_benchmarks(*, dimension=2, peaks=12, budget=64, population_size=12, offspring=12, samples=64, neighbors=5, threshold=.03, archive_capacity=256, mutation_scale=.15, novelty=True, seed=0)[source]¶
Search heights and scales under a common escape-probe panel.
Use novelty-ranked parent-plus-child survival in the eight graph features. Normalize size-dependent features by the component count. Keep all measured landscapes for downstream benchmarks independently of the bounded search memory.
- class qdpy.benchmarks.LandscapeBenchmarkResult(landscapes: tuple[MaxGaussianLandscape, ...], networks: tuple[LocalOptimaNetwork, ...], population: tuple[int, ...], novelty_archive: tuple[int, ...], evaluations: int, basin_probes: int)[source]¶
Each evaluated landscape is paired with one estimated network.
Reference benchmarks¶
- qdpy.benchmarks.pyribs_sphere(genomes)[source]¶
Implement the pyribs Sphere linear projection benchmark.
Each out-of-bounds coordinate contributes 5.12 divided by its value to its descriptor. Fitness uses the original coordinates and may be negative for points outside the nominal search domain.
- class qdpy.benchmarks.ReferenceBatch(fitness: ndarray, descriptors: ndarray, episode_steps: ndarray, simulator_steps: int)[source]¶
Fitness and descriptors preserve evaluator order.
Episode lengths count the transitions used for scoring. Simulator steps also count any computation after termination in a fixed-length scan. Both are zero for benchmarks without a simulator.
- class qdpy.benchmarks.PyribsSphereBenchmark(dimension=100)[source]¶
Use the two sums as descriptors in physical, unnormalized units.
- class qdpy.benchmarks.LunarLanderBenchmark[source]¶
Reuse one Box2D environment across candidates and close it when finished.
The first ground contact supplies horizontal position and vertical velocity. Episodes without contact use final horizontal position and the lowest vertical velocity observed after a step.
- qdpy.benchmarks.kheperax_maze(*, episode_length=250)[source]¶
Use the standard target map, final-position descriptor, and seeded upstream resets.