105 def __init__(self, genomes, fitnesses, *, ind_domain=(0., 1.), maximize=
True, temperature=1.,
106 beta=1., transport_limit=.03, max_multiplier=16., bandwidth=.15, batch_size=24,
112 positive = (temperature, beta, max_multiplier, bandwidth, proposal_sigma, length_scale, noise)
116 vectors, fitness = np.asarray(genomes, dtype=float), np.asarray(fitnesses, dtype=float)
136 def run(self, budget, *, count=16):
137 """Assess budget proposals and return at most count distinct designs."""
138 budget = _positive_int(budget,
"budget")
139 count = _positive_int(count,
"count")
140 reference_rng, proposal_rng, draw_rng = map(np.random.default_rng, np.random.SeedSequence(self.
seed).spawn(3))
145 log_weights = logits - logsumexp(logits)
146 weights = np.exp(log_weights)
147 if np.any(weights == 0.):
148 active = weights > 0.
149 reference, weights, log_weights = reference[active], weights[active], log_weights[active]
155 proposals = proposal_rng.random((size, reference.shape[1]))
156 local = size - size // 4
158 proposals[:local] = reference[proposal_rng.choice(len(reference), size=local, p=weights)]
160 parents = proposal_rng.choice(len(pool), size=local, p=probabilities)
161 proposals[:local] = np.clip(points[parents] + proposal_rng.normal(0., self.
_sigma,
162 size=(local, reference.shape[1])), 0., 1.)
163 predictions = self.
_model.predict(proposals)
164 if not np.isfinite(predictions).all():
165 raise ValueError(
"The frozen reward surrogate produced nonfinite predictions.")
166 for point, score
in zip(proposals, predictions):
167 pool.setdefault(tuple(point), float(score))
169 potential, source_distance = _empirical_critic(reference, weights, proposals)
172 points = np.asarray(tuple(pool))
173 distances = cdist(points, reference)
175 critic = (potential - distances).max(axis=1)
176 with np.errstate(over=
"ignore"):
177 density = logsumexp(-.5 * np.square(distances / self.
_bandwidth) + log_weights, axis=1)
178 scores = density + self.
_reward_scale * np.asarray(tuple(pool.values())) + (
180 if not np.isfinite(scores).all():
181 raise ValueError(
"DynAMO acquisition became nonfinite. Reduce the scale ratios.")
182 probabilities = softmax(scores)
184 order = np.argsort(-(scores - scores.max() + draw_rng.gumbel(size=len(scores))), kind=
"stable")
186 if not np.isfinite(predicted).all():
187 raise ValueError(
"Predicted fitness exceeds the raw objective range.")
191 point = tuple(physical[i])
192 designs.setdefault(point,
DynAMODesign(point, float(predicted[i]), float(probabilities[i])))
193 if len(designs) == count:
195 return DynAMOResult(tuple(designs.values()), budget, solves, multiplier, source_distance)