Class AhrensDieterExponentialSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.SamplerBase
-
- org.apache.commons.rng.sampling.distribution.AhrensDieterExponentialSampler
-
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
public class AhrensDieterExponentialSampler extends SamplerBase implements SharedStateContinuousSampler
Sampling from an exponential distribution.Sampling uses:
- Since:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private static double[]
EXPONENTIAL_SA_QI
Table containing the constants \( q_i = sum_{j=1}^i (\ln 2)^j / j! = \ln 2 + (\ln 2)^2 / 2 + ...private double
mean
The mean of this distribution.private UniformRandomProvider
rng
Underlying source of randomness.
-
Constructor Summary
Constructors Modifier Constructor Description AhrensDieterExponentialSampler(UniformRandomProvider rng, double mean)
private
AhrensDieterExponentialSampler(UniformRandomProvider rng, AhrensDieterExponentialSampler source)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateContinuousSampler
of(UniformRandomProvider rng, double mean)
Create a new exponential distribution sampler.double
sample()
Creates adouble
sample.java.lang.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.-
Methods inherited from class org.apache.commons.rng.sampling.distribution.SamplerBase
nextDouble, nextInt, nextInt, nextLong
-
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
-
EXPONENTIAL_SA_QI
private static final double[] EXPONENTIAL_SA_QI
Table containing the constants \( q_i = sum_{j=1}^i (\ln 2)^j / j! = \ln 2 + (\ln 2)^2 / 2 + ... + (\ln 2)^i / i! \) until the largest representable fraction below 1 is exceeded. Note that \( 1 = 2 - 1 = \exp(\ln 2) - 1 = sum_{n=1}^\infinity (\ln 2)^n / n! \) thus \( q_i \rightarrow 1 as i \rightarrow +\infinity \), so the higher \( i \), the closer we get to 1 (the series is not alternating). By trying, n = 16 in Java is enough to reach 1.
-
mean
private final double mean
The mean of this distribution.
-
rng
private final UniformRandomProvider rng
Underlying source of randomness.
-
-
Constructor Detail
-
AhrensDieterExponentialSampler
public AhrensDieterExponentialSampler(UniformRandomProvider rng, double mean)
- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean of this distribution.- Throws:
java.lang.IllegalArgumentException
- ifmean <= 0
-
AhrensDieterExponentialSampler
private AhrensDieterExponentialSampler(UniformRandomProvider rng, AhrensDieterExponentialSampler source)
- Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Detail
-
sample
public double sample()
Creates adouble
sample.- Specified by:
sample
in interfaceContinuousSampler
- Returns:
- a sample.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classSamplerBase
-
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:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateContinuousSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
of
public static SharedStateContinuousSampler of(UniformRandomProvider rng, double mean)
Create a new exponential distribution sampler.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean of the distribution.- Returns:
- the sampler
- Throws:
java.lang.IllegalArgumentException
- ifmean <= 0
- Since:
- 1.3
-
-