Skip to content

feat: add Randomized LatinHypercube sampler - #251

Open
Samuel-Vangu wants to merge 3 commits into
esa:developfrom
Samuel-Vangu:feat/add-randomized-latinhypercube-sampler
Open

feat: add Randomized LatinHypercube sampler#251
Samuel-Vangu wants to merge 3 commits into
esa:developfrom
Samuel-Vangu:feat/add-randomized-latinhypercube-sampler

Conversation

@Samuel-Vangu

Copy link
Copy Markdown

Description

Summary of changes

  • Adds RandomizedLatinHypercube, a randomized Latin Hypercube (LHS) sampler, shaped like Sobol/Halton/RNG — plugs into MonteCarlo.integrate via the existing rng= slot, no changes to MonteCarlo itself.
  • torch backend: pure PyTorch implementation (independent random permutation per dimension via argsort on random keys, plus independent uniform jitter within each stratum), generated directly on the target device — no NumPy/SciPy round-trip, same rationale as Halton's torch path (no native LHS engine exists in torch.quasirandom either).
  • numpy / jax / tensorflow backends: scipy.stats.qmc.LatinHypercube (already a hard dependency), converted to the requested backend.
  • No scramble parameter (unlike Sobol/Halton): this sampler is always the randomized (jittered) LHS variant; there is no deterministic/unrandomized mode to expose.
  • size entries (N, dim) accept any strictly positive whole number, not necessarily int (e.g. 4.0 is accepted and converted); non-whole or non-positive values raise ValueError, non-numeric/bool values raise TypeError.
  • Adds randomized_lhs_test.py, mirroring sobol_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 flow
  • test_lhs_exact_stratification: exact-equality check (no tolerance) that every dimension is a perfect bijection onto its n strata
  • test_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 development
  • test_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

@Samuel-Vangu

Copy link
Copy Markdown
Author

Hi @gomezzz, this one's ready for CI whenever you get a chance — thanks!

@Samuel-Vangu

Copy link
Copy Markdown
Author

Hi @gomezzz, pushed the ruff format fix — could you approve/trigger the CI run when you
get a chance? Thanks!

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