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

public Class UniformIntegerDistribution

extends AbstractIntegerDistribution
Class Inheritance
Imports
org.apache.commons.math3.exception.NumberIsTooLargeException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, .Well19937c

Implementation of the uniform integer distribution.
Since
3.0
See Also
Uniform distribution (discrete), at Wikipedia

Field Summary

Modifier and TypeField and Description
private final int
lower

Lower bound (inclusive) of this distribution.

private static final long
private final int
upper

Upper bound (inclusive) of this distribution.

Inherited from org.apache.commons.math3.distribution.AbstractIntegerDistribution:
randomrandomData

Constructor Summary

AccessConstructor and Description
public
UniformIntegerDistribution(int
Lower bound (inclusive) of this distribution.
lower
,
int
Upper bound (inclusive) of this distribution.
upper
)

Creates a new uniform integer distribution using the given lower and upper bounds (both inclusive).

public
UniformIntegerDistribution(RandomGenerator
Random number generator.
rng
,
int
Lower bound (inclusive) of this distribution.
lower
,
int
Upper bound (inclusive) of this distribution.
upper
)

Creates a new uniform integer distribution using the given lower and upper bounds (both inclusive).

Method Summary

Modifier and TypeMethod and Description
public double
cumulativeProbability(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
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
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:

lower bound of the support
getSupportLowerBound
()

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

Access the lower bound of the support.

public int

Returns:

upper bound of the support
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(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

lowerback to summary
private final int lower

Lower bound (inclusive) of this distribution.

serialVersionUIDback to summary
private static final long serialVersionUID

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

Serializable version identifier.

upperback to summary
private final int upper

Upper bound (inclusive) of this distribution.

Constructor Detail

UniformIntegerDistributionback to summary
public UniformIntegerDistribution(int lower, int upper) throws NumberIsTooLargeException

Creates a new uniform integer distribution using the given lower and upper bounds (both inclusive).

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
lower:int

Lower bound (inclusive) of this distribution.

upper:int

Upper bound (inclusive) of this distribution.

Exceptions
NumberIsTooLargeException:
if lower >= upper.
UniformIntegerDistributionback to summary
public UniformIntegerDistribution(RandomGenerator rng, int lower, int upper) throws NumberIsTooLargeException

Creates a new uniform integer distribution using the given lower and upper bounds (both inclusive).

Parameters
rng:RandomGenerator

Random number generator.

lower:int

Lower bound (inclusive) of this distribution.

upper:int

Upper bound (inclusive) of this distribution.

Exceptions
NumberIsTooLargeException:
if lower > upper.
Since
3.1

Method Detail

cumulativeProbabilityback to summary
public double cumulativeProbability(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. For lower bound lower and upper bound upper, the mean is 0.5 * (lower + upper).

Returns:double

the mean or Double.NaN if it is not defined

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. For lower bound lower and upper bound upper, and n = upper - lower + 1, the variance is (n^2 - 1) / 12.

Returns:double

the variance (possibly Double.POSITIVE_INFINITY or Double.NaN if it is not defined)

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}.

The lower bound of the support is equal to the lower bound parameter of the distribution.
Returns:int

lower bound of the support

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}.

The upper bound of the support is equal to the upper bound parameter of the distribution.
Returns:int

upper bound of the support

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(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