Class MarsagliaTsangWangDiscreteSampler.Poisson
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler.Poisson
-
- Enclosing class:
- MarsagliaTsangWangDiscreteSampler
public static final class MarsagliaTsangWangDiscreteSampler.Poisson extends java.lang.Object
Create a sampler for the Poisson distribution.
-
-
Field Summary
Fields Modifier and Type Field Description private static double
MAX_MEAN
Upper bound on the mean for the Poisson distribution.private static double
MEAN_THRESHOLD
The threshold for the mean of the Poisson distribution to switch the method used to compute the probabilities.private static java.lang.String
POISSON_NAME
The name of the Poisson distribution.
-
Constructor Summary
Constructors Modifier Constructor Description private
Poisson()
Class contains only static methods.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static SharedStateDiscreteSampler
createPoissonDistributionFromX0(UniformRandomProvider rng, double mean)
Creates the Poisson distribution by computing probabilities recursively fromX=0
.private static SharedStateDiscreteSampler
createPoissonDistributionFromXMode(UniformRandomProvider rng, double mean)
Creates the Poisson distribution by computing probabilities recursively upward and downward fromX=mode
, the location of the largest p-value.static SharedStateDiscreteSampler
of(UniformRandomProvider rng, double mean)
Creates a sampler for the Poisson distribution.private static void
validatePoissonDistributionParameters(double mean)
Validate the Poisson distribution parameters.
-
-
-
Field Detail
-
POISSON_NAME
private static final java.lang.String POISSON_NAME
The name of the Poisson distribution.- See Also:
- Constant Field Values
-
MAX_MEAN
private static final double MAX_MEAN
Upper bound on the mean for the Poisson distribution.The original source code provided in Marsaglia, et al (2004) has no explicit limit but the code fails at mean
>= 1941
as the transform to compute p(x=mode) produces infinity. Use a conservative limit of 1024.- See Also:
- Constant Field Values
-
MEAN_THRESHOLD
private static final double MEAN_THRESHOLD
The threshold for the mean of the Poisson distribution to switch the method used to compute the probabilities. This is taken from the example software provided by Marsaglia, et al (2004).- See Also:
- Constant Field Values
-
-
Method Detail
-
of
public static SharedStateDiscreteSampler of(UniformRandomProvider rng, double mean)
Creates a sampler for the Poisson distribution.Any probability less than 2-31 will not be observed in samples.
Storage requirements depend on the tabulated probability values. Example storage requirements are listed below.
mean table size kB 0.25 882 0.88 0.5 1135 1.14 1 1200 1.20 2 1451 1.45 4 1955 1.96 8 2961 2.96 16 4410 4.41 32 6115 6.11 64 8499 8.50 128 11528 11.53 256 15935 31.87 512 20912 41.82 1024 30614 61.23
Note: Storage changes to 2 bytes per index between
mean=128
andmean=256
.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Returns:
- Sampler.
- Throws:
java.lang.IllegalArgumentException
- ifmean <= 0
ormean > 1024
.
-
validatePoissonDistributionParameters
private static void validatePoissonDistributionParameters(double mean)
Validate the Poisson distribution parameters.- Parameters:
mean
- Mean.- Throws:
java.lang.IllegalArgumentException
- ifmean <= 0
ormean > 1024
.
-
createPoissonDistributionFromX0
private static SharedStateDiscreteSampler createPoissonDistributionFromX0(UniformRandomProvider rng, double mean)
Creates the Poisson distribution by computing probabilities recursively fromX=0
.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Returns:
- Sampler.
-
createPoissonDistributionFromXMode
private static SharedStateDiscreteSampler createPoissonDistributionFromXMode(UniformRandomProvider rng, double mean)
Creates the Poisson distribution by computing probabilities recursively upward and downward fromX=mode
, the location of the largest p-value.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Returns:
- Sampler.
-
-