Top Description Fields Constructors Methods
org.apache.commons.math3.distribution

public Class EnumeratedRealDistribution

extends AbstractRealDistribution
Class Inheritance
Imports
java.util.ArrayList, .HashMap, .List, .Map, .Map.Entry, org.apache.commons.math3.exception.DimensionMismatchException, .MathArithmeticException, .NotANumberException, .NotFiniteNumberException, .NotPositiveException, .OutOfRangeException, org.apache.commons.math3.random.RandomGenerator, .Well19937c, org.apache.commons.math3.util.Pair

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

Modifier and TypeField and Description
protected final EnumeratedDistribution<Double>
innerDistribution

EnumeratedDistribution (using the Double wrapper) used to generate the pmf.

private static final long
Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
randomrandomDataSOLVER_DEFAULT_ABSOLUTE_ACCURACY

Constructor Summary

AccessConstructor and Description
public
EnumeratedRealDistribution(final double[]
array of random variable values.
singletons
,
final double[]
array of probabilities.
probabilities
)

Create a discrete real-valued distribution using the given probability mass function enumeration.

public
EnumeratedRealDistribution(final RandomGenerator
random number generator.
rng
,
final double[]
array of random variable values.
singletons
,
final double[]
array of probabilities.
probabilities
)

Create a discrete real-valued distribution using the given random number generator and probability mass function enumeration.

public
EnumeratedRealDistribution(final RandomGenerator
random number generator used for sampling
rng
,
final double[]
input dataset
data
)

Create a discrete real-valued distribution from the input data.

public
EnumeratedRealDistribution(final double[]
input dataset
data
)

Create a discrete real-valued distribution from the input data.

Method Summary

Modifier and TypeMethod and Description
private static List<Pair<Double, Double>>

Returns:

list of value/probability pairs
createDistribution
(double[]
values
singletons
,
double[]
probabilities
probabilities
)

Create the list of Pairs representing the distribution from singletons and probabilities.

public double
cumulativeProbability(final double
the point at which the CDF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x).

public double

Returns:

the value of the probability mass function at point x
density
(final double
the point at which the PMF is evaluated
x
)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).

public double

Returns:

sum(singletons[i] * probabilities[i])
getNumericalMean
()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

public double

Returns:

sum((singletons[i] - mean) ^ 2 * probabilities[i])
getNumericalVariance
()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

public double

Returns:

the lowest value with non-zero probability.
getSupportLowerBound
()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Access the lower bound of the support.

public double

Returns:

the highest value with non-zero probability.
getSupportUpperBound
()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Access the upper bound of the support.

public double
public boolean

Returns:

true
isSupportConnected
()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Use this method to get information about whether the support is connected, i.e. whether all values between the lower and upper bound of the support are included in the support.

public boolean

Returns:

true
isSupportLowerBoundInclusive
()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function.

public boolean

Returns:

true
isSupportUpperBoundInclusive
()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function.

public double
probability(final double
the point at which the PMF is evaluated
x
)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

Implements org.apache.commons.math3.distribution.RealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x).

public double
Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
cumulativeProbabilitygetSolverAbsoluteAccuracylogDensityprobabilityreseedRandomGeneratorsample

Field Detail

innerDistributionback to summary
protected final EnumeratedDistribution<Double> innerDistribution

EnumeratedDistribution (using the Double wrapper) used to generate the pmf.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.math3.distribution.AbstractRealDistribution.serialVersionUID.

Serializable UID.

Constructor Detail

EnumeratedRealDistributionback to summary
public EnumeratedRealDistribution(final double[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException

Create a discrete real-valued distribution using the given probability mass function enumeration.

Note

this constructor will implicitly create an instance of Well19937c as random generator to be used for sampling only (see sample() and sample(int)). In case no sampling is needed for the created distribution, it is advised to pass null as random generator via the appropriate constructors to avoid the additional initialisation overhead.

Parameters
singletons:double[]

array of random variable values.

probabilities:double[]

array of probabilities.

Exceptions
DimensionMismatchException:
if singletons.length != probabilities.length
NotPositiveException:
if any of the probabilities are negative.
MathArithmeticException:
all of the probabilities are 0.
NotFiniteNumberException:
if any of the probabilities are infinite.
NotANumberException:
if any of the probabilities are NaN.
EnumeratedRealDistributionback to summary
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] singletons, final 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
rng:RandomGenerator

random number generator.

singletons:double[]

array of random variable values.

probabilities:double[]

array of probabilities.

Exceptions
DimensionMismatchException:
if singletons.length != probabilities.length
NotPositiveException:
if any of the probabilities are negative.
MathArithmeticException:
all of the probabilities are 0.
NotFiniteNumberException:
if any of the probabilities are infinite.
NotANumberException:
if any of the probabilities are NaN.
EnumeratedRealDistributionback to summary
public EnumeratedRealDistribution(final RandomGenerator rng, final double[] data)

Create a discrete real-valued distribution from the input data. Values are assigned mass based on their frequency.

Parameters
rng:RandomGenerator

random number generator used for sampling

data:double[]

input dataset

Since
3.6
EnumeratedRealDistributionback to summary
public EnumeratedRealDistribution(final double[] data)

Create a discrete real-valued distribution from the input data. Values are assigned mass based on their frequency. For example, [0,1,1,2] as input creates a distribution with values 0, 1 and 2 having probability masses 0.25, 0.5 and 0.25 respectively,

Parameters
data:double[]

input dataset

Since
3.6

Method Detail

createDistributionback to summary
private static List<Pair<Double, Double>> createDistribution(double[] singletons, double[] probabilities)

Create the list of Pairs representing the distribution from singletons and probabilities.

Parameters
singletons:double[]

values

probabilities:double[]

probabilities

Returns:List<Pair<Double, Double>>

list of value/probability pairs

cumulativeProbabilityback to summary
public double cumulativeProbability(final double x)

Implements org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

Doc from org.apache.commons.math3.distribution.RealDistribution.cumulativeProbability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X <= x). In other words, this method represents the (cumulative) distribution function (CDF) for this distribution.

Parameters
x:double

the point at which the CDF is evaluated

Returns:double

the probability that a random variable with this distribution takes a value less than or equal to x

densityback to summary
public double density(final double x)

Implements org.apache.commons.math3.distribution.RealDistribution.density.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.

Parameters
x:double

the point at which the PMF is evaluated

Returns:double

the value of the probability mass function at point x

getNumericalMeanback to summary
public double getNumericalMean()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalMean.

Use this method to get the numerical value of the mean of this distribution.

Returns:double

sum(singletons[i] * probabilities[i])

getNumericalVarianceback to summary
public double getNumericalVariance()

Implements org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Doc from org.apache.commons.math3.distribution.RealDistribution.getNumericalVariance.

Use this method to get the numerical value of the variance of this distribution.

Returns:double

sum((singletons[i] - mean) ^ 2 * probabilities[i])

getSupportLowerBoundback to summary
public double getSupportLowerBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportLowerBound.

Access the lower bound of the support. This method must return the same value as inverseCumulativeProbability(0). In other words, this method must return

inf {x in R | P(X <= x) > 0}.

Returns the lowest value with non-zero probability.
Returns:double

the lowest value with non-zero probability.

getSupportUpperBoundback to summary
public double getSupportUpperBound()

Implements org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Doc from org.apache.commons.math3.distribution.RealDistribution.getSupportUpperBound.

Access the upper bound of the support. This method must return the same value as inverseCumulativeProbability(1). In other words, this method must return

inf {x in R | P(X <= x) = 1}.

Returns the highest value with non-zero probability.
Returns:double

the highest value with non-zero probability.

inverseCumulativeProbabilityback to summary
public double inverseCumulativeProbability(final double p) throws OutOfRangeException

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.inverseCumulativeProbability.

Implements org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.inverseCumulativeProbability.

Computes the quantile function of this distribution. For a random variable X distributed according to this distribution, the returned value is

  • inf{x in R | P(X<=x) >= p} for 0 < p <= 1,
  • inf{x in R | P(X<=x) > 0} for p = 0.
The default implementation returns
Parameters
p:double

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

the cumulative probability

Returns:double

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

the smallest p-quantile of this distribution (largest 0-quantile for p = 0)

Annotations
@Override
Exceptions
OutOfRangeException:

Doc from org.apache.commons.math3.distribution.RealDistribution.inverseCumulativeProbability.

if p < 0 or p > 1

isSupportConnectedback to summary
public boolean isSupportConnected()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportConnected.

Use this method to get information about 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.

Returns:boolean

true

isSupportLowerBoundInclusiveback to summary
public boolean isSupportLowerBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportLowerBoundInclusive.

Whether or not the lower bound of support is in the domain of the density function. Returns true iff getSupporLowerBound() is finite and density(getSupportLowerBound()) returns a non-NaN, non-infinite value. The support of this distribution includes the lower bound.

Returns:boolean

true

isSupportUpperBoundInclusiveback to summary
public boolean isSupportUpperBoundInclusive()

Implements org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Doc from org.apache.commons.math3.distribution.RealDistribution.isSupportUpperBoundInclusive.

Whether or not the upper bound of support is in the domain of the density function. Returns true iff getSupportUpperBound() is finite and density(getSupportUpperBound()) returns a non-NaN, non-infinite value. The support of this distribution includes the upper bound.

Returns:boolean

true

probabilityback to summary
public double probability(final double x)

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

Implements org.apache.commons.math3.distribution.RealDistribution.probability.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.probability.

For a random variable X whose values are distributed according to this distribution, this method returns P(X = x). In other words, this method represents the probability mass function (PMF) for the distribution.

Parameters
x:double

Doc from org.apache.commons.math3.distribution.RealDistribution.probability.

the point at which the PMF is evaluated

Returns:double

zero.

Annotations
@Override
sampleback to summary
public double sample()

Overrides org.apache.commons.math3.distribution.AbstractRealDistribution.sample.

Implements org.apache.commons.math3.distribution.RealDistribution.sample.

Doc from org.apache.commons.math3.distribution.AbstractRealDistribution.sample.

Generate a random value sampled from this distribution. The default implementation uses the inversion method.

Returns:double

Doc from org.apache.commons.math3.distribution.RealDistribution.sample.

a random value.

Annotations
@Override