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

public Class Beta

extends Object
Class Inheritance
Imports
org.apache.commons.math3.exception.NumberIsTooSmallException, .OutOfRangeException, org.apache.commons.math3.util.ContinuedFraction, .FastMath

This is a utility class that provides computation methods related to the Beta family of functions.

Implementation of logBeta(double, double) is based on the algorithms described in

and implemented in the NSWC Library of Mathematical Functions, available here. This library is "approved for public release", and the Copyright guidance indicates that unless otherwise stated in the code, all FORTRAN functions in this library are license free. Since no such notice appears in the code these functions can safely be ported to Commons-Math.

Field Summary

Modifier and TypeField and Description
private static final double
DEFAULT_EPSILON

Maximum allowed numerical error.

private static final double[]
DELTA

The coefficients of the series expansion of the Δ function.</center>

private static final double
HALF_LOG_TWO_PI

The constant value of ½log 2π.

Constructor Summary

AccessConstructor and Description
private
Beta()

Default constructor.

Method Summary

Modifier and TypeMethod and Description
private static double

Returns:

the value of Delta(b) - Delta(a + b)
deltaMinusDeltaSum
(final double
First argument.
a
,
final double
Second argument.
b
)

Returns the value of Δ(b) - Δ(a + b), with 0 ≤ a ≤ b and b ≥ 10.

public static double

Returns:

log(B(a, b)).
logBeta
(double
Parameter a.
a
,
double
Parameter b.
b
,
double
This parameter is ignored.
epsilon
,
int
This parameter is ignored.
maxIterations
)
Deprecated as of version 3.1, this method is deprecated as the computation of the beta function is no longer iterative; it will be removed in version 4.0.

Returns the natural logarithm of the beta function B(a, b).

public static double

Returns:

the value of log(Beta(p, q)), NaN if p <= 0 or q <= 0.
logBeta
(final double
First argument.
p
,
final double
Second argument.
q
)

Returns the value of log B(p, q) for 0 ≤ x ≤ 1 and p, q > 0.

private static double

Returns:

the value of log(Gamma(b) / Gamma(a + b)).
logGammaMinusLogGammaSum
(final double
First argument.
a
,
final double
Second argument.
b
)

Returns the value of log[Γ(b) / Γ(a + b)] for a ≥ 0 and b ≥ 10.

private static double

Returns:

the value of log(Gamma(a + b)).
logGammaSum
(final double
First argument.
a
,
final double
Second argument.
b
)

Returns the value of log Γ(a + b) for 1 ≤ a, b ≤ 2.

public static double

Returns:

the regularized beta function I(x, a, b).
regularizedBeta
(double
Value.
x
,
double
Parameter a.
a
,
double
Parameter b.
b
)

Returns the regularized beta function I(x, a, b).

public static double

Returns:

the regularized beta function I(x, a, b)
regularizedBeta
(double
Value.
x
,
double
Parameter a.
a
,
double
Parameter b.
b
,
double
When the absolute value of the nth item in the series is less than epsilon the approximation ceases to calculate further elements in the series.
epsilon
)

Returns the regularized beta function I(x, a, b).

public static double

Returns:

the regularized beta function I(x, a, b)
regularizedBeta
(double
the value.
x
,
double
Parameter a.
a
,
double
Parameter b.
b
,
int
Maximum number of "iterations" to complete.
maxIterations
)

Returns the regularized beta function I(x, a, b).

public static double

Returns:

the regularized beta function I(x, a, b)
regularizedBeta
(double
the value.
x
,
final double
Parameter a.
a
,
final double
Parameter b.
b
,
double
When the absolute value of the nth item in the series is less than epsilon the approximation ceases to calculate further elements in the series.
epsilon
,
int
Maximum number of "iterations" to complete.
maxIterations
)

Returns the regularized beta function I(x, a, b).

private static double

Returns:

the value of Delta(p) + Delta(q) - Delta(p + q).
sumDeltaMinusDeltaSum
(final double
First argument.
p
,
final double
Second argument.
q
)

Returns the value of Δ(p) + Δ(q) - Δ(p + q), with p, q ≥ 10.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_EPSILONback to summary
private static final double DEFAULT_EPSILON

Maximum allowed numerical error.

DELTAback to summary
private static final double[] DELTA

The coefficients of the series expansion of the Δ function. This function is defined as follows

Δ(x) = log Γ(x) - (x - 0.5) log a + a - 0.5 log 2π,

see equation (23) in Didonato and Morris (1992). The series expansion, which applies for x ≥ 10, reads

                14
               ====
            1  \                2 n
    Δ(x) = ---  >    d  (10 / x)
            x  /      n
               ====
               n = 0

HALF_LOG_TWO_PIback to summary
private static final double HALF_LOG_TWO_PI

The constant value of ½log 2π.

Constructor Detail

Betaback to summary
private Beta()

Default constructor. Prohibit instantiation.

Method Detail

deltaMinusDeltaSumback to summary
private static double deltaMinusDeltaSum(final double a, final double b) throws OutOfRangeException, NumberIsTooSmallException

Returns the value of Δ(b) - Δ(a + b), with 0 ≤ a ≤ b and b ≥ 10. Based on equations (26), (27) and (28) in Didonato and Morris (1992).

Parameters
a:double

First argument.

b:double

Second argument.

Returns:double

the value of Delta(b) - Delta(a + b)

Exceptions
OutOfRangeException:
if a < 0 or a > b
NumberIsTooSmallException:
if b < 10
logBetaback to summary
public static double logBeta(double a, double b, double epsilon, int maxIterations)

Deprecated

as of version 3.1, this method is deprecated as the computation of the beta function is no longer iterative; it will be removed in version 4.0. Current implementation of this method internally calls logBeta(double, double).

Returns the natural logarithm of the beta function B(a, b). The implementation of this method is based on:

Parameters
a:double

Parameter a.

b:double

Parameter b.

epsilon:double

This parameter is ignored.

maxIterations:int

This parameter is ignored.

Returns:double

log(B(a, b)).

Annotations
@Deprecated
logBetaback to summary
public static double logBeta(final double p, final double q)

Returns the value of log B(p, q) for 0 ≤ x ≤ 1 and p, q > 0. Based on the NSWC Library of Mathematics Subroutines implementation, DBETLN.

Parameters
p:double

First argument.

q:double

Second argument.

Returns:double

the value of log(Beta(p, q)), NaN if p <= 0 or q <= 0.

logGammaMinusLogGammaSumback to summary
private static double logGammaMinusLogGammaSum(final double a, final double b) throws NumberIsTooSmallException

Returns the value of log[Γ(b) / Γ(a + b)] for a ≥ 0 and b ≥ 10. Based on the NSWC Library of Mathematics Subroutines double precision implementation, DLGDIV. In BetaTest.testLogGammaMinusLogGammaSum(), this private method is accessed through reflection.

Parameters
a:double

First argument.

b:double

Second argument.

Returns:double

the value of log(Gamma(b) / Gamma(a + b)).

Exceptions
NumberIsTooSmallException:
if a < 0.0 or b < 10.0.
logGammaSumback to summary
private static double logGammaSum(final double a, final double b) throws OutOfRangeException

Returns the value of log Γ(a + b) for 1 ≤ a, b ≤ 2. Based on the NSWC Library of Mathematics Subroutines double precision implementation, DGSMLN. In BetaTest.testLogGammaSum(), this private method is accessed through reflection.

Parameters
a:double

First argument.

b:double

Second argument.

Returns:double

the value of log(Gamma(a + b)).

Exceptions
OutOfRangeException:
if a or b is lower than 1.0 or greater than 2.0.
regularizedBetaback to summary
public static double regularizedBeta(double x, double a, double b)

Returns the regularized beta function I(x, a, b).

Parameters
x:double

Value.

a:double

Parameter a.

b:double

Parameter b.

Returns:double

the regularized beta function I(x, a, b).

Exceptions
MaxCountExceededException:
if the algorithm fails to converge.
regularizedBetaback to summary
public static double regularizedBeta(double x, double a, double b, double epsilon)

Returns the regularized beta function I(x, a, b).

Parameters
x:double

Value.

a:double

Parameter a.

b:double

Parameter b.

epsilon:double

When the absolute value of the nth item in the series is less than epsilon the approximation ceases to calculate further elements in the series.

Returns:double

the regularized beta function I(x, a, b)

Exceptions
MaxCountExceededException:
if the algorithm fails to converge.
regularizedBetaback to summary
public static double regularizedBeta(double x, double a, double b, int maxIterations)

Returns the regularized beta function I(x, a, b).

Parameters
x:double

the value.

a:double

Parameter a.

b:double

Parameter b.

maxIterations:int

Maximum number of "iterations" to complete.

Returns:double

the regularized beta function I(x, a, b)

Exceptions
MaxCountExceededException:
if the algorithm fails to converge.
regularizedBetaback to summary
public static double regularizedBeta(double x, final double a, final double b, double epsilon, int maxIterations)

Returns the regularized beta function I(x, a, b). The implementation of this method is based on:

Parameters
x:double

the value.

a:double

Parameter a.

b:double

Parameter b.

epsilon:double

When the absolute value of the nth item in the series is less than epsilon the approximation ceases to calculate further elements in the series.

maxIterations:int

Maximum number of "iterations" to complete.

Returns:double

the regularized beta function I(x, a, b)

Exceptions
MaxCountExceededException:
if the algorithm fails to converge.
sumDeltaMinusDeltaSumback to summary
private static double sumDeltaMinusDeltaSum(final double p, final double q)

Returns the value of Δ(p) + Δ(q) - Δ(p + q), with p, q ≥ 10. Based on the NSWC Library of Mathematics Subroutines double precision implementation, DBCORR. In BetaTest.testSumDeltaMinusDeltaSum(), this private method is accessed through reflection.

Parameters
p:double

First argument.

q:double

Second argument.

Returns:double

the value of Delta(p) + Delta(q) - Delta(p + q).

Exceptions
NumberIsTooSmallException:
if p < 10.0 or q < 10.0.