Gradient-informed search on categorical genomes =============================================== Use ME-GIDE if you evaluate integer designs and can differentiate a relaxation of their objective and descriptors. A genome with two categories in one coordinate and three in the next has five one-hot columns. An edit at the second coordinate compares derivatives within the last three columns. This example scores one selected entry per block, so the derivative of the one-hot relaxation is just the array of coefficients. .. code-block:: python import numpy as np from qdpy.algorithms import GradientEvaluation, MEGIDE from qdpy.containers import Grid nvec = (2, 3) offsets = np.array([0, 2]) jacobian = np.array([[0.1, 0.8, 0.2, 0.4, 0.1], [0.0, 0.5, 0.0, 0.25, 0.5]]) def evaluate(candidate): chosen = offsets + candidate fitness, descriptor = jacobian[:, chosen].sum(axis=1) return GradientEvaluation(fitness, (descriptor,), jacobian) archive = Grid(shape=5, fitness_domain=((0, 2),), features_domain=((0, 1),), fitness_weights=(1.0,)) search = MEGIDE(archive, budget=64, nvec=nvec, batch_size=8, entropy_fraction=.6, seed=11) search.optimise(evaluate) print(archive.filled_bins, archive.best.fitness.values) In a nonlinear problem, return the measured discrete objective and descriptor, with derivatives evaluated at the one-hot representation of that candidate. QDpy uses the derivatives of retained elites to guide edits. Keep the evaluator fixed within a run and treat stored genomes and measurements as read-only. A prepopulated grid supplies incumbents for admission immediately. An elite supplies gradients after the search evaluates and retains it. The emitter normalizes objective and descriptor gradients by row, draws a random direction, and samples one category from the joint distribution over one-hot entries. The distribution includes the current category in each block, so an edit can leave a candidate unchanged. Use ``entropy_fraction=1`` for uniform entries. A value of zero samples uniformly among the strongest tied directions. If ties prevent the requested entropy, the emitter uses the closest attainable value. Every call to the evaluator spends a candidate attempt. See :doc:`repertoire_qd_benchmarks` for the guided and uniform comparison. `Boige et al., Gradient-Informed Quality Diversity for the Illumination of Discrete Spaces, GECCO 2023 `_.