Class SmallMeanPoissonSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.SmallMeanPoissonSampler
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
Sampler for the Poisson distribution.
-
For small means, a Poisson process is simulated using uniform deviates, as described in
Knuth (1969). Seminumerical Algorithms. The Art of Computer Programming, Volume 2. Chapter 3.4.1.F.3 Important integer-valued distributions: The Poisson distribution. Addison Wesley.
The Poisson process (and hence, the returned value) is bounded by1000 * mean
.
This sampler is suitable for mean < 40
.
For large means, LargeMeanPoissonSampler
should be used instead.
Sampling uses UniformRandomProvider.nextDouble()
and requires on average
mean + 1
deviates per sample.
- Since:
- 1.1
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
Pre-compute1000 * mean
as the upper limit of the sample.private final double
Pre-computeMath.exp(-mean)
.private final UniformRandomProvider
Underlying source of randomness. -
Constructor Summary
ConstructorsModifierConstructorDescriptionSmallMeanPoissonSampler
(UniformRandomProvider rng, double mean) private
-
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSampler
of
(UniformRandomProvider rng, double mean) Creates a new sampler for the Poisson distribution.int
sample()
Creates anint
sample.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, wait
Methods inherited from interface org.apache.commons.rng.sampling.distribution.DiscreteSampler
samples, samples
-
Field Details
-
p0
private final double p0Pre-computeMath.exp(-mean)
. Note: This is the probability of the Poisson sampleP(n=0)
. -
limit
private final int limitPre-compute1000 * mean
as the upper limit of the sample. -
rng
Underlying source of randomness.
-
-
Constructor Details
-
SmallMeanPoissonSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Throws:
IllegalArgumentException
- ifmean <= 0
orMath.exp(-mean) == 0
-
SmallMeanPoissonSampler
- Parameters:
rng
- Generator of uniformly distributed random numbers.source
- Source to copy.
-
-
Method Details
-
sample
public int sample()Creates anint
sample.- Specified by:
sample
in 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:
withUniformRandomProvider
in interfaceSharedStateSampler<SharedStateDiscreteSampler>
- Parameters:
rng
- Generator of uniformly distributed random numbers.- Returns:
- the sampler
- Since:
- 1.3
-
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 <= 0
orMath.exp(-mean) == 0
.- Since:
- 1.3
-