Class GeometricSampler
This distribution samples the number of failures before the first success taking values in the
set [0, 1, 2, ...]
.
The sample is computed using a related exponential distribution. If \( X \) is an exponentially distributed random variable with parameter \( \lambda \), then \( Y = \left \lfloor X \right \rfloor \) is a geometrically distributed random variable with parameter \( p = 1 − e^\lambda \), with \( p \) the probability of success.
This sampler outperforms using the InverseTransformDiscreteSampler
with an appropriate
geometric inverse cumulative probability function.
Usage note: As the probability of success (\( p \)) tends towards zero the mean of the
distribution (\( \frac{1-p}{p} \)) tends towards infinity and due to the use of int
for the sample this can result in truncation of the distribution.
Sampling uses UniformRandomProvider.nextDouble()
.
- Since:
- 1.3
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
Sample from the geometric distribution by using a related exponential distribution.private static final class
Sample from the geometric distribution when the probability of success is 1. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSampler
of
(UniformRandomProvider rng, double probabilityOfSuccess) Creates a new geometric distribution sampler.
-
Constructor Details
-
GeometricSampler
private GeometricSampler()Class contains only static methods.
-
-
Method Details
-
of
Creates a new geometric distribution sampler. The samples will be provided in the setk=[0, 1, 2, ...]
wherek
indicates the number of failures before the first success.- Parameters:
rng
- Generator of uniformly distributed random numbers.probabilityOfSuccess
- The probability of success.- Returns:
- the sampler
- Throws:
IllegalArgumentException
- ifprobabilityOfSuccess
is not in the range[0 < probabilityOfSuccess <= 1]
)
-