23 """T-DominO admission following Gaier et al. (PPSN 2022).
25 Compare challenger and incumbent to the challenger and to present
26 and historical elites in the cell and its neighborhood. For each
27 objective count how many anchors the
28 candidate matches or beats, then multiply the counts. The incumbent
29 remains on a tie. Store the raw multiobjective measurements for reporting.
31 :param iterable: Optional measured individuals to offer in order.
32 :param shape: Number of cells along each descriptor axis.
33 :param fitness_domain: Raw bounds for at least two objectives.
34 :param features_domain: Bounds for each descriptor axis.
35 :param anchor_capacity: Maximum displaced objective vectors retained per cell.
36 :param neighbor_radius: Maximum coordinate difference in bins to include.
37 :param kwargs: Other Grid configuration, including fitness_weights.
40 def __init__(self, iterable=None, *, shape, fitness_domain, features_domain,
41 anchor_capacity=10, neighbor_radius=4, **kwargs):
45 raise ValueError(
"T-DominO requires positive anchor capacity, nonnegative radius and multiple objectives.")
46 if kwargs.pop(
"max_items_per_bin", 1) != 1
or kwargs.get(
"discard_random_on_bin_overload"):
47 raise ValueError(
"T-DominO requires one elite and tournament-based admission.")
48 weights = kwargs.get(
"fitness_weights")
49 if weights
is not None and (len(weights) != len(fitness_domain)
50 or not all(isfinite(w)
and w != 0
for w
in weights)):
51 raise ValueError(
"Supply one finite, nonzero direction per objective.")
53 super().__init__(
None, shape, max_items_per_bin=1, fitness_domain=fitness_domain,
54 features_domain=features_domain, **kwargs)
55 if iterable
is not None:
58 def _set_fitness_weights(self, weights):
59 if len(weights) != len(self.
fitness_domain)
or not all(isfinite(w)
and w != 0
for w
in weights):
60 raise ValueError(
"Supply one finite, nonzero direction per objective.")
61 super()._set_fitness_weights(weights)
66 if (
not all(map(isfinite, fitness.values))
or
67 not all(isfinite(w)
and w != 0
for w
in fitness.weights)):
68 raise ValueError(
"T-DominO requires finite objectives and finite, nonzero objective directions.")
72 """Return current and displaced objective vectors from the cell neighborhood."""
75 raise IndexError(
"Unknown T-DominO grid cell.")
77 spans = [range(max(0, value - radius), min(size, value + radius + 1))
78 for value, size
in zip(cell, self.
shape)]
80 for neighbor
in product(*spans):
81 anchors.extend(self.
_anchors.get(neighbor, ()))
87 """Return the integer product of win counts, optionally including a challenger anchor."""
88 return self.
_score(objectives, self.
anchors(cell), challenger, weights)
90 def _score(self, objectives, anchors, challenger, weights):
91 objectives = np.asarray(objectives, dtype=float)
92 if objectives.shape != (len(self.
fitness_domain),)
or not np.isfinite(objectives).all():
93 raise ValueError(
"Supply one finite value per objective.")
94 if challenger
is not None:
95 challenger = np.asarray(challenger, dtype=float)
96 if challenger.shape != objectives.shape
or not np.isfinite(challenger).all():
97 raise ValueError(
"Challenger must have one finite value per objective.")
98 anchors = (*anchors, challenger)
103 directions = np.ones_like(objectives)
if weights
is None else np.sign(weights)
104 if directions.shape != objectives.shape
or not np.all(np.abs(directions) == 1):
105 raise ValueError(
"Supply one finite, nonzero direction per objective.")
106 wins = objectives * directions >= np.asarray(anchors) * directions
107 return prod(map(int, wins.sum(axis=0)))
109 def _replacement_in_bin(self, individual, solutions):
110 incumbent = solutions[0]
115 challenger = self.
_score(challenger_fit.values, anchors, challenger_fit.values, incumbent_fit.weights)
116 current = self.
_score(incumbent_fit.values, anchors, challenger_fit.values, incumbent_fit.weights)
117 return 0
if challenger > current
else None
119 def _add_to_grid(self, individual, ig, raise_if_not_added_to_parents, replacement=None):
121 displaced = (
None if replacement
is None else
123 result = super().
_add_to_grid(individual, ig, raise_if_not_added_to_parents, replacement)
124 if displaced
is not None and self.
nb_added > before:
126 history.append(displaced)
129 def clear(self, also_from_parents=False):
130 """Clear both retained solutions and historical reference vectors."""
131 super().
clear(also_from_parents)
_add_to_grid(self, individual, ig, raise_if_not_added_to_parents, replacement=None)
Apply a successful storage update to per-cell bookkeeping.
tournament_score(self, cell, objectives, *, challenger=None, weights=None)
Compute a raw candidate's contextual score against the current cell anchors.