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

public Class EnumeratedIntegerDistribution

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

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

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

EnumeratedDistribution instance (using the Integer wrapper) used to generate the pmf.

private static final long
Inherited from org.apache.commons.math3.distribution.AbstractIntegerDistribution:
randomrandomData

Constructor Summary

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

Create a discrete distribution using the given probability mass function definition.

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

Create a discrete distribution using the given random number generator and probability mass function definition.

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

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

public
EnumeratedIntegerDistribution(final int[]
input dataset
data
)

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

Method Summary

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

Returns:

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

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

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

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

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.IntegerDistribution.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.IntegerDistribution.getNumericalVariance.

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

public int

Returns:

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

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

Access the lower bound of the support.

public int

Returns:

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

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

Access the upper bound of the support.

public boolean

Returns:

true
isSupportConnected
()

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

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

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

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

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

public int
Inherited from org.apache.commons.math3.distribution.AbstractIntegerDistribution:
cumulativeProbabilityinverseCumulativeProbabilitylogProbabilityreseedRandomGeneratorsamplesolveInverseCumulativeProbability

Field Detail

innerDistributionback to summary
protected final EnumeratedDistribution<Integer> innerDistribution

EnumeratedDistribution instance (using the Integer wrapper) used to generate the pmf.

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serializable UID.

Constructor Detail

EnumeratedIntegerDistributionback to summary
public EnumeratedIntegerDistribution(final int[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException

Create a discrete distribution using the given probability mass function definition.

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:int[]

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.
EnumeratedIntegerDistributionback to summary
public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] singletons, final double[] probabilities) throws DimensionMismatchException, NotPositiveException, MathArithmeticException, NotFiniteNumberException, NotANumberException

Create a discrete distribution using the given random number generator and probability mass function definition.

Parameters
rng:RandomGenerator

random number generator.

singletons:int[]

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.
EnumeratedIntegerDistributionback to summary
public EnumeratedIntegerDistribution(final RandomGenerator rng, final int[] data)

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

Parameters
rng:RandomGenerator

random number generator used for sampling

data:int[]

input dataset

Since
3.6
EnumeratedIntegerDistributionback to summary
public EnumeratedIntegerDistribution(final int[] data)

Create a discrete integer-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:int[]

input dataset

Since
3.6

Method Detail

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

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

Parameters
singletons:int[]

values

probabilities:double[]

probabilities

Returns:List<Pair<Integer, Double>>

list of value/probability pairs

cumulativeProbabilityback to summary
public double cumulativeProbability(final int x)

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

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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:int

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

getNumericalMeanback to summary
public double getNumericalMean()

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

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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.IntegerDistribution.getNumericalVariance.

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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 int getSupportLowerBound()

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

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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 Z | P(X <= x) > 0}.

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

the lowest value with non-zero probability.

getSupportUpperBoundback to summary
public int getSupportUpperBound()

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

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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:int

the highest value with non-zero probability.

isSupportConnectedback to summary
public boolean isSupportConnected()

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

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

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

Returns:boolean

true

probabilityback to summary
public double probability(final int x)

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

Doc from org.apache.commons.math3.distribution.IntegerDistribution.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:int

the point at which the PMF is evaluated

Returns:double

the value of the probability mass function at x

sampleback to summary
public int sample()

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

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

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

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

Returns:int

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

a random value

Annotations
@Override