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
| Modifier and Type | Field and Description |
|---|---|
| private final double[] | cumulativeProbabilities
Cumulative probabilities, cached to speed up sampling. |
| private final double[] | probabilities
Probabilities of respective random variable values. |
| protected final RandomGenerator | random
RNG instance used to generate samples from the distribution. |
| private static final long | serialVersionUID
Serializable UID. |
| private final List | singletons
List of random variable values. |
| Access | Constructor and Description |
|---|---|
| public | EnumeratedDistribution(final List<Pair<T, Double>>
probability mass function enumerated as a list of pmf)Create an enumerated distribution using the given probability mass function enumeration. |
| public | EnumeratedDistribution(final RandomGenerator
random number generator. rng, final List<Pair<T, Double>> probability mass function enumerated as a list of pmf)Create an enumerated distribution using the given random number generator and probability mass function enumeration. |
| Modifier and Type | Method and Description |
|---|---|
| public List | Returns: the probability mass function.Return the probability mass function as a list of <value, probability> pairs. |
| pack-priv double | Returns: the value of the probability mass function atxthe point at which the PMF is evaluated x)For a random variable |
| public void | |
| public T | |
| public Object[] | Returns: an array representing the random sample.the number of random values to generate. sampleSize)Generate a random sample from the distribution. |
| public T[] | Returns: an array representing the random sample.the number of random values to generate. sampleSize, final T[] the array to populate. array)Generate a random sample from the distribution. |
| cumulativeProbabilities | back to summary |
|---|---|
| private final double[] cumulativeProbabilities Cumulative probabilities, cached to speed up sampling. | |
| probabilities | back to summary |
|---|---|
| private final double[] probabilities Probabilities of respective random variable values. For i = 0, ..., singletons.size() - 1, probability[i] is the probability that a random variable following this distribution takes the value singletons[i]. | |
| random | back to summary |
|---|---|
| protected final RandomGenerator random RNG instance used to generate samples from the distribution. | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serializable UID. | |
| singletons | back to summary |
|---|---|
| private final List<T> singletons List of random variable values. | |
| EnumeratedDistribution | back to summary |
|---|---|
| public EnumeratedDistribution(final List<Pair<T, Double>> pmf) throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException Create an enumerated distribution using the given probability mass function enumeration. Note this constructor will implicitly create an instance of
| |
| EnumeratedDistribution | back to summary |
|---|---|
| public EnumeratedDistribution(final RandomGenerator rng, final 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.
| |
| getPmf | back to summary |
|---|---|
| public List Return the probability mass function as a list of 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). | |
| probability | back to summary |
|---|---|
| pack-priv double probability(final T x) For a random variable Note that if
| |
| reseedRandomGenerator | back to summary |
|---|---|
| public void reseedRandomGenerator(long seed) Reseed the random generator used to generate samples.
| |
| sample | back to summary |
|---|---|
| public T sample() Generate a random value sampled from this distribution.
| |
| sample | back to summary |
|---|---|
| public Object[] sample(int sampleSize) throws NotStrictlyPositiveException Generate a random sample from the distribution.
| |
| sample | back to summary |
|---|---|
| public T[] sample(int sampleSize, final T[] array) throws NotStrictlyPositiveException Generate a random sample from the distribution. If the requested samples fit in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this collection.
| |