Class MarsagliaTsangWangDiscreteSampler.Enumerated
java.lang.Object
org.apache.commons.rng.sampling.distribution.MarsagliaTsangWangDiscreteSampler.Enumerated
- Enclosing class:
MarsagliaTsangWangDiscreteSampler
Create a sampler for an enumerated distribution of
n values each with an
associated probability.
The samples corresponding to each probability are assumed to be a natural sequence
starting at zero.- Since:
- 1.3
-
Method Summary
Modifier and TypeMethodDescriptionstatic SharedStateDiscreteSamplerof(UniformRandomProvider rng, double[] probabilities) Creates a sampler for an enumerated distribution ofnvalues each with an associated probability.
-
Method Details
-
of
Creates a sampler for an enumerated distribution ofnvalues each with an associated probability.The probabilities will be normalised using their sum. The only requirement is the sum is positive.
The sum of the probabilities is normalised to 230. Note that probabilities are adjusted to the nearest 2-30 due to round-off during the normalisation conversion. Consequently any probability less than 2-31 will not be observed in samples.
- Parameters:
rng- Generator of uniformly distributed random numbers.probabilities- The list of probabilities.- Returns:
- Sampler.
- Throws:
IllegalArgumentException- ifprobabilitiesis null or empty, a probability is negative, infinite orNaN, or the sum of all probabilities is not strictly positive.
-