20 """Retain one reporting elite and at most one auxiliary breeder per cell.
22 A strict fitness improvement replaces the reporting elite. An
23 otherwise eligible candidate may overwrite the auxiliary slot
24 even when its fitness is lower. Parent selection samples an occupied
25 cell uniformly and chooses between its two live occupants when both
26 exist. All data in the reporting grid comes from elite competition.
28 :param container: Empty parentless best-only Grid or CVTGrid with one objective.
29 :param budget: Candidate evaluation attempts.
30 :param dimension: Number of real-valued genome coordinates.
31 :param replacement_probability: Chance a non-improving candidate occupies the second slot.
32 :param sigma: Scale of default bounded Gaussian mutation.
33 :param mutate: Optional callback taking (parent_genome, rng).
34 :param ind_domain: Common bounds for all genome coordinates.
35 :param batch_size: Number of simultaneous proposals.
36 :param seed: Private seed for parent selection, mutation, and second-slot admission.
37 :param kwargs: Native QDAlgorithm settings.
40 _requires_proposed_genome =
True
42 def __init__(self, container, budget, dimension, *, replacement_probability=.3,
43 sigma=.1, mutate=None, ind_domain=(0., 1.), batch_size=1, seed=0, **kwargs):
44 _validate_grid(container)
46 raise ValueError(
"MEPGD needs a parentless reporting archive.")
47 if not 0. <= replacement_probability <= 1.
or not 0. <= sigma < np.inf:
48 raise ValueError(
"Use probabilities in [0, 1] and finite nonnegative sigma.")
49 if mutate
is not None and not callable(mutate):
50 raise TypeError(
"mutate must be callable.")
53 raise ValueError(
"Use finite decision spans.")
56 if container.fitness_weights
is not None:
57 kwargs.setdefault(
"optimisation_task", tuple(container.fitness_weights))
58 super().__init__(container, _positive_int(budget,
"budget"),
59 dimension=_positive_int(dimension,
"dimension"),
60 batch_size=_positive_int(batch_size,
"batch_size"), **kwargs)
62 raise ValueError(
"A nonzero scalar fitness weight is required.")
65 """Reset auxiliary slots, admission counters, and random state."""
68 self.
_rng = np.random.default_rng(self.
seed)
73 """Return the second-slot occupants indexed by reporting cell."""
78 """Return the cumulative number of second-slot updates."""
87 if backup
is not None and self.
_rng.integers(2):
90 genome = np.clip(np.asarray(parent, dtype=float) + self.
_rng.normal(0., self.
sigma, self.
dimension),
93 genome = np.asarray(self.
mutate(tuple(parent), self.
_rng), dtype=float)
95 if genome.shape != (self.
dimension,)
or not np.all((genome >= lower) & (genome <= upper)):
96 raise ValueError(
"Mutation must return a bounded real genome of the configured length.")
100 def _check_candidate(self, individual):
101 super()._check_candidate(individual)
106 for slot, candidate
in enumerate(evaluated):
107 if candidate
is None:
109 cell = self.
container.index_grid(candidate)
113 if candidate == self.
_breeders.get(cell):
115 elif (front
and candidate != front[0]
and candidate != self.
_breeders.get(cell)