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

public Class BetaDistribution

extends AbstractRealDistribution
Class Inheritance
Imports
org.apache.commons.math3.exception.NumberIsTooSmallException, org.apache.commons.math3.exception.util.LocalizedFormats, org.apache.commons.math3.random.RandomGenerator, .Well19937c, org.apache.commons.math3.special.Beta, .Gamma, org.apache.commons.math3.util.FastMath, .Precision

Implements the Beta distribution.
Since
2.0 (changed to concrete class in 3.0)
See Also
Beta distribution

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
BetaDistribution.ChengBetaSampler

Utility class implementing Cheng's algorithms for beta distribution sampling.

Field Summary

Modifier and TypeField and Description
private final double
alpha

First shape parameter.

private final double
beta

Second shape parameter.

public static final double
DEFAULT_INVERSE_ABSOLUTE_ACCURACY

Default inverse cumulative probability accuracy.

private static final long
private final double
private double
z

Normalizing factor used in density computations.

Inherited from org.apache.commons.math3.distribution.AbstractRealDistribution:
randomrandomDataSOLVER_DEFAULT_ABSOLUTE_ACCURACY

Constructor Summary

AccessConstructor and Description
public
BetaDistribution(double
First shape parameter (must be positive).
alpha
,
double
Second shape parameter (must be positive).
beta
)

Build a new instance.

public
BetaDistribution(double
First shape parameter (must be positive).
alpha
,
double
Second shape parameter (must be positive).
beta
,
double
Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
inverseCumAccuracy
)

Build a new instance.

public
BetaDistribution(RandomGenerator
Random number generator.
rng
,
double
First shape parameter (must be positive).
alpha
,
double
Second shape parameter (must be positive).
beta
)

Creates a β distribution.

public
BetaDistribution(RandomGenerator
Random number generator.
rng
,
double
First shape parameter (must be positive).
alpha
,
double
Second shape parameter (must be positive).
beta
,
double
Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).
inverseCumAccuracy
)

Creates a β distribution.

Method Summary

Modifier and TypeMethod and Description
public double
cumulativeProbability(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
density(double
the point at which the PDF is evaluated
x
)

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

Returns the probability density function (PDF) of this distribution evaluated at the specified point x.

public double

Returns:

the first shape parameter.
getAlpha
()

Access the first shape parameter, alpha.

public double

Returns:

the second shape parameter.
getBeta
()

Access the second shape parameter, beta.

public double
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
getNumericalVariance()

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

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

protected double

Returns:

the solver absolute accuracy.
getSolverAbsoluteAccuracy
()

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

Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.

public double

Returns:

lower bound of the support (always 0)
getSupportLowerBound
()

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

Access the lower bound of the support.

public double

Returns:

upper bound of the support (always 1)
getSupportUpperBound
()

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

Access the upper bound of the support.

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
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
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
logDensity(double
the point at which the PDF is evaluated
x
)

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

Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified point x.

private void
recomputeZ()

Recompute the normalization factor.

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

Field Detail

alphaback to summary
private final double alpha

First shape parameter.

betaback to summary
private final double beta

Second shape parameter.

DEFAULT_INVERSE_ABSOLUTE_ACCURACYback to summary
public static final double DEFAULT_INVERSE_ABSOLUTE_ACCURACY

Default inverse cumulative probability accuracy.

Since
2.1
serialVersionUIDback to summary
private static final long serialVersionUID

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

Serializable version identifier.

solverAbsoluteAccuracyback to summary
private final double solverAbsoluteAccuracy

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

Inverse cumulative probability accuracy.

zback to summary
private double z

Normalizing factor used in density computations. updated whenever alpha or beta are changed.

Constructor Detail

BetaDistributionback to summary
public BetaDistribution(double alpha, double beta)

Build a new instance.

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
alpha:double

First shape parameter (must be positive).

beta:double

Second shape parameter (must be positive).

BetaDistributionback to summary
public BetaDistribution(double alpha, double beta, double inverseCumAccuracy)

Build a new instance.

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
alpha:double

First shape parameter (must be positive).

beta:double

Second shape parameter (must be positive).

inverseCumAccuracy:double

Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).

Since
2.1
BetaDistributionback to summary
public BetaDistribution(RandomGenerator rng, double alpha, double beta)

Creates a β distribution.

Parameters
rng:RandomGenerator

Random number generator.

alpha:double

First shape parameter (must be positive).

beta:double

Second shape parameter (must be positive).

Since
3.3
BetaDistributionback to summary
public BetaDistribution(RandomGenerator rng, double alpha, double beta, double inverseCumAccuracy)

Creates a β distribution.

Parameters
rng:RandomGenerator

Random number generator.

alpha:double

First shape parameter (must be positive).

beta:double

Second shape parameter (must be positive).

inverseCumAccuracy:double

Maximum absolute error in inverse cumulative probability estimates (defaults to DEFAULT_INVERSE_ABSOLUTE_ACCURACY).

Since
3.1

Method Detail

cumulativeProbabilityback to summary
public double cumulativeProbability(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(double x)

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

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

Returns the probability density function (PDF) of this distribution evaluated at the specified point x. In general, the PDF is the derivative of the CDF. If the derivative does not exist at x, then an appropriate replacement should be returned, e.g. Double.POSITIVE_INFINITY, Double.NaN, or the limit inferior or limit superior of the difference quotient.

Parameters
x:double

the point at which the PDF is evaluated

Returns:double

the value of the probability density function at point x

getAlphaback to summary
public double getAlpha()

Access the first shape parameter, alpha.

Returns:double

the first shape parameter.

getBetaback to summary
public double getBeta()

Access the second shape parameter, beta.

Returns:double

the second shape parameter.

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. For first shape parameter alpha and second shape parameter beta, the mean is alpha / (alpha + beta).

Returns:double

the mean or Double.NaN if it is not defined

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. For first shape parameter alpha and second shape parameter beta, the variance is (alpha * beta) / [(alpha + beta)^2 * (alpha + beta + 1)].

Returns:double

the variance (possibly Double.POSITIVE_INFINITY as for certain cases in TDistribution) or Double.NaN if it is not defined

getSolverAbsoluteAccuracyback to summary
protected double getSolverAbsoluteAccuracy()

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

Return the absolute accuracy setting of the solver used to estimate inverse cumulative probabilities.

Returns:double

the solver absolute accuracy.

Annotations
@Override
Since
2.1
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}.

The lower bound of the support is always 0 no matter the parameters.
Returns:double

lower bound of the support (always 0)

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

The upper bound of the support is always 1 no matter the parameters.
Returns:double

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

Returns:boolean

true if the lower bound of support is finite and the density function returns a non-NaN, non-infinite value there

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.

Returns:boolean

true if the upper bound of support is finite and the density function returns a non-NaN, non-infinite value there

logDensityback to summary
public double logDensity(double x)

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

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

Returns the natural logarithm of the probability density function (PDF) of this distribution evaluated at the specified point x. In general, the PDF is the derivative of the CDF. If the derivative does not exist at x, then an appropriate replacement should be returned, e.g. Double.POSITIVE_INFINITY, Double.NaN, or the limit inferior or limit superior of the difference quotient. Note that due to the floating point precision and under/overflow issues, this method will for some distributions be more precise and faster than computing the logarithm of density(double). The default implementation simply computes the logarithm of density(x).

Parameters
x:double

the point at which the PDF is evaluated

Returns:double

the logarithm of the value of the probability density function at point x

Annotations
@Override
recomputeZback to summary
private void recomputeZ()

Recompute the normalization factor.

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.

Sampling is performed using Cheng algorithms:

R. C. H. Cheng, "Generating beta variates with nonintegral shape parameters.". Communications of the ACM, 21, 317–322, 1978.

Returns:double

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

a random value.

Annotations
@Override
org.apache.commons.math3.distribution back to summary

private final Class BetaDistribution.ChengBetaSampler

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.distribution.BetaDistribution.ChengBetaSampler

Utility class implementing Cheng's algorithms for beta distribution sampling.

R. C. H. Cheng, "Generating beta variates with nonintegral shape parameters.". Communications of the ACM, 21, 317–322, 1978.

Since
3.6

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static double

Returns:

sampled value
algorithmBB
(RandomGenerator
random generator to use
random
,
final double
distribution first shape parameter (α)
a0
,
final double
min(α, β) where α, β are the two distribution shape parameters
a
,
final double
max(α, β) where α, β are the two distribution shape parameters
b
)

Returns one sample using Cheng's BB algorithm, when both α and β are greater than 1.

private static double

Returns:

sampled value
algorithmBC
(RandomGenerator
random generator to use
random
,
final double
distribution first shape parameter (α)
a0
,
final double
max(α, β) where α, β are the two distribution shape parameters
a
,
final double
min(α, β) where α, β are the two distribution shape parameters
b
)

Returns one sample using Cheng's BC algorithm, when at least one of α and β is smaller than 1.

pack-priv static double

Returns:

sampled value
sample
(RandomGenerator
random generator to use
random
,
final double
distribution first shape parameter
alpha
,
final double
distribution second shape parameter
beta
)

Returns one sample using Cheng's sampling algorithm.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ChengBetaSamplerback to summary
private ChengBetaSampler()

Method Detail

algorithmBBback to summary
private static double algorithmBB(RandomGenerator random, final double a0, final double a, final double b)

Returns one sample using Cheng's BB algorithm, when both α and β are greater than 1.

Parameters
random:RandomGenerator

random generator to use

a0:double

distribution first shape parameter (α)

a:double

min(α, β) where α, β are the two distribution shape parameters

b:double

max(α, β) where α, β are the two distribution shape parameters

Returns:double

sampled value

algorithmBCback to summary
private static double algorithmBC(RandomGenerator random, final double a0, final double a, final double b)

Returns one sample using Cheng's BC algorithm, when at least one of α and β is smaller than 1.

Parameters
random:RandomGenerator

random generator to use

a0:double

distribution first shape parameter (α)

a:double

max(α, β) where α, β are the two distribution shape parameters

b:double

min(α, β) where α, β are the two distribution shape parameters

Returns:double

sampled value

sampleback to summary
pack-priv static double sample(RandomGenerator random, final double alpha, final double beta)

Returns one sample using Cheng's sampling algorithm.

Parameters
random:RandomGenerator

random generator to use

alpha:double

distribution first shape parameter

beta:double

distribution second shape parameter

Returns:double

sampled value