32 """Evaluate once per proposal, then offer its measured descriptor trace.
34 By default sample from occupied cells. A parent that wins more cells
35 is drawn more often. Set parent_selection to "records" for uniform
36 choice from the retained measurements.
38 :param archive: TraceArchive to update, optionally with compatible elites.
39 :param dimension: Genome length.
40 :param ind_domain: Shared inclusive genome bounds.
41 :param iso_sigma: Independent mutation scale for Iso+LineDD.
42 :param line_sigma: Shared direction scale for Iso+LineDD.
43 :param initial_samples: Number of initial uniform samples on an empty archive.
44 :param parent_selection: Sample from "cells" or "records".
45 :param seed: Private seed for proposals and parent selection.
48 def __init__(self, archive, dimension, *, ind_domain=(0., 1.), iso_sigma=.05, line_sigma=.2,
49 initial_samples=16, parent_selection=
"cells", seed=0):
50 if not isinstance(archive, TraceArchive):
51 raise TypeError(
"Supply a TraceArchive.")
52 self.
dimension = _positive_int(dimension,
"dimension")
53 if parent_selection
not in (
"cells",
"records"):
54 raise ValueError(
"Choose cells or records for parent_selection.")
55 self.
_by_cell = parent_selection ==
"cells"
56 initial_samples = _positive_int(initial_samples,
"initial_samples")
57 self.
_bounds = _variation_settings(ind_domain, iso_sigma, line_sigma)
59 raise ValueError(
"Use a finite genome domain width.")
62 or any(
not self.
_bounds[0] <= gene <= self.
_bounds[1]
for gene
in elite.genome)):
63 raise ValueError(
"Existing trace elites must match the dimension and bounds.")
65 self.
_warmup = 0
if len(archive)
else initial_samples
67 self.
_rng = np.random.default_rng(seed)
71 def run(self, evaluate, budget):
72 """Evaluate tuples of reals and expect (scalar fitness, points) or None."""
73 budget = _positive_int(budget,
"budget")
74 if not callable(evaluate):
75 raise TypeError(
"evaluate must be callable.")
77 for _
in range(budget):
83 point = iso_line_dd(first.genome, second.genome, bounds=self.
_bounds,
86 rows = evaluate(tuple(map(float, point)))
91 updates += len(self.
archive.add(point, fitness, trace))