20def select_youth(archive, count, *, rng=None):
31 return archive[randrange(first, size)
if rng
is None else rng.integers(first, size)]
37 """Draw uniformly from the last parent_window current archive admissions.
39 Successful insertions and replacements appear at the end of the native
40 Grid or CVTGrid storage. Rejected offspring leave that order unchanged.
41 The list therefore reflects the youngest retained parents, including
42 when starting from a prefilled archive. Each generation commits
43 feedback in proposal order. Manual evaluations use ask_batch() and
46 :param container: Best-only regular Grid or CVTGrid.
47 :param budget: Candidate evaluation attempts.
48 :param dimension: Number of real genome coordinates.
49 :param parent_window: Maximum number of recent elites eligible for sampling.
50 :param ind_domain: Common lower and upper bounds for each coordinate.
51 :param sigma: Standard deviation of default Gaussian mutation.
52 :param mutate: Optional callable taking (parent_tuple, rng) and returning a genome.
53 :param seed: Private seed.
54 :param kwargs: Native algorithm settings such as batch_size.
57 _requires_proposed_genome =
True
59 def __init__(self, container, budget, dimension, *, parent_window=16, ind_domain=(0., 1.),
60 sigma=.1, mutate=
None, seed=0, **kwargs):
61 if (type(container)
not in (Grid, CVTGrid)
or container.max_items_per_bin != 1
62 or container.discard_random_on_bin_overload):
63 raise ValueError(
"YouthMAPElites requires a best-only Grid or CVTGrid.")
64 if not 0 <= sigma < np.inf
or (mutate
is not None and not callable(mutate)):
65 raise ValueError(
"Use a finite nonnegative sigma and an optional mutation callback.")
68 raise ValueError(
"Use decision bounds with a finite span.")
69 self.
parent_window = _positive_int(parent_window,
"parent_window")
71 dimension = _positive_int(dimension,
"dimension")
73 for item
in container:
74 genome = np.asarray(item, dtype=float)
75 if genome.shape != (dimension,)
or not np.all((genome >= lo) & (genome <= hi)):
76 raise ValueError(
"Existing elites must be bounded real genomes of the configured length.")
77 if container.fitness_weights
is not None:
78 kwargs.setdefault(
"optimisation_task", tuple(container.fitness_weights))
79 super().__init__(container, _positive_int(budget,
"budget"), dimension=dimension, **kwargs)
82 """Reset the proposal stream and recover admission order from the current archive."""
84 self.
_rng = np.random.default_rng(self.
seed)
97 genome = np.asarray(self.
mutate(parent, self.
_rng), dtype=float)
99 if genome.shape != (self.
dimension,)
or not np.all((genome >= lo) & (genome <= hi)):
100 raise ValueError(
"Mutation must return a finite bounded genome of the configured length.")