Class KempSmallMeanPoissonSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.KempSmallMeanPoissonSampler
- All Implemented Interfaces:
DiscreteSampler,SharedStateDiscreteSampler,SharedStateSampler<SharedStateDiscreteSampler>
Sampler for the Poisson
distribution.
- Kemp, A, W, (1981) Efficient Generation of Logarithmically Distributed Pseudo-Random Variables. Journal of the Royal Statistical Society. Vol. 30, No. 3, pp. 249-253.
This sampler is suitable for mean < 40. For large means,
LargeMeanPoissonSampler should be used instead.
Note: The algorithm uses a recurrence relation to compute the Poisson probability and a rolling summation for the cumulative probability. When the mean is large the initial probability (Math.exp(-mean)) is zero and an exception is raised by the constructor.
Sampling uses 1 call to UniformRandomProvider.nextDouble(). This method provides
an alternative to the SmallMeanPoissonSampler for slow generators of double.
- Since:
- 1.3
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final doubleThe mean of the Poisson sample.private final doublePre-computeMath.exp(-mean).private final UniformRandomProviderUnderlying source of randomness. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateKempSmallMeanPoissonSampler(UniformRandomProvider rng, double p0, double mean) -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSamplerof(UniformRandomProvider rng, double mean) Creates a new sampler for the Poisson distribution.intsample()Creates anintsample.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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.rng.sampling.distribution.DiscreteSampler
samples, samples
-
Field Details
-
rng
Underlying source of randomness. -
p0
private final double p0Pre-computeMath.exp(-mean). Note: This is the probability of the Poisson samplep(x=0). -
mean
private final double meanThe mean of the Poisson sample.
-
-
Constructor Details
-
KempSmallMeanPoissonSampler
- Parameters:
rng- Generator of uniformly distributed random numbers.p0- Probability of the Poisson samplep(x=0).mean- Mean.
-
-
Method Details
-
sample
public int sample()Creates anintsample.- Specified by:
samplein interfaceDiscreteSampler- Returns:
- a sample.
-
toString
-
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<SharedStateDiscreteSampler>- Parameters:
rng- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
Creates a new sampler for the Poisson distribution.- Parameters:
rng- Generator of uniformly distributed random numbers.mean- Mean of the distribution.- Returns:
- the sampler
- Throws:
IllegalArgumentException- ifmean <= 0orMath.exp(-mean) == 0.
-