Class PoissonSampler
java.lang.Object
org.apache.commons.rng.sampling.distribution.SamplerBase
org.apache.commons.rng.sampling.distribution.PoissonSampler
- 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
. -
For large means, we use the rejection algorithm described in
Devroye, Luc. (1981). The Computer Generation of Poisson Random Variables
Computing vol. 26 pp. 197-207.
Sampling uses:
UniformRandomProvider.nextDouble()
UniformRandomProvider.nextLong()
(large means only)
- Since:
- 1.0
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final double
Value for switching sampling algorithm.private final SharedStateDiscreteSampler
The internal Poisson sampler. -
Constructor Summary
ConstructorsConstructorDescriptionPoissonSampler
(UniformRandomProvider rng, double mean) This instance delegates sampling. -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSampler
of
(UniformRandomProvider rng, double mean) Creates a new Poisson distribution sampler.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 org.apache.commons.rng.sampling.distribution.SamplerBase
nextDouble, nextInt, nextInt, nextLong
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
-
PIVOT
static final double PIVOTValue for switching sampling algorithm.Package scope for the
PoissonSamplerCache
.- See Also:
-
poissonSamplerDelegate
The internal Poisson sampler.
-
-
Constructor Details
-
PoissonSampler
This instance delegates sampling. Use the factory methodof(UniformRandomProvider, double)
to create an optimal sampler.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Throws:
IllegalArgumentException
- ifmean <= 0
ormean > 0.5 *
Integer.MAX_VALUE
.
-
-
Method Details
-
sample
public int sample()Creates anint
sample.- Specified by:
sample
in interfaceDiscreteSampler
- Returns:
- a sample.
-
toString
- Overrides:
toString
in classSamplerBase
-
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 Poisson distribution sampler.- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Returns:
- the sampler
- Throws:
IllegalArgumentException
- ifmean <= 0
ormean > 0.5 *
Integer.MAX_VALUE
.- Since:
- 1.3
-