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>innerDistributionEnumeratedDistribution(using theDoublewrapper) 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.SamplercreateSampler(org.apache.commons.rng.UniformRandomProvider rng)doublecumulativeProbability(double x)doubledensity(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x).doublegetMean()doublegetSupportLowerBound()Returns the lowest value with non-zero probability.doublegetSupportUpperBound()Returns the highest value with non-zero probability.doublegetVariance()doubleinverseCumulativeProbability(double p)
-
-
-
Field Detail
-
innerDistribution
protected final EnumeratedDistribution<Double> innerDistribution
EnumeratedDistribution(using theDoublewrapper) 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.lengthNotPositiveException- 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 variableXwhose 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:
densityin 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:
cumulativeProbabilityin interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
-
inverseCumulativeProbability
public double inverseCumulativeProbability(double p) throws OutOfRangeException
- Specified by:
inverseCumulativeProbabilityin interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution- Throws:
OutOfRangeException
-
getMean
public double getMean()
- Specified by:
getMeanin interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution- Returns:
sum(singletons[i] * probabilities[i])
-
getVariance
public double getVariance()
- Specified by:
getVariancein 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:
getSupportLowerBoundin 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:
getSupportUpperBoundin 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:
createSamplerin interfaceorg.apache.commons.statistics.distribution.ContinuousDistribution
-
-