Skip to content

Commit 7b598d8

Browse files
committed
Make cmaes a bit faster
1 parent 3b42d65 commit 7b598d8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cmaes/_cma.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,13 @@ def tell(self, solutions: list[tuple[np.ndarray, float]]) -> None:
383383

384384
# (eq.47)
385385
rank_one = np.outer(self._pc, self._pc)
386+
386387
rank_mu = np.sum(
387-
np.array([w * np.outer(y, y) for w, y in zip(w_io, y_k)]), axis=0
388+
w_io.reshape(-1, 1, 1) * np.einsum("...i,...j->...ij", y_k, y_k), axis=0
388389
)
390+
# The above line is equivalent to:
391+
# rank_mu = np.sum(np.array([w * np.outer(y, y) for w, y in zip(w_io, y_k)]), axis=0)
392+
389393
self._C = (
390394
(
391395
1

0 commit comments

Comments
 (0)