51 """Quality with Just Enough Diversity, following Templier et al. (GECCO 2024).
53 A Matérn Gaussian process models elite fitness over normalized descriptor
54 coordinates. Each occupied cell's noise is inversely proportional to its
55 number of visits. Sample target cells without replacement from the
56 posterior mean and deviation Pareto front. Start one LM-MA-ES per target
57 from the closest elite and rank proposals by normalized fitness and
58 target proximity. Every valid measurement can enter the reporting grid.
60 :param container: Fixed best-only Grid or CVTGrid with a scalar objective.
61 :param budget: Number of evaluation attempts.
62 :param dimension: Length of the real genome, at least two.
63 :param ind_domain: Common lower and upper genome bounds.
64 :param batch_size: Population size per target.
65 :param warmup: Minimum initialization attempts before using the GP.
66 :param targets_per_cycle: Maximum concurrent target strategies.
67 :param generations_per_target: Complete generations attempted per target.
68 :param sigma0: Initial genome step size.
69 :param proximity_weight: Weight of target proximity in [0, 1].
70 :param length_scale: Fixed Matérn kernel length in normalized descriptor units.
71 :param noise: Positive base observation variance in scaled fitness units.
72 :param seed: Private search seed.
73 :param kwargs: Common QDAlgorithm options, including optimisation_task.
76 _requires_proposed_genome =
True
78 def __init__(self, container, budget, dimension, ind_domain=(0., 1.), *,
79 batch_size=16, warmup=32, targets_per_cycle=3, generations_per_target=4,
80 sigma0=.1, proximity_weight=.5, length_scale=.25, noise=.01, seed=0, **kwargs):
81 if (type(container)
not in (Grid, CVTGrid)
or container.max_items_per_bin != 1
82 or container.discard_random_on_bin_overload
or container.fitness_domain
is None
83 or len(container.fitness_domain) != 1
84 or not len(container.features_domain)):
85 raise ValueError(
"JEDi requires a fixed, best-only Grid or CVTGrid with one objective.")
86 domain = np.asarray(container.features_domain, dtype=float)
90 raise ValueError(
"JEDi requires finite descriptor intervals with positive widths.")
91 self.
_cells = tuple(container.solutions)
92 if isinstance(container, CVTGrid):
95 self.
_centers = (np.asarray(self.
_cells, dtype=float) + .5) / container.shape
99 raise ValueError(
"The genome interval must have a finite width.")
100 if not (0 < sigma0 < np.inf
and 0 <= proximity_weight <= 1
and
101 0 < length_scale < np.inf
and 0 < noise < np.inf):
102 raise ValueError(
"Invalid sigma0, proximity_weight, length_scale, or noise.")
105 self.
warmup = _positive_int(warmup,
"warmup")
108 dimension, batch_size = _positive_int(dimension,
"dimension"), _positive_int(batch_size,
"batch_size")
109 if dimension < 2
or batch_size < 2:
110 raise ValueError(
"JEDi needs at least two genome coordinates and two proposals per target.")
111 self.
_memory = min(dimension, 4 + int(3 * log(dimension)))
112 super().__init__(container, _positive_int(budget,
"budget"), dimension=dimension,
113 batch_size=batch_size, **kwargs)
115 raise ValueError(
"JEDi requires a nonzero objective direction.")
118 """Reset target scheduling and visit counters while retaining the archive."""
120 self.
_rng = np.random.default_rng(self.
seed)
126 def _normalize(self, descriptors):
131 """Return a copy of the per-cell counts of valid evaluations."""
136 """Return the cell indices selected for each completed target draw."""
139 def _start_cycle(self):
140 occupied = [cell
for cell
in self.
_cells if self.
container.solutions[cell]]
141 elites = [self.
container.solutions[cell][0]
for cell
in occupied]
142 features = self.
_normalize([tuple(self.
container.get_ind_features(elite))
for elite
in elites])
145 raise ValueError(
"JEDi requires a nonzero objective direction.")
146 scores = direction * np.asarray([self.
container.get_ind_fitness(elite).values[0]
for elite
in elites])
147 variance = self.
noise / np.array([max(1, self.
_visits[cell])
for cell
in occupied])
148 gp = GaussianProcessRegressor(kernel=Matern(self.
length_scale, length_scale_bounds=
"fixed", nu=2.5),
149 alpha=np.maximum(variance, 1e-12), optimizer=
None)
150 gp.fit(self.
_centers[[self.
_positions[cell]
for cell
in occupied]], _unit_range(scores))
151 means, deviations = gp.predict(self.
_centers, return_std=
True)
152 front = _target_front(means, deviations)
157 closest = np.argmin(np.linalg.norm(features - target, axis=1))
158 center = np.asarray(elites[closest], dtype=float)
159 if (center.shape != (self.
dimension,)
or not np.isfinite(center).all()
161 raise ValueError(
"JEDi requires finite archive genomes inside ind_domain.")
179 def _check_candidate(self, individual):
180 super()._check_candidate(individual)
183 def _generation_feedback(self, position):
191 for position, individual
in enumerate(evaluated):
192 if individual
is not None:
193 cell = self.
container.index_grid(individual)
195 valid.append(position)
197 admitted.add(position)
198 if self.
_agent is not None:
199 strategy, row, remaining = self.
_agents.popleft()
200 if len(evaluated) == self.
batch_size and valid:
201 elites = [evaluated[position]
for position
in valid]
202 fitness = np.asarray([self.
container.get_ind_fitness(elite).values[0]
for elite
in elites])
203 features = self.
_normalize([tuple(self.
container.get_ind_features(elite))
for elite
in elites])
204 distances = np.linalg.norm(features - self.
_centers[row], axis=1)
207 strategy.adapt(self.
_vectors, np.asarray(valid)[np.argsort(-score, kind=
"stable")])
208 if remaining > 1
and not strategy.stop():
209 self.
_agents.append((strategy, row, remaining - 1))