Quality diversity through human feedback¶
QDHF learns where to place candidates in a MAP-Elites grid. An evaluator supplies quality and a fixed-width observation of each candidate’s behavior. A feedback provider sees three observations and selects the one of the two alternatives that is more similar to the anchor. The search keeps its original quality objective.
from qdpy.algorithms import qdhf_search
from qdpy.containers import Grid
grid = Grid(shape=(12,), fitness_domain=((0.0, 1.0),),
features_domain=((-1.0, 1.0),), fitness_weights=(1.0,))
def evaluate(genome):
angle, effort = genome
return 1 - (effort - 0.7)**2, (2 * angle - 1, 2 * effort - 1)
def judge(anchor, first, second):
a = anchor.raw_features[0]
return int(abs(a - second.raw_features[0]) < abs(a - first.raw_features[0]))
result = qdhf_search(
evaluate, grid, feedback=judge, budget=128, feedback_budget=24,
dimension=2, raw_feature_size=2, warmup=32, refit_every=32,
feedback_batch=6, seed=11,
)
print(result.attempts, len(result.feedback), result.fits)
print(result.projector.transform([0.3, -0.2]))
The judge in this example uses a known distance. For human feedback,
display the three measurements or render their genomes. Return
0 for the first alternative, 1 for the second, or None
to abstain. The callback executes in the search process. The result
records the attempt IDs and choices in order, which a repeated run can
use to replay the judgments. Keep the evaluator and seed with that log.
Use refit_every=None for QDHF-Base. This spends the feedback
budget on the warm-up population and freezes its projection. The online
variant spends up to feedback_batch per round. Each round samples
from the current archive after warm-up and skips annotation if fewer
than three trials are available. Abstentions count as feedback requests.
The grid is a template. Read result.archive for the final grid.
After a fit, retained trials are projected into a scratch grid. A
trial can lose its cell when the coordinates move or when a stronger
trial takes the same cell. Fits and rebinning use cached measurements.
Choose grid bounds in projected units and inspect coverage before
fixing them for an experiment. The low-dimensional linear projection
uses a squared Euclidean triplet margin. You can fit a
TripletProjector separately using an array of labeled indices.
Local Pareto, team, feedback, graph, and Bayesian QD pilots compares both schedules at equal evaluation and annotation budgets using synthetic labels.