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
FieldsModifier and TypeFieldDescriptionprivate static final double[]Table containing the constants \( q_i = sum_{j=1}^i (\ln 2)^j / j! = \ln 2 + (\ln 2)^2 / 2 + ...private final doubleThe mean of this distribution.private final UniformRandomProviderUnderlying source of randomness. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateAhrensDieterExponentialSampler(double mean, UniformRandomProvider rng) AhrensDieterExponentialSampler(UniformRandomProvider rng, double mean) Create an instance. -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateContinuousSamplerof(UniformRandomProvider rng, double mean) Create a new exponential distribution sampler.doublesample()Creates adoublesample.toString()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 SamplerBase
nextDouble, nextInt, nextInt, nextLongMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ContinuousSampler
samples, samples
-
Field Details
-
EXPONENTIAL_SA_QI
private static final double[] EXPONENTIAL_SA_QITable 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 meanThe mean of this distribution. -
rng
Underlying source of randomness.
-
-
Constructor Details
-
AhrensDieterExponentialSampler
Create an instance.- Parameters:
rng- Generator of uniformly distributed random numbers.mean- Mean of this distribution.- Throws:
IllegalArgumentException- ifmean <= 0
-
AhrensDieterExponentialSampler
- Parameters:
mean- Mean.rng- Generator of uniformly distributed random numbers.
-
-
Method Details
-
sample
public double sample()Creates adoublesample.- Specified by:
samplein interfaceContinuousSampler- Returns:
- a sample.
-
toString
- Overrides:
toStringin classSamplerBase
-
withUniformRandomProvider
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
Create a new exponential distribution sampler.- Parameters:
rng- Generator of uniformly distributed random numbers.mean- Mean of the distribution.- Returns:
- the sampler
- Throws:
IllegalArgumentException- ifmean <= 0- Since:
- 1.3
-