public class GaussianSampler extends Object implements SharedStateContinuousSampler
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.
Constructor and Description |
---|
GaussianSampler(NormalizedGaussianSampler normalized,
double mean,
double standardDeviation) |
Modifier and Type | Method and Description |
---|---|
static SharedStateContinuousSampler |
of(NormalizedGaussianSampler normalized,
double mean,
double standardDeviation)
Create a new normalised Gaussian sampler.
|
double |
sample()
Creates a
double 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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
samples, samples
public GaussianSampler(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
normalized
- Generator of N(0,1) Gaussian distributed random numbers.mean
- Mean of the Gaussian distribution.standardDeviation
- Standard deviation of the Gaussian distribution.IllegalArgumentException
- if standardDeviation <= 0
or is infinite;
or mean
is infinitepublic double sample()
double
sample.sample
in interface ContinuousSampler
public SharedStateContinuousSampler withUniformRandomProvider(UniformRandomProvider rng)
Note: This function is available if the underlying NormalizedGaussianSampler
is a SharedStateSampler
.
Otherwise a run-time exception is thrown.
withUniformRandomProvider
in interface SharedStateSampler<SharedStateContinuousSampler>
rng
- Generator of uniformly distributed random numbers.UnsupportedOperationException
- if the underlying sampler is not a
SharedStateSampler
or
does not return a NormalizedGaussianSampler
when sharing state.public static SharedStateContinuousSampler of(NormalizedGaussianSampler normalized, double mean, double standardDeviation)
Note: The shared-state functionality is available if the NormalizedGaussianSampler
is a SharedStateSampler
.
Otherwise a run-time exception will be thrown when the sampler is used to share state.
normalized
- Generator of N(0,1) Gaussian distributed random numbers.mean
- Mean of the Gaussian distribution.standardDeviation
- Standard deviation of the Gaussian distribution.IllegalArgumentException
- if standardDeviation <= 0
or is infinite;
or mean
is infinitewithUniformRandomProvider(UniformRandomProvider)
Copyright © 2016–2022 The Apache Software Foundation. All rights reserved.