Class EnumeratedDistribution<T>
- java.lang.Object
-
- org.apache.commons.math4.legacy.distribution.EnumeratedDistribution<T>
-
- Type Parameters:
T
- type of the elements in the sample space.
public class EnumeratedDistribution<T> extends Object
A generic implementation of a discrete probability distribution (Wikipedia) over a finite sample space, based on an enumerated list of <value, probability> pairs. Input probabilities must all be non-negative, but zero values are allowed and their sum does not have to equal one. Constructors will normalize input probabilities to make them sum to one.
The list of <value, probability> pairs does not, strictly speaking, have to be a function and it can contain null values. The pmf created by the constructor will combine probabilities of equal values and will treat null values as equal. For example, if the list of pairs <"dog", 0.2>, <null, 0.1>, <"pig", 0.2>, <"dog", 0.1>, <null, 0.4> is provided to the constructor, the resulting pmf will assign mass of 0.5 to null, 0.3 to "dog" and 0.2 to pig.
- Since:
- 3.2
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
EnumeratedDistribution.Sampler
Sampler functionality.
-
Constructor Summary
Constructors Constructor Description EnumeratedDistribution(List<Pair<T,Double>> pmf)
Create an enumerated distribution using the given random number generator and probability mass function enumeration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description EnumeratedDistribution.Sampler
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Creates aEnumeratedDistribution.Sampler
.List<Pair<T,Double>>
getPmf()
Return the probability mass function as a list of <value, probability> pairs.
-
-
-
Constructor Detail
-
EnumeratedDistribution
public EnumeratedDistribution(List<Pair<T,Double>> pmf) throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException
Create an enumerated distribution using the given random number generator and probability mass function enumeration.- Parameters:
pmf
- probability mass function enumerated as a list of<T, probability>
pairs.- Throws:
NotPositiveException
- if any of the probabilities are negative.NotFiniteNumberException
- if any of the probabilities are infinite.NotANumberException
- if any of the probabilities are NaN.MathArithmeticException
- all of the probabilities are 0.
-
-
Method Detail
-
getPmf
public List<Pair<T,Double>> getPmf()
Return the probability mass function as a list of <value, probability> pairs.
Note that if duplicate and / or null values were provided to the constructor when creating this EnumeratedDistribution, the returned list will contain these values. If duplicates values exist, what is returned will not represent a pmf (i.e., it is up to the caller to consolidate duplicate mass points).
- Returns:
- the probability mass function.
-
createSampler
public EnumeratedDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Creates aEnumeratedDistribution.Sampler
.- Parameters:
rng
- Random number generator.- Returns:
- a new sampler instance.
-
-