Class GaussianSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.GaussianSampler
-
- All Implemented Interfaces:
ContinuousSampler,SharedStateContinuousSampler,SharedStateSampler<SharedStateContinuousSampler>
public class GaussianSampler extends java.lang.Object implements SharedStateContinuousSampler
Sampling from a Gaussian distribution with given mean and standard deviation.Note
The mean and standard deviation are validated to ensure they are finite. This prevents generation of NaN samples by avoiding invalid arithmetic (inf * 0 or inf - inf). However use of an extremely large standard deviation and/or mean may result in samples that are infinite; that is the parameters are not validated to prevent truncation of the output distribution.
- Since:
- 1.1
-
-
Field Summary
Fields Modifier and Type Field Description private doublemeanMean.private NormalizedGaussianSamplernormalizedNormalized Gaussian sampler.private doublestandardDeviationstandardDeviation.
-
Constructor Summary
Constructors Modifier Constructor Description privateGaussianSampler(double mean, double standardDeviation, NormalizedGaussianSampler normalized)GaussianSampler(NormalizedGaussianSampler normalized, double mean, double standardDeviation)Create an instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateContinuousSamplerof(NormalizedGaussianSampler normalized, double mean, double standardDeviation)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
-
mean
private final double mean
Mean.
-
standardDeviation
private final double standardDeviation
standardDeviation.
-
normalized
private final NormalizedGaussianSampler normalized
Normalized Gaussian sampler.
-
-
Constructor Detail
-
GaussianSampler
public GaussianSampler(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
Create an instance.- Parameters:
normalized- Generator of N(0,1) Gaussian distributed random numbers.mean- Mean of the Gaussian distribution.standardDeviation- Standard deviation of the Gaussian distribution.- Throws:
java.lang.IllegalArgumentException- ifstandardDeviation <= 0or is infinite; ormeanis infinite
-
GaussianSampler
private GaussianSampler(double mean, double standardDeviation, NormalizedGaussianSampler normalized)- Parameters:
mean- Mean of the Gaussian distribution.standardDeviation- Standard deviation of the Gaussian distribution.normalized- Generator of N(0,1) Gaussian 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.Note: This function is available if the underlying
NormalizedGaussianSampleris aSharedStateSampler. Otherwise a run-time exception is thrown.- Specified by:
withUniformRandomProviderin interfaceSharedStateSampler<SharedStateContinuousSampler>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Throws:
java.lang.UnsupportedOperationException- if the underlying sampler is not aSharedStateSampleror does not return aNormalizedGaussianSamplerwhen sharing state.- Since:
- 1.3
-
of
public static SharedStateContinuousSampler of(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
Create a new normalised Gaussian sampler.Note: The shared-state functionality is available if the
NormalizedGaussianSampleris aSharedStateSampler. Otherwise a run-time exception will be thrown when the sampler is used to share state.- Parameters:
normalized- Generator of N(0,1) Gaussian distributed random numbers.mean- Mean of the Gaussian distribution.standardDeviation- Standard deviation of the Gaussian distribution.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException- ifstandardDeviation <= 0or is infinite; ormeanis infinite- Since:
- 1.3
- See Also:
withUniformRandomProvider(UniformRandomProvider)
-
-