public class Gamma extends Object
This is a utility class that provides computation methods related to the Γ (Gamma) family of functions.
Implementation of invGamma1pm1(double)
and
logGamma1p(double)
is based on the algorithms described in
Modifier and Type | Field and Description |
---|---|
static double |
GAMMA
|
static double |
LANCZOS_G
The value of the
g constant in the Lanczos approximation, see
lanczos(double) . |
Modifier and Type | Method and Description |
---|---|
static double |
digamma(double x)
Computes the digamma function of x.
|
static double |
gamma(double x)
Returns the value of Γ(x).
|
static double |
invGamma1pm1(double x)
Returns the value of 1 / Γ(1 + x) - 1 for -0.5 ≤ x ≤
1.5.
|
static double |
lanczos(double x)
Returns the Lanczos approximation used to compute the gamma function.
|
static double |
logGamma(double x)
Returns the value of log Γ(x) for x > 0.
|
static double |
logGamma1p(double x)
Returns the value of log Γ(1 + x) for -0.5 ≤ x ≤ 1.5.
|
static double |
regularizedGammaP(double a,
double x)
Returns the regularized gamma function P(a, x).
|
static double |
regularizedGammaP(double a,
double x,
double epsilon,
int maxIterations)
Returns the regularized gamma function P(a, x).
|
static double |
regularizedGammaQ(double a,
double x)
Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
|
static double |
regularizedGammaQ(double a,
double x,
double epsilon,
int maxIterations)
Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
|
static double |
trigamma(double x)
Computes the trigamma function of x.
|
public static final double GAMMA
public static final double LANCZOS_G
g
constant in the Lanczos approximation, see
lanczos(double)
.public static double logGamma(double x)
Returns the value of log Γ(x) for x > 0.
For x ≤ 8, the implementation is based on the double precision
implementation in the NSWC Library of Mathematics Subroutines,
DGAMLN
. For x > 8, the implementation is based on
x
- Argument.log(Gamma(x))
, Double.NaN
if
x <= 0.0
.public static double regularizedGammaP(double a, double x)
a
- Parameter.x
- Value.MaxCountExceededException
- if the algorithm fails to converge.public static double regularizedGammaP(double a, double x, double epsilon, int maxIterations)
a
- the a parameter.x
- the value.epsilon
- 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
- Maximum number of "iterations" to complete.MaxCountExceededException
- if the algorithm fails to converge.public static double regularizedGammaQ(double a, double x)
a
- the a parameter.x
- the value.MaxCountExceededException
- if the algorithm fails to converge.public static double regularizedGammaQ(double a, double x, double epsilon, int maxIterations)
a
- the a parameter.x
- the value.epsilon
- 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
- Maximum number of "iterations" to complete.MaxCountExceededException
- if the algorithm fails to converge.public static double digamma(double x)
Computes the digamma function of x.
This is an independently written implementation of the algorithm described in Jose Bernardo, Algorithm AS 103: Psi (Digamma) Function, Applied Statistics, 1976.
Some of the constants have been changed to increase accuracy at the moderate expense of run-time. The result should be accurate to within 10^-8 absolute tolerance for x >= 10^-5 and within 10^-8 relative tolerance for x > 0.
Performance for large negative values of x will be quite expensive (proportional to |x|). Accuracy for negative values of x should be about 10^-8 absolute for results less than 10^5 and 10^-8 relative for results larger than that.
x
- Argument.public static double trigamma(double x)
x
- Argument.digamma(double)
public static double lanczos(double x)
Returns the Lanczos approximation used to compute the gamma function. The Lanczos approximation is related to the Gamma function by the following equation
gamma(x) = sqrt(2 * pi) / x * (x + g + 0.5) ^ (x + 0.5)
* exp(-x - g - 0.5) * lanczos(x)
,
g
is the Lanczos constant.
x
- Argument.public static double invGamma1pm1(double x)
DGAM1
.x
- Argument.1.0 / Gamma(1.0 + x) - 1.0
.NumberIsTooSmallException
- if x < -0.5
NumberIsTooLargeException
- if x > 1.5
public static double logGamma1p(double x) throws NumberIsTooSmallException, NumberIsTooLargeException
DGMLN1
.x
- Argument.log(Gamma(1 + x))
.NumberIsTooSmallException
- if x < -0.5
.NumberIsTooLargeException
- if x > 1.5
.public static double gamma(double x)
DGAMMA
.x
- Argument.Gamma(x)
.Copyright © 2003–2016 The Apache Software Foundation. All rights reserved.