feat: add Randomized LatinHypercube sampler - #251
Open
Samuel-Vangu wants to merge 3 commits into
Open
Conversation
Author
|
Hi @gomezzz, this one's ready for CI whenever you get a chance — thanks! |
Author
|
Hi @gomezzz, pushed the ruff format fix — could you approve/trigger the CI run when you |
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
Summary of changes
RandomizedLatinHypercube, a randomized Latin Hypercube (LHS) sampler, shaped likeSobol/Halton/RNG— plugs intoMonteCarlo.integratevia the existingrng=slot, no changes toMonteCarloitself.torchbackend: pure PyTorch implementation (independent random permutation per dimension viaargsorton random keys, plus independent uniform jitter within each stratum), generated directly on the target device — no NumPy/SciPy round-trip, same rationale asHalton's torch path (no native LHS engine exists intorch.quasirandomeither).numpy/jax/tensorflowbackends:scipy.stats.qmc.LatinHypercube(already a hard dependency), converted to the requested backend.scrambleparameter (unlikeSobol/Halton): this sampler is always the randomized (jittered) LHS variant; there is no deterministic/unrandomized mode to expose.sizeentries (N,dim) accept any strictly positive whole number, not necessarilyint(e.g.4.0is accepted and converted); non-whole or non-positive values raiseValueError, non-numeric/bool values raiseTypeError.randomized_lhs_test.py, mirroringsobol_test.py's structure, plus LHS-specific tests (see Test plan).Resolved Issues
How Has This Been Tested?
randomized_lhs_test.py, all backends: analytic accuracy against the test-function collection, seed reproducibility, torch gradient flowtest_lhs_exact_stratification: exact-equality check (no tolerance) that every dimension is a perfect bijection onto itsnstratatest_lhs_crushes_mc_on_additive_integrand: for a purely additive integrand, LHS's mean squared error is >100x below plain Monte Carlo's, averaged over 30 seeds — Stein's (1987) theoretical guarantee, measured at ~1200x during developmenttest_lhs_fixed_seed_is_reproducible,test_lhs_points_in_unit_cube, and 4 input-validation tests (accepts whole-valued floats, rejects non-whole/non-positive/non-numeric/bool)ruff format --check .Related Pull Requests