Class GaussianSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.GaussianSampler
-
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
public class GaussianSampler extends 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
-
-
Constructor Summary
Constructors Constructor Description GaussianSampler(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateContinuousSampler
of(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
Create a new normalised Gaussian sampler.double
sample()
Creates a sample.String
toString()
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.
-
-
-
Constructor Detail
-
GaussianSampler
public GaussianSampler(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
- 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:
IllegalArgumentException
- ifstandardDeviation <= 0
or is infinite; ormean
is infinite
-
-
Method Detail
-
sample
public double sample()
Creates a sample.- Specified by:
sample
in interfaceContinuousSampler
- Returns:
- a sample.
-
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
NormalizedGaussianSampler
is aSharedStateSampler
. Otherwise a run-time exception is thrown.- Specified by:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateContinuousSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Throws:
UnsupportedOperationException
- if the underlying sampler is not aSharedStateSampler
or does not return aNormalizedGaussianSampler
when 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
NormalizedGaussianSampler
is 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:
IllegalArgumentException
- ifstandardDeviation <= 0
or is infinite; ormean
is infinite- Since:
- 1.3
- See Also:
withUniformRandomProvider(UniformRandomProvider)
-
-