Class ZigguratSampler.Exponential
java.lang.Object
org.apache.commons.rng.sampling.distribution.ZigguratSampler
org.apache.commons.rng.sampling.distribution.ZigguratSampler.Exponential
- All Implemented Interfaces:
ContinuousSampler
,SharedStateContinuousSampler
,SharedStateSampler<SharedStateContinuousSampler>
- Direct Known Subclasses:
ZigguratSampler.Exponential.ExponentialMean
- Enclosing class:
ZigguratSampler
Modified ziggurat method for sampling from an exponential distribution.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Specialisation which multiplies the standard exponential result by a specified mean.Nested classes/interfaces inherited from class org.apache.commons.rng.sampling.distribution.ZigguratSampler
ZigguratSampler.Exponential, ZigguratSampler.NormalizedGaussian
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final long
Maximum deviation of concave pdf(x) below the hypotenuse value for early exit.private static final int
The number of layers in the ziggurat.private static final long[]
The alias inverse PMF.private static final byte[]
The alias map.private static final double[]
The precomputed ziggurat lengths, denoted X_i in the main text.private static final double
Beginning of tail.private static final double[]
The precomputed ziggurat heights, denoted Y_i in the main text. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate double
edgeSample
(long xx) Create the sample from the edge of the ziggurat.static ZigguratSampler.Exponential
of
(UniformRandomProvider rng) Create a new exponential sampler withmean = 1
.static ZigguratSampler.Exponential
of
(UniformRandomProvider rng, double mean) Create a new exponential sampler with the specifiedmean
.double
sample()
Creates adouble
sample.private double
sampleOverhang
(int j, long xx) Sample from overhang regionj
.private int
Select the overhang region or the tail using alias sampling.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 org.apache.commons.rng.sampling.distribution.ZigguratSampler
interpolate, nextLong, randomInt63, toString
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 Details
-
I_MAX
private static final int I_MAXThe number of layers in the ziggurat. Maximum i value for early exit.- See Also:
-
E_MAX
private static final long E_MAXMaximum deviation of concave pdf(x) below the hypotenuse value for early exit. Equal to approximately 0.0926 scaled by 2^63.- See Also:
-
X_0
private static final double X_0Beginning of tail. Equal to X[0] * 2^63.- See Also:
-
MAP
private static final byte[] MAPThe alias map. An integer in [0, 255] stored as a byte to save space. Contains the alias j for each index. j=0 is the tail; j in [1, N] is the overhang for each layer. -
IPMF
private static final long[] IPMFThe alias inverse PMF. This is the probability threshold to use the alias for j in-place of j. This has been scaled by 2^64 and offset by -2^63. It represents the numerator of a fraction with denominator 2^64 and can be compared directly to a uniform long deviate. The value probability 0.0 is Long.MIN_VALUE and is used whenj > I_MAX
. -
X
private static final double[] XThe precomputed ziggurat lengths, denoted X_i in the main text.- X_i = length of ziggurat layer i.
- X_j is the upper-left X coordinate of overhang j (starting from 1).
- X_(j-1) is the lower-right X coordinate of overhang j.
Values have been scaled by 2^-63. Contains
I_MAX + 1
entries as the final value is 0. -
Y
private static final double[] YThe precomputed ziggurat heights, denoted Y_i in the main text.- Y_i = height of ziggurat layer i.
- Y_j is the upper-left Y coordinate of overhang j (starting from 1).
- Y_(j-1) is the lower-right Y coordinate of overhang j.
Values have been scaled by 2^-63. Contains
I_MAX + 1
entries as the final value is pdf(x=0).
-
-
Constructor Details
-
Exponential
Exponential(UniformRandomProvider rng) - Parameters:
rng
- Generator of uniformly distributed random numbers.
-
-
Method Details
-
toString
-
sample
public double sample()Creates adouble
sample.- Returns:
- a sample.
-
edgeSample
private double edgeSample(long xx) Create the sample from the edge of the ziggurat.This method has been extracted to fit the main sample method within 35 bytes (the default size for a JVM to inline a method).
- Parameters:
xx
- Initial random deviate- Returns:
- a sample
-
selectRegion
private int selectRegion()Select the overhang region or the tail using alias sampling.- Returns:
- the region
-
sampleOverhang
private double sampleOverhang(int j, long xx) Sample from overhang regionj
.- Parameters:
j
- Index j (must be> 0
)xx
- Initial random deviate- Returns:
- the sample
-
withUniformRandomProvider
Create a new instance of the sampler with the same underlying state using the given uniform random provider as the source of randomness.- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
Create a new exponential sampler withmean = 1
.- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
Create a new exponential sampler with the specifiedmean
.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Returns:
- the sampler
- Throws:
IllegalArgumentException
- if the mean is not strictly positive (mean <= 0
)
-