Class BoxMullerNormalizedGaussianSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.BoxMullerNormalizedGaussianSampler
- All Implemented Interfaces:
ContinuousSampler
,NormalizedGaussianSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
public class BoxMullerNormalizedGaussianSampler
extends Object
implements NormalizedGaussianSampler, SharedStateContinuousSampler
Box-Muller algorithm for sampling from Gaussian distribution with
mean 0 and standard deviation 1.
Sampling uses UniformRandomProvider.nextDouble()
.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate double
Next gaussian.private final UniformRandomProvider
Underlying source of randomness. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <S extends NormalizedGaussianSampler & SharedStateContinuousSampler>
Sof
(UniformRandomProvider rng) Create a new normalised Gaussian sampler.double
sample()
Creates adouble
sample.toString()
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.apache.commons.rng.sampling.distribution.ContinuousSampler
samples, samples
-
Field Details
-
nextGaussian
private double nextGaussianNext gaussian. -
rng
Underlying source of randomness.
-
-
Constructor Details
-
BoxMullerNormalizedGaussianSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.
-
-
Method Details
-
sample
public double sample()Creates adouble
sample.- Specified by:
sample
in interfaceContinuousSampler
- Returns:
- a sample.
-
toString
-
withUniformRandomProvider
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateContinuousSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static <S extends NormalizedGaussianSampler & SharedStateContinuousSampler> S of(UniformRandomProvider rng) Create a new normalised Gaussian sampler.- Type Parameters:
S
- Sampler type.- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-