57 return max(0., arm.mean - radius), min(1., arm.mean + radius)
62 """Assume deterministic descriptors and independent bounded fitness observations.
64 Race against an incumbent only within the challenger's predetermined
65 cell. Reuse the incumbent's earlier observations. Once the outsider's
66 upper bound is within epsilon of the leader's lower bound, the leader
67 is an epsilon-accurate choice under the confidence event. If the
68 rollout or pair budget ends first, use the empirical leader and
69 record an unresolved race. Exact ties retain the incumbent.
71 :param archive: Empty standalone best-only Grid or CVTGrid, with one
72 finite fitness interval covering the support of every observation.
73 Unweighted archives maximize fitness.
74 :param dimension: Real genome length.
75 :param delta: Total confidence error allowance across arms and sample counts.
76 :param epsilon: Additive fitness tolerance in original units.
77 :param initial_samples: Number of fitness observations for a new arm.
78 :param max_pairs: Maximum extra pairs per local race.
79 :param ind_domain: Shared finite, increasing genome bounds.
80 :param iso_sigma: Isotropic mutation scale.
81 :param line_sigma: Directional mutation scale.
82 :param seed: Private variation and evaluator seed.
85 def __init__(self, archive, dimension, *, delta=.05, epsilon=0., initial_samples=2,
86 max_pairs=16, ind_domain=(0., 1.), iso_sigma=.03, line_sigma=.2, seed=0):
87 if (type(archive)
not in (Grid, CVTGrid)
or len(archive)
or archive.parents
88 or archive.max_items_per_bin != 1
or archive.discard_random_on_bin_overload
89 or archive.fitness_domain
is None or len(archive.fitness_domain) != 1
90 or archive.fitness_score_names
or archive.features_score_names):
91 raise ValueError(
"Use an empty standalone scalar best-only Grid or CVTGrid.")
92 low, high = archive.fitness_domain[0]
94 weights = archive.fitness_weights
97 if (
not 0. < span < np.inf
or len(weights) != 1
or not isfinite(weights[0])
or weights[0] == 0.
98 or not 0. < delta < 1.
or not 0. <= epsilon <= span):
99 raise ValueError(
"Supply a finite fitness span, nonzero weight, delta in (0, 1), and epsilon within the span.")
101 self.
dimension = _positive_int(dimension,
"dimension")
102 self.
initial_samples = _positive_int(initial_samples,
"initial_samples")
103 self.
max_pairs = _positive_int(max_pairs,
"max_pairs")
104 self.
ind_domain = _variation_settings(ind_domain, iso_sigma, line_sigma)
106 raise ValueError(
"Use a finite genome span.")
112 self.
seed = int(np.random.SeedSequence(seed).generate_state(1, dtype=np.uint64)[0])
113 self.
_rng = np.random.default_rng(self.
seed)
119 slots = self.
_rng.integers(len(self.
archive), size=2)
120 return tuple(iso_line_dd(self.
archive[int(slots[0])], self.
archive[int(slots[1])],
124 def _observe(self, evaluate, arm):
127 fitness = float(evaluate(arm.genome, seed))
128 if not self.
_low <= fitness <= self.
_high:
129 raise ValueError(
"Fitness observations must be finite and within the declared support.")
130 fraction = (fitness - self.
_low) / self.
_span
131 return arm.observe(fraction
if self.
_maximizing else 1. - fraction)
133 def _select(self, incumbent, challenger):
134 keep = incumbent.mean >= challenger.mean
135 leader, outsider = (incumbent, challenger)
if keep
else (challenger, incumbent)
136 lower, _ = _confidence(leader, self.
_delta)
137 _, upper = _confidence(outsider, self.
_delta)
138 return leader, upper - lower <= self.
_epsilon
140 def _admit(self, winner, old=None):
146 elite._lucie_arm = winner
147 elite.scores[
"rollout_count"] = winner.samples
158 def run(self, evaluate, descriptor, budget, *, proposal_limit=None):
159 """Use evaluate(genome, seed) for fitness and descriptor(genome) for a fixed cell."""
160 if not callable(evaluate)
or not callable(descriptor):
161 raise TypeError(
"Supply callable evaluate and descriptor functions.")
162 budget = _positive_int(budget,
"budget")
163 limit = 10 * budget
if proposal_limit
is None else _positive_int(proposal_limit,
"proposal_limit")
166 incumbent_calls = proposals = outside = certified = unresolved = replacements = 0
170 features = tuple(map(float, descriptor(genome)))
171 if len(features) != len(self.
archive.features_domain)
or not all(map(isfinite, features)):
172 raise ValueError(
"Return a finite descriptor of the configured length.")
173 if not self.
archive.in_bounds(features, self.
archive.features_domain):
176 cell = self.
archive.index_grid(features)
177 front = self.
archive.solutions[cell]
178 prior = front[0]
if front
else None
179 if prior
is not None and tuple(prior) == genome:
180 revised = self.
_observe(evaluate, prior._lucie_arm)
182 self.
_admit(revised, prior)
185 challenger =
_Arm(genome, features, self._arms)
187 challenger = self.
_observe(evaluate, challenger)
193 incumbent = prior._lucie_arm
194 winner, complete = self.
_select(incumbent, challenger)
198 incumbent = self.
_observe(evaluate, incumbent)
199 challenger = self.
_observe(evaluate, challenger)
201 winner, complete = self.
_select(incumbent, challenger)
202 certified += complete
203 unresolved +=
not complete
204 replacements += winner
is challenger
205 if winner
is challenger
or winner
is not prior._lucie_arm:
206 self.
_admit(winner, prior)
209 certified, unresolved, replacements)
run(self, evaluate, descriptor, budget, *, proposal_limit=None)
Spend an additional hard budget of scalar fitness calls.