Class MarsagliaNormalizedGaussianSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.MarsagliaNormalizedGaussianSampler
-
- All Implemented Interfaces:
ContinuousSampler,NormalizedGaussianSampler,SharedStateContinuousSampler,SharedStateSampler<SharedStateContinuousSampler>
public class MarsagliaNormalizedGaussianSampler extends java.lang.Object implements NormalizedGaussianSampler, SharedStateContinuousSampler
Marsaglia polar method for sampling from a Gaussian distribution with mean 0 and standard deviation 1. This is a variation of the algorithm implemented inBoxMullerNormalizedGaussianSampler.Sampling uses
UniformRandomProvider.nextDouble().- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description private doublenextGaussianNext gaussian.private UniformRandomProviderrngUnderlying source of randomness.
-
Constructor Summary
Constructors Constructor Description MarsagliaNormalizedGaussianSampler(UniformRandomProvider rng)Create an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <S extends NormalizedGaussianSampler & SharedStateContinuousSampler>
Sof(UniformRandomProvider rng)Create a new normalised Gaussian sampler.doublesample()Creates adoublesample.java.lang.StringtoString()SharedStateContinuousSamplerwithUniformRandomProvider(UniformRandomProvider rng)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 Detail
-
nextGaussian
private double nextGaussian
Next gaussian.
-
rng
private final UniformRandomProvider rng
Underlying source of randomness.
-
-
Constructor Detail
-
MarsagliaNormalizedGaussianSampler
public MarsagliaNormalizedGaussianSampler(UniformRandomProvider rng)
Create an instance.- Parameters:
rng- Generator of uniformly distributed random numbers.
-
-
Method Detail
-
sample
public double sample()
Creates adoublesample.- Specified by:
samplein interfaceContinuousSampler- Returns:
- a sample.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
withUniformRandomProvider
public SharedStateContinuousSampler withUniformRandomProvider(UniformRandomProvider rng)
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:
withUniformRandomProviderin 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
-
-