Class EnumeratedRealDistribution
- java.lang.Object
-
- org.apache.commons.math4.distribution.EnumeratedRealDistribution
-
- All Implemented Interfaces:
java.io.Serializable,ContinuousDistribution
public class EnumeratedRealDistribution extends java.lang.Object implements ContinuousDistribution, java.io.Serializable
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
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution
ContinuousDistribution.Sampler
-
-
Field Summary
Fields Modifier and Type Field Description protected EnumeratedDistribution<java.lang.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
Modifier and Type Method Description ContinuousDistribution.SamplercreateSampler(UniformRandomProvider rng)Creates a sampler.doublecumulativeProbability(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x).doubledensity(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x).doublegetMean()Gets the mean of this distribution.doublegetSupportLowerBound()Gets the lower bound of the support.doublegetSupportUpperBound()Gets the upper bound of the support.doublegetVariance()Gets the variance of this distribution.doubleinverseCumulativeProbability(double p)Computes the quantile function of this distribution.booleanisSupportConnected()Indicates whether the support is connected, i.e.doubleprobability(double x)For a random variableXwhose values are distributed according to this distribution, this method returnsP(X = x).-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.commons.statistics.distribution.ContinuousDistribution
logDensity, probability
-
-
-
-
Field Detail
-
innerDistribution
protected final EnumeratedDistribution<java.lang.Double> innerDistribution
EnumeratedDistribution(using theDoublewrapper) used to generate the pmf.
-
-
Constructor Detail
-
EnumeratedRealDistribution
public EnumeratedRealDistribution(double[] singletons, double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberExceptionCreate 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
-
probability
public double probability(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:
probabilityin interfaceContinuousDistribution- Parameters:
x- Point at which the PMF is evaluated.- Returns:
- the value of the probability mass function at point
x.
-
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 interfaceContinuousDistribution- 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)
For a random variableXwhose values are distributed according to this distribution, this method returnsP(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.- Specified by:
cumulativeProbabilityin interfaceContinuousDistribution- Parameters:
x- Point at which the CDF is evaluated.- Returns:
- the probability that a random variable with this
distribution takes a value less than or equal to
x.
-
inverseCumulativeProbability
public double inverseCumulativeProbability(double p) throws OutOfRangeExceptionComputes the quantile function of this distribution. For a random variableXdistributed according to this distribution, the returned value isinf{x in R | P(X<=x) >= p}for0 < p <= 1,inf{x in R | P(X<=x) > 0}forp = 0.
- Specified by:
inverseCumulativeProbabilityin interfaceContinuousDistribution- Parameters:
p- Cumulative probability.- Returns:
- the smallest
p-quantile of this distribution (largest 0-quantile forp = 0). - Throws:
OutOfRangeException
-
getMean
public double getMean()
Gets the mean of this distribution.- Specified by:
getMeanin interfaceContinuousDistribution- Returns:
sum(singletons[i] * probabilities[i])
-
getVariance
public double getVariance()
Gets the variance of this distribution.- Specified by:
getVariancein interfaceContinuousDistribution- Returns:
sum((singletons[i] - mean) ^ 2 * probabilities[i])
-
getSupportLowerBound
public double getSupportLowerBound()
Gets the lower bound of the support. It must return the same value asinverseCumulativeProbability(0), i.e.inf {x in R | P(X <= x) > 0}. Returns the lowest value with non-zero probability.- Specified by:
getSupportLowerBoundin interfaceContinuousDistribution- Returns:
- the lowest value with non-zero probability.
-
getSupportUpperBound
public double getSupportUpperBound()
Gets the upper bound of the support. It must return the same value asinverseCumulativeProbability(1), i.e.inf {x in R | P(X <= x) = 1}. Returns the highest value with non-zero probability.- Specified by:
getSupportUpperBoundin interfaceContinuousDistribution- Returns:
- the highest value with non-zero probability.
-
isSupportConnected
public boolean isSupportConnected()
Indicates whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support. The support of this distribution is connected.- Specified by:
isSupportConnectedin interfaceContinuousDistribution- Returns:
true
-
createSampler
public ContinuousDistribution.Sampler createSampler(UniformRandomProvider rng)
Creates a sampler.- Specified by:
createSamplerin interfaceContinuousDistribution- Parameters:
rng- Generator of uniformly distributed numbers.- Returns:
- a sampler that produces random numbers according this distribution.
-
-