Class KempSmallMeanPoissonSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.KempSmallMeanPoissonSampler
-
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
public final class KempSmallMeanPoissonSampler extends Object implements 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 theSmallMeanPoissonSampler
for slow generators ofdouble
.- Since:
- 1.3
- See Also:
- Kemp, A.W. (1981) JRSS Vol. 30, pp. 249-253
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SharedStateDiscreteSampler
of(UniformRandomProvider rng, double mean)
Creates a new sampler for the Poisson distribution.int
sample()
Creates a sample.String
toString()
SharedStateDiscreteSampler
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.
-
-
-
Method Detail
-
sample
public int sample()
Creates a sample.- Specified by:
sample
in interfaceDiscreteSampler
- Returns:
- a sample.
-
withUniformRandomProvider
public SharedStateDiscreteSampler 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<SharedStateDiscreteSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
-
of
public static SharedStateDiscreteSampler of(UniformRandomProvider rng, double mean)
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 <= 0
orMath.exp(-mean) == 0
.
-
-