This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / stats / _qmc / Halton

ABCMeta

scipy.stats._qmc:Halton

source: build-install/usr/lib/python3.14/site-packages/scipy/stats/_qmc.py:1114

Signature

def Halton(d: int, *, scramble: bool = True, optimization: Literal['random-cd', 'lloyd'] | None = None, rng: SeedType = None, seed = None) → None

Members

Summary

Halton sequence.

Extended Summary

Pseudo-random number generator that generalize the Van der Corput sequence for multiple dimensions. The Halton sequence uses the base-two Van der Corput sequence for the first dimension, base-three for its second and base- for its -dimension, with the 'th prime.

Parameters

d : int

Dimension of the parameter space.

scramble : bool, optional

If True, use random scrambling from [2]. Otherwise no scrambling is done. Default is True.

optimization : {None, "random-cd", "lloyd"}, optional

Whether to use an optimization scheme to improve the quality after sampling. Note that this is a post-processing step that does not guarantee that all properties of the sample will be conserved. Default is None.

  • random-cd: random permutations of coordinates to lower the centered discrepancy. The best sample based on the centered discrepancy is constantly updated. Centered discrepancy-based sampling shows better space-filling robustness toward 2D and 3D subprojections compared to using other discrepancy measures.

  • lloyd: Perturb samples using a modified Lloyd-Max algorithm. The process converges to equally spaced samples.

rng : `numpy.random.Generator`, optional

Pseudorandom number generator state. When rng is None, a new numpy.random.Generator is created using entropy from the operating system. Types other than numpy.random.Generator are passed to numpy.random.default_rng to instantiate a Generator.

Notes

The Halton sequence has severe striping artifacts for even modestly large dimensions. These can be ameliorated by scrambling. Scrambling also supports replication-based error estimates and extends applicability to unbounded integrands.

Examples

Generate samples from a low discrepancy sequence of Halton.
from scipy.stats import qmc
sampler = qmc.Halton(d=2, scramble=False)
sample = sampler.random(n=5)
✓
sample
✗
array([[0.     , 0.     ],
       [0.5    , 0.33333],
       [0.25   , 0.66667],
       [0.75   , 0.11111],
       [0.125  , 0.44444]])
Compute the quality of the sample using the discrepancy criterion.
qmc.discrepancy(sample)
✗
0.08889371141975322
If some wants to continue an existing design, extra points can be obtained by calling again `random`. Alternatively, you can skip some points like:
_ = sampler.fast_forward(5)
sample_continued = sampler.random(n=5)
✓
sample_continued
✗
array([[0.3125 , 0.37037],
       [0.8125 , 0.7037 ],
       [0.1875 , 0.14815],
       [0.6875 , 0.48148],
       [0.4375 , 0.81481]])
Finally, samples can be scaled to bounds.
l_bounds = [0, 2]
u_bounds = [10, 5]
✓
qmc.scale(sample_continued, l_bounds, u_bounds)
✗
array([[3.125  , 3.11111],
       [8.125  , 4.11111],
       [1.875  , 2.44444],
       [6.875  , 3.44444],
       [4.375  , 4.44444]])

Aliases

  • scipy.stats._qmc.Halton

Referenced by