|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.commons.math3.distribution.EnumeratedDistribution<T>
T
- type of the elements in the sample space.public class EnumeratedDistribution<T>
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
Field Summary | |
---|---|
protected RandomGenerator |
random
RNG instance used to generate samples from the distribution. |
Constructor Summary | |
---|---|
EnumeratedDistribution(List<Pair<T,Double>> pmf)
Create an enumerated distribution using the given probability mass function enumeration. |
|
EnumeratedDistribution(RandomGenerator rng,
List<Pair<T,Double>> pmf)
Create an enumerated distribution using the given random number generator and probability mass function enumeration. |
Method Summary | |
---|---|
List<Pair<T,Double>> |
getPmf()
Return the probability mass function as a list of |
void |
reseedRandomGenerator(long seed)
Reseed the random generator used to generate samples. |
T |
sample()
Generate a random value sampled from this distribution. |
Object[] |
sample(int sampleSize)
Generate a random sample from the distribution. |
T[] |
sample(int sampleSize,
T[] array)
Generate a random sample from the distribution. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final RandomGenerator random
Constructor Detail |
---|
public EnumeratedDistribution(List<Pair<T,Double>> pmf) throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException
pmf
- probability mass function enumerated as a list of 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.public EnumeratedDistribution(RandomGenerator rng, List<Pair<T,Double>> pmf) throws NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException
rng
- random number generator.pmf
- probability mass function enumerated as a list of 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 |
---|
public void reseedRandomGenerator(long seed)
seed
- the new seedpublic List<Pair<T,Double>> getPmf()
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).
public T sample()
public Object[] sample(int sampleSize) throws NotStrictlyPositiveException
sampleSize
- the number of random values to generate.
NotStrictlyPositiveException
- if sampleSize
is not
positive.public T[] sample(int sampleSize, T[] array) throws NotStrictlyPositiveException
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.
sampleSize
- the number of random values to generate.array
- the array to populate.
NotStrictlyPositiveException
- if sampleSize
is not positive.
NullArgumentException
- if array
is null
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |