Skip to content

Fix/random state, solving #29 - #70

Merged
gAldeia merged 3 commits into
masterfrom
fix/random_state
Sep 22, 2026
Merged

gAldeia merged 3 commits into
masterfrom
fix/random_state

Conversation

@gAldeia

@gAldeia gAldeia commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator

This pull request improves the determinism and reproducibility of the Brush library by ensuring that a fixed random seed produces identical results across runs, regardless of thread scheduling. The changes affect both the C++ and Python code, update the handling of random number generation, and add comprehensive tests to verify reproducibility.
Deterministic Randomness and Reproducibility

  • The C++ engine now executes fitness evaluation and selection for each island in a deterministic order, instead of relying on thread scheduling, ensuring reproducible results when a fixed random seed is set.
  • The random number generator (Rnd) now resets its internal Box-Muller cache state (has_spare_normal, spare_normal) when seeded, and its Gaussian sampling (gasdev) implementation is made thread-safe and deterministic.
  • The Python estimator seeds the native (C++) random generator at the start of fitting if a fixed random_state is provided, making Python-side runs reproducible as well.
  • The documentation for random_state is updated to clarify that a fixed integer ensures full reproducibility, including for multi-island runs.

Testing and Validation

  • Extensive tests are added or updated in the C++ test suite to set a fixed random seed (params.set_random_state(42)) in all relevant places, and a new test (FixedSeedProducesIdenticalRuns) asserts that repeated runs with the same seed produce identical models, weights, and populations.

@gAldeia

gAldeia commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Looks good

@gAldeia
gAldeia merged commit 4bb64fe into master Sep 22, 2026
4 checks passed
@gAldeia gAldeia mentioned this pull request Sep 22, 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.

1 participant