85 def __init__(self, archive, nvec, *, initial_samples=16, random_injection=.05,
109 def run(self, evaluate, budget, *, seed_genomes=()):
110 """Fill the supplied empty archive and return its search costs."""
111 if self.
archive or not callable(evaluate):
112 raise ValueError(
"Use an empty archive and a callable evaluator.")
113 budget = _positive_int(budget,
"budget")
114 rng = np.random.default_rng(self.
seed)
116 weights = archive.fitness_weights
117 direction = -1.
if weights
is None or weights[0] < 0.
else 1.
118 seeds, sentinel = iter(seed_genomes), object()
119 singles = tuple((column,)
for column
in range(len(self.
nvec)))
121 calls = random_calls = block_calls = accepted = fits = outside = 0
122 start_updates = archive.nb_added
126 nonlocal calls, outside
128 fitness, features = evaluate(genome)
129 result = _measurement(archive, ((fitness,), features), genome)
130 outside += result[1]
is None
131 _offer(archive, result)
132 return direction * result[0].fitness.values[0]
135 return tuple(map(int, rng.integers(self.
nvec)))
137 while calls < budget:
138 supplied = next(seeds, sentinel)
139 if supplied
is not sentinel
or calls < self.
initial_samples or len(archive) < 2
or (
141 genome = random_point()
if supplied
is sentinel
else self.
_seed_genome(supplied)
146 members = tuple(archive)
147 donors = np.asarray([tuple(member)
for member
in members], dtype=np.int64)
149 groups = learn_categorical_linkage(donors)
152 parent = int(rng.integers(len(members)))
153 incumbent = donors[parent]
154 quality = direction * archive.get_ind_fitness(members[parent]).values[0]
156 for group_id
in rng.permutation(len(groups)):
157 columns = list(groups[int(group_id)])
158 choices = np.flatnonzero(np.any(donors[:, columns] != incumbent[columns], axis=1))
161 child = incumbent.copy()
162 child[columns] = donors[int(rng.choice(choices)), columns]
163 score = measure(tuple(map(int, child)))
167 incumbent, quality = child, score
171 measure(random_point())
174 return GOMSearchStats(calls, random_calls, block_calls, accepted, fits, archive.nb_added - start_updates,