Skip to content

Fix DE_binary_crossover sampling from a normal instead of uniform distribution - #252

Merged
BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
Arthur031221:fix-de-binary-crossover-distribution
Oct 9, 2026
Merged

BillHuang2001 merged 1 commit into
EMI-Group:mainfrom
Arthur031221:fix-de-binary-crossover-distribution

Conversation

@Arthur031221

Copy link
Copy Markdown
Contributor

Description

DE_binary_crossover in src/evox/operators/crossover/differential_evolution.py builds the crossover mask with torch.randn(pop_size, dim, device=device) < CR, sampling from a standard normal distribution instead of a uniform [0, 1) distribution. CR is the crossover probability and is meant to be compared against a uniform draw, which is exactly what sibling implementations in de.py and ode.py do with torch.rand.

This affects SHADE, SaDE, and CoDE, which all call DE_binary_crossover. At CR=0.1 the actual fraction of genes crossed over measured 0.5655 instead of the intended ~0.1; at CR=0.9 it measured 0.8276 instead of ~0.9. Since SHADE and SaDE adapt CR toward low values to fine-tune search late in optimization, this bug means the crossover rate they converge to has little relation to the rate their adaptive mechanism computes, which changes the search behavior of all three algorithms.

Fix is a one-line change from torch.randn to torch.rand on line 53.

Tested with python -m unittest discover -s unit_test -v. Added two regression tests in unit_test/operators/test_differential_evolution.py: test_crossover_rate_matches_CR (CR=0.1, expects empirical crossover rate < 0.2) and test_high_CR_crosses_over_most_genes (CR=0.9, expects rate > 0.85). Both fail against the original code (measured 0.5655 and 0.8276) and pass with the fix. Full suite before and after: 132 baseline tests with 28 pre-existing errors and 11 skips, all unrelated (triton_kernels GPU kernel tests, supervised_learning neuroevolution tests, a distributed NCCL workflow test); after the fix, 134 tests with the same 28 errors and 11 skips, plus the two new tests passing.

Checklist

  • I have formatted my Python code with ruff.
  • I have good commit messages.
  • If adding new algorithms, problems, operators:
    • Added related test cases.
    • Added docstring to explain important parameters.
    • Added entries in the docs.

The crossover mask compared torch.randn samples against CR, the
documented crossover probability. A standard normal distribution does
not give a crossover rate close to CR, especially at low CR, which
SHADE and SaDE adapt toward to fine-tune search late in optimization.
Sibling code in de.py and ode.py already builds the same kind of mask
with torch.rand.

Measured on this repo (seed 42, pop_size=2000, dim=20, CUDA): at
CR=0.1 the empirical crossover rate was 0.5655 instead of ~0.1; at
CR=0.9 it was 0.8276 instead of ~0.9.
@BillHuang2001

Copy link
Copy Markdown
Collaborator

Thanks for the findings

@BillHuang2001
BillHuang2001 merged commit b448c04 into EMI-Group:main Oct 9, 2026
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.

2 participants