Class SmallMeanPoissonSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.SmallMeanPoissonSampler
-
- All Implemented Interfaces:
DiscreteSampler
,SharedStateDiscreteSampler
,SharedStateSampler<SharedStateDiscreteSampler>
public class SmallMeanPoissonSampler extends Object implements 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 averagemean + 1
deviates per sample.- Since:
- 1.1
-
-
Constructor Summary
Constructors Constructor Description SmallMeanPoissonSampler(UniformRandomProvider rng, double mean)
-
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.
-
-
-
Constructor Detail
-
SmallMeanPoissonSampler
public SmallMeanPoissonSampler(UniformRandomProvider rng, double mean)
- Parameters:
rng
- Generator of uniformly distributed random numbers.mean
- Mean.- Throws:
IllegalArgumentException
- ifmean <= 0
orMath.exp(-mean) == 0
-
-
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
- Since:
- 1.3
-
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
.- Since:
- 1.3
-
-