Repository navigation
Fix the CMA-ES cumulation constant c_c - #256
Merged
Merged
Conversation
c_c used (mu_eff + 2) as its numerator, which belongs to c_sigma. The tutorial (eq. 56), pycma and evosax all use c_c = (4 + mu_eff / n) / (n + 4 + 2 mu_eff / n). With the wrong numerator c_c exceeds 2 once mu_eff is large relative to n (e.g. n = 10, pop_size = 100 gives 1.49; pop_size = 1000 gives 3.95), so sqrt(c_c * (2 - c_c) * mu_eff) in the p_c update is NaN.
Collaborator
|
Thanks for the fix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The CMA-ES cumulation constant for the rank-one evolution path uses the wrong numerator:
(mu_eff + 2)is the numerator ofc_sigma, two lines above. The tutorial this class cites (Hansen, arXiv:1604.00772, eq. 56) givesand pycma and evosax use the same formula.
At the default population size the difference is moderate: with
n = 10,c_cis 0.353 instead of 0.295. It grows withmu_eff, though. Oncec_c > 1, the(1 - c_c)decay in thep_cupdate flips sign every generation. Oncec_c > 2,sqrt(c_c * (2 - c_c) * mu_eff)is NaN, and the NaN spreads intoC. Large populations are a main use case for a GPU library, so this matters:I ran 100 generations on the 10-d sphere starting at mean 3·1, with
sigma = 1. Withpop_size = 1000, the current constant makesCNaN, and the run stops withtorch._C._LinAlgError: linalg.eigh: The algorithm failed to converge. With the fixed constant it converges (best fitness 1.6e-9). This end-to-end run also needs #255, becauseCMAES.stepcurrently fails intorch.condbefore reaching this point. This PR does not depend on #255 otherwise.test_cmaes_cumulation_constantchecksc_cagainst eq. (56) for several(n, pop_size)pairs and checks that thep_cupdate stays finite. Before the fix it fails on the first case (0.3531 != 0.2950); with the fix it passes.Checklist
ruff.