scipy.stats.qmc.LatinHypercube¶
- class scipy.stats.qmc.LatinHypercube(d, *, centered=False, seed=None)[source]¶
Latin hypercube sampling (LHS).
A Latin hypercube sample [1] generates \(n\) points in \([0,1)^{d}\). Each univariate marginal distribution is stratified, placing exactly one point in \([j/n, (j+1)/n)\) for \(j=0,1,...,n-1\). They are still applicable when \(n << d\). LHS is extremely effective on integrands that are nearly additive [2]. LHS on \(n\) points never has more variance than plain MC on \(n-1\) points [3]. There is a central limit theorem for LHS [4], but not necessarily for optimized LHS.
- Parameters
- dint
Dimension of the parameter space.
- centeredbool, optional
Center the point within the multi-dimensional grid. Default is False.
- seed{None, int,
numpy.random.Generator
}, optional If seed is None the
numpy.random.Generator
singleton is used. If seed is an int, a newGenerator
instance is used, seeded with seed. If seed is already aGenerator
instance then that instance is used.
References
- 1
Mckay et al., “A Comparison of Three Methods for Selecting Values of Input Variables in the Analysis of Output from a Computer Code”, Technometrics, 1979.
- 2
M. Stein, “Large sample properties of simulations using Latin hypercube sampling.” Technometrics 29, no. 2: 143-151, 1987.
- 3
A. B. Owen, “Monte Carlo variance of scrambled net quadrature.” SIAM Journal on Numerical Analysis 34, no. 5: 1884-1910, 1997
- 4
Loh, W.-L. “On Latin hypercube sampling.” The annals of statistics 24, no. 5: 2058-2080, 1996.
Examples
Generate samples from a Latin hypercube generator.
>>> from scipy.stats import qmc >>> sampler = qmc.LatinHypercube(d=2) >>> sample = sampler.random(n=5) >>> sample array([[0.1545328 , 0.53664833], # random [0.84052691, 0.06474907], [0.52177809, 0.93343721], [0.68033825, 0.36265316], [0.26544879, 0.61163943]])
Compute the quality of the sample using the discrepancy criterion.
>>> qmc.discrepancy(sample) 0.019558034794794565 # random
Finally, samples can be scaled to bounds.
>>> l_bounds = [0, 2] >>> u_bounds = [10, 5] >>> qmc.scale(sample, l_bounds, u_bounds) array([[1.54532796, 3.609945 ], # random [8.40526909, 2.1942472 ], [5.2177809 , 4.80031164], [6.80338249, 3.08795949], [2.65448791, 3.83491828]])
Methods
fast_forward
(n)Fast-forward the sequence by n positions.
random
([n])Draw n in the half-open interval
[0, 1)
.reset
()Reset the engine to base state.