Skip to content

Fix CMA-ES rank-one covariance update - #251

Merged
BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
bbopen:fix/cmaes-rank-one-covariance
Sep 21, 2026
Merged

BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
bbopen:fix/cmaes-rank-one-covariance

Conversation

@bbopen

@bbopen bbopen commented Sep 20, 2026 •

Copy link
Copy Markdown

Fix CMA-ES rank-one covariance update

The CMA-ES covariance update currently treats its 1D evolution path as a scalar dot product. For p_c = [1, 2, -1], the scalar p_c @ p_c.T is 6. Broadcasting 6 across the covariance matrix changes every entry. This patch uses torch.outer(p_c, p_c) so the update applies the required rank-one matrix.

Add focused regression checks for the isolated update with a nonzero path and no rank-mu contribution. The tests compare the full expected covariance matrix in eager mode, then check a batch of paths with torch.vmap and torch.compile. The existing disabled CMA-ES smoke test remains unchanged.

Validation on NVIDIA DGX Spark, PyTorch 2.13.0+cu130:

  • Original source with the new tests: 2 failures on CPU and 2 failures on CUDA. Both failures report covariance mismatches.
  • Fixed source: 2 passes on CPU and 2 passes on CUDA. This includes eager, vmap, and full-graph compiled vmap checks.
  • git diff --check passes.

Commands:

CUDA_VISIBLE_DEVICES='' python -m pytest -o addopts= -q unit_test/algorithms/test_es_variants.py -k covariance_rank_one
python -m pytest -o addopts= -q unit_test/algorithms/test_es_variants.py -k covariance_rank_one

This validation covers the focused regression tests. It does not cover the full algorithm suite.

Algorithm reference

Nikolaus Hansen, The CMA Evolution Strategy: A Tutorial, arXiv:1604.00772v2.

Section 3.3.2, Equation 28, page 17 defines the evolution-path contribution as $c_1 p_c p_c^T$, an outer product.
Appendix C, lines 69-71, page 37 implements this as pc*pc', with pc a column vector. It also includes the same h_sigma correction used here.

For EvoX's one-dimensional p_c tensor, torch.outer(p_c, p_c) gives that matrix. p_c @ p_c.T instead returns a scalar.

Fixes #250.

@BillHuang2001

Copy link
Copy Markdown
Collaborator

Thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CMA-ES covariance update broadcasts a scalar instead of a rank-one matrix

2 participants