Class GeometricSampler
- java.lang.Object
-
- org.apache.commons.rng.sampling.distribution.GeometricSampler
-
public final class GeometricSampler extends Object
Sampling from a geometric distribution.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
is an exponentially distributed random variable with parameter , then is a geometrically distributed random variable with parameter , with the probability of success.This sampler outperforms using the
InverseTransformDiscreteSamplerwith an appropriate geometric inverse cumulative probability function.Usage note: As the probability of success (
) tends towards zero the mean of the distribution ( ) tends towards infinity and due to the use ofintfor the sample this can result in truncation of the distribution.Sampling uses
UniformRandomProvider.nextDouble().- Since:
- 1.3
- See Also:
- Geometric distribution - related distributions
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static SharedStateDiscreteSamplerof(UniformRandomProvider rng, double probabilityOfSuccess)Creates a new geometric distribution sampler.
-
-
-
Method Detail
-
of
public static SharedStateDiscreteSampler of(UniformRandomProvider rng, double probabilityOfSuccess)
Creates a new geometric distribution sampler. The samples will be provided in the setk=[0, 1, 2, ...]wherekindicates 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- ifprobabilityOfSuccessis not in the range[0 < probabilityOfSuccess <= 1])
-
-