18 """Rank-based LM-MA-ES adaptation in an implicit transformation."""
20 def __init__(self, center, sigma, population, memory_size, bounds, rng):
21 self.
center = np.array(center, dtype=float)
23 dimension = len(center)
24 self.
paths = np.zeros((memory_size, dimension))
25 self.
path = np.zeros(dimension)
26 times = np.arange(memory_size, dtype=float)
27 self.
transforms = np.exp(-times * log(1.5)) / dimension
28 self.
rates = np.minimum(1., (population / dimension) * np.exp(-times * log(4.)))
29 self.
sigma_rate = min(1., 2 * population / dimension)
33 return not 1e-12 <= self.
sigma <= 1e12
or not np.isfinite(self.
paths).all()
35 def ask(self, number):
37 directions = self.
normal.copy()
39 directions = (1 - rate) * directions + rate * (directions @ path)[:,
None] * path
41 return proposals
if self.
bounds is None else np.clip(proposals, *self.
bounds)
43 def adapt(self, vectors, order):
48 weights = log(count + 0.5) - np.log(np.arange(1, count + 1))
49 weights /= weights.sum()
50 effective = 1 / (weights @ weights)
51 normal_step = weights @ self.
normal[selected]
52 self.
center = weights @ vectors[selected]
54 self.
path = (1 - rate) * self.
path + np.sqrt(effective * rate * (2 - rate)) * normal_step
55 rates = self.
rates[:,
None]
56 self.
paths = (1 - rates) * self.
paths + np.sqrt(effective * rates * (2 - rates)) * normal_step
57 exponent = rate / 2 * (np.mean(self.
path ** 2) - 1)
58 self.
sigma *= exp(min(exponent, 100))
65 """LM-MA-MAE for fixed one-elite grids and CVT grids.
67 Uses the CMA-MAE annealed thresholds and reporting archive with the
68 LM-MA-ES optimizer from Loshchilov et al. The optimizer stores direction
69 vectors instead of a square covariance matrix. No CMA extra is needed.
71 :param container: Fixed, one-elite Grid or CVTGrid.
72 :param budget: Candidate evaluations per run.
73 :param x0: Finite center vector in genome coordinates.
74 :param sigma0: Positive initial search step size.
75 :param batch_size: Population size (at least two).
76 :param threshold_min: Initial threshold in weighted quality units.
77 :param memory_size: Number of direction vectors, at most the genome
78 length. The default is the smaller of that length and
79 four plus the floor of three times the natural logarithm of the length.
80 :param kwargs: CMA-MAE threshold, seed, and native QD options.
82 Bounded candidates are clipped to the genome domain. On small problems
83 the path learning rates are capped at one. Incomplete trailing batches
84 update the archives only. Failed slots are excluded from adaptation.
87 def __init__(self, container, budget, x0, sigma0, batch_size, threshold_min, *,
88 memory_size=None, **kwargs):
90 super().__init__(container, budget, x0, sigma0, batch_size, threshold_min, **kwargs)
91 if memory_size
is None:
94 self.
memory_size = _positive_int(memory_size,
"memory_size")
96 raise ValueError(
"memory_size cannot exceed the genome length.")
98 def _check_optimizer_dependency(self):
101 def _new_strategy(self, center, *, bounded=True):
102 rng = np.random.default_rng(self._search_rng().randint(0, 2**32 - 1))
103 return _LMMAES(center, self.sigma0, self.batch_size, self.memory_size,
104 self.ind_domain
if bounded
else None, rng)
106 def _adapt_strategy(self, vectors):
107 valid = np.flatnonzero(np.isfinite(self._gains))
108 order = valid[np.argsort(-self._gains[valid], kind=
"stable")]
109 self._strategy.adapt(vectors, order)