115 def run(self, budget, *, initial_samples=16, targeting_steps=3, mutation_steps=24, refinement_steps=3,
116 dropout=.25, step_size=.08):
117 """Return an independently reproducible prediction map.
119 Target at most initial_samples descriptor points, each using
120 up to targeting_steps gradient moves. Each cycle uses mutation_steps
121 evaluated candidates, then up to refinement_steps moves for each
122 new elite. Set either gradient phase to zero for ablation.
124 budget = _positive_int(budget,
"budget")
125 initial = _positive_int(initial_samples,
"initial_samples")
126 mutation = _positive_int(mutation_steps,
"mutation_steps")
127 targeting, refinement = index(targeting_steps), index(refinement_steps)
128 if min(targeting, refinement) < 0
or not (0 <= dropout <= 1
and 0 < step_size < np.inf):
129 raise ValueError(
"Use nonnegative gradient steps, dropout in [0, 1], and a positive finite step size.")
130 active, report = _empty_geometry(self.
_source), _empty_geometry(self.
_source)
131 geometry, rng = map(np.random.default_rng, np.random.SeedSequence(self.
seed).spawn(2))
132 sobol = qmc.Sobol(len(self.
_feature_span), scramble=
True, seed=int(geometry.integers(2**32)))
133 seed_order = rng.permutation(len(self.
_genomes))
134 used = target_cost = refine_cost = drops = 0
136 def measure(point, gradient=False):
141 def offer(candidate):
142 _insert(report, candidate)
143 before = active.nb_added
144 cell = _insert(active, candidate)
145 return cell
if before != active.nb_added
else None
147 for slot
in range(min(initial, budget)):
148 target = sobol.random(1)[0]
151 first = np.argmin(np.linalg.norm(offsets, axis=1))
153 first = seed_order[slot % len(seed_order)]
156 for step
in range(targeting + 1):
159 candidate, jacobian = measure(point, step < targeting)
164 point = self.
_move(point, -(jacobian[:, 1:] / self.
_feature_span) @ distance, step_size)
167 target_cost += used - start
173 for _
in range(min(mutation, budget - used)):
175 first, second = rng.integers(len(active), size=2)
176 point = iso_line_dd(active[first], active[second], bounds=self.
ind_domain,
180 candidate, _ = measure(point)
181 cell = offer(candidate)
183 changed[cell] = candidate
184 for cell, incumbent
in changed.items():
186 for _
in range(refinement):
187 if budget - used < 2:
189 _, jacobian = measure(incumbent,
True)
194 candidate, _ = measure(point)
196 features = candidate.features.values
197 if (active.in_bounds(features, active.features_domain)
and active.index_grid(features) == cell
198 and candidate.fitness.dominates(incumbent.fitness)):
199 if offer(candidate)
is not None:
200 incumbent = candidate
203 if used < budget
and dropout
and active:
205 for candidate
in list(active):
206 if rng.random() < dropout:
207 active.discard(candidate)