Class EnumeratedIntegerDistribution
- java.lang.Object
-
- org.apache.commons.math4.legacy.distribution.AbstractIntegerDistribution
-
- org.apache.commons.math4.legacy.distribution.EnumeratedIntegerDistribution
-
- All Implemented Interfaces:
org.apache.commons.statistics.distribution.DiscreteDistribution
public class EnumeratedIntegerDistribution extends AbstractIntegerDistribution
Implementation of an integer-valued
EnumeratedDistribution
.Values with zero-probability are allowed but they do not extend the support.
Duplicate values are allowed. Probabilities of duplicate values are combined when computing cumulative probabilities and statistics.- Since:
- 3.2
-
-
Field Summary
Fields Modifier and Type Field Description protected EnumeratedDistribution<Integer>
innerDistribution
EnumeratedDistribution
instance (using theInteger
wrapper) used to generate the pmf.
-
Constructor Summary
Constructors Constructor Description EnumeratedIntegerDistribution(int[] data)
Create a discrete integer-valued distribution from the input data.EnumeratedIntegerDistribution(int[] singletons, double[] probabilities)
Create a discrete distribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Refer toEnumeratedDistribution.Sampler
for implementation details.double
cumulativeProbability(int x)
double
getMean()
int
getSupportLowerBound()
Returns the lowest value with non-zero probability.int
getSupportUpperBound()
Returns the highest value with non-zero probability.double
getVariance()
double
probability(int x)
-
Methods inherited from class org.apache.commons.math4.legacy.distribution.AbstractIntegerDistribution
inverseCumulativeProbability, logProbability, probability, sample, solveInverseCumulativeProbability
-
-
-
-
Field Detail
-
innerDistribution
protected final EnumeratedDistribution<Integer> innerDistribution
EnumeratedDistribution
instance (using theInteger
wrapper) used to generate the pmf.
-
-
Constructor Detail
-
EnumeratedIntegerDistribution
public EnumeratedIntegerDistribution(int[] singletons, double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException
Create a discrete distribution.- Parameters:
singletons
- array of random variable values.probabilities
- array of probabilities.- Throws:
DimensionMismatchException
- ifsingletons.length != probabilities.length
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.
-
EnumeratedIntegerDistribution
public EnumeratedIntegerDistribution(int[] data)
Create a discrete integer-valued distribution from the input data. Values are assigned mass based on their frequency.- Parameters:
data
- input dataset
-
-
Method Detail
-
probability
public double probability(int x)
-
cumulativeProbability
public double cumulativeProbability(int x)
-
getMean
public double getMean()
- Returns:
sum(singletons[i] * probabilities[i])
-
getVariance
public double getVariance()
- Returns:
sum((singletons[i] - mean) ^ 2 * probabilities[i])
-
getSupportLowerBound
public int getSupportLowerBound()
Returns the lowest value with non-zero probability.- Returns:
- the lowest value with non-zero probability.
-
getSupportUpperBound
public int getSupportUpperBound()
Returns the highest value with non-zero probability.- Returns:
- the highest value with non-zero probability.
-
createSampler
public org.apache.commons.statistics.distribution.DiscreteDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
Refer toEnumeratedDistribution.Sampler
for implementation details.- Specified by:
createSampler
in interfaceorg.apache.commons.statistics.distribution.DiscreteDistribution
- Overrides:
createSampler
in classAbstractIntegerDistribution
-
-