Class EnumeratedRealDistribution
- java.lang.Object
-
- org.apache.commons.math4.legacy.distribution.EnumeratedRealDistribution
-
- All Implemented Interfaces:
org.apache.commons.statistics.distribution.ContinuousDistribution
public class EnumeratedRealDistribution extends Object implements org.apache.commons.statistics.distribution.ContinuousDistribution
Implementation of a real-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<Double>
innerDistribution
EnumeratedDistribution
(using theDouble
wrapper) used to generate the pmf.
-
Constructor Summary
Constructors Constructor Description EnumeratedRealDistribution(double[] data)
Creates a discrete real-valued distribution from the input data.EnumeratedRealDistribution(double[] singletons, double[] probabilities)
Create a discrete real-valued 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 org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler
createSampler(org.apache.commons.rng.UniformRandomProvider rng)
double
cumulativeProbability(double x)
double
density(double x)
For a random variableX
whose values are distributed according to this distribution, this method returnsP(X = x)
.double
getMean()
double
getSupportLowerBound()
Returns the lowest value with non-zero probability.double
getSupportUpperBound()
Returns the highest value with non-zero probability.double
getVariance()
double
inverseCumulativeProbability(double p)
-
-
-
Field Detail
-
innerDistribution
protected final EnumeratedDistribution<Double> innerDistribution
EnumeratedDistribution
(using theDouble
wrapper) used to generate the pmf.
-
-
Constructor Detail
-
EnumeratedRealDistribution
public EnumeratedRealDistribution(double[] singletons, double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException
Create a discrete real-valued distribution using the given random number generator and probability mass function enumeration.- 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.
-
EnumeratedRealDistribution
public EnumeratedRealDistribution(double[] data)
Creates a discrete real-valued distribution from the input data. Values are assigned mass based on their frequency.- Parameters:
data
- input dataset
-
-
Method Detail
-
density
public double density(double x)
For a random variableX
whose values are distributed according to this distribution, this method returnsP(X = x)
. In other words, this method represents the probability mass function (PMF) for the distribution.- Specified by:
density
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Parameters:
x
- the point at which the PMF is evaluated- Returns:
- the value of the probability mass function at point
x
-
cumulativeProbability
public double cumulativeProbability(double x)
- Specified by:
cumulativeProbability
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
-
inverseCumulativeProbability
public double inverseCumulativeProbability(double p) throws OutOfRangeException
- Specified by:
inverseCumulativeProbability
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Throws:
OutOfRangeException
-
getMean
public double getMean()
- Specified by:
getMean
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Returns:
sum(singletons[i] * probabilities[i])
-
getVariance
public double getVariance()
- Specified by:
getVariance
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Returns:
sum((singletons[i] - mean) ^ 2 * probabilities[i])
-
getSupportLowerBound
public double getSupportLowerBound()
Returns the lowest value with non-zero probability.- Specified by:
getSupportLowerBound
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Returns:
- the lowest value with non-zero probability.
-
getSupportUpperBound
public double getSupportUpperBound()
Returns the highest value with non-zero probability.- Specified by:
getSupportUpperBound
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
- Returns:
- the highest value with non-zero probability.
-
createSampler
public org.apache.commons.statistics.distribution.ContinuousDistribution.Sampler createSampler(org.apache.commons.rng.UniformRandomProvider rng)
- Specified by:
createSampler
in interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
-
-