T
- type of the elements in the sample space.public class EnumeratedDistribution<T> extends Object implements Serializable
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 null.
Constructor and Description |
---|
EnumeratedDistribution(List<Pair<T,Double>> pmf)
Create an enumerated distribution using the given random number generator
and probability mass function enumeration.
|
Modifier and Type | Method and Description |
---|---|
List<Pair<T,Double>> |
getPmf()
Return the probability mass function as a list of
|
double |
probability(T x)
For a random variable
X whose values are distributed according to
this distribution, this method returns P(X = x) . |
public EnumeratedDistribution(List<Pair<T,Double>> pmf) throws MathIllegalArgumentException
pmf
- probability mass function enumerated as a list of <T, probability>
pairs.MathIllegalArgumentException
- if any of the probabilities are negative.MathIllegalArgumentException
- if any of the probabilities are NaN.MathIllegalArgumentException
- if any of the probabilities are infinite.public double probability(T x)
X
whose values are distributed according to
this distribution, this method returns P(X = x)
. In other words,
this method represents the probability mass function (PMF) for the
distribution.
Note that if x1
and x2
satisfy x1.equals(x2)
,
or both are null, then probability(x1) = probability(x2)
.
x
- the point at which the PMF is evaluatedx
public List<Pair<T,Double>> getPmf()
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).
Copyright © 2016 Hipparchus.org. All rights reserved.