public class Gamma
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static double |
C_LIMIT
C limit.
|
private static double |
DEFAULT_EPSILON
Maximum allowed numerical error.
|
static double |
GAMMA
|
private static double |
HALF_LOG_2_PI
Avoid repeated computation of log of 2 PI in logGamma
|
private static double[] |
LANCZOS
Lanczos coefficients
|
private static double |
S_LIMIT
S limit.
|
Modifier | Constructor and Description |
---|---|
private |
Gamma()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
static double |
digamma(double x)
Computes the digamma function of x.
|
static double |
logGamma(double x)
Returns the natural logarithm of the gamma function Γ(x).
|
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
private static final double DEFAULT_EPSILON
private static final double[] LANCZOS
private static final double HALF_LOG_2_PI
private static final double C_LIMIT
private static final double S_LIMIT
public static double logGamma(double x)
x
- the value.public static double regularizedGammaP(double a, double x) throws MathException
a
- the a parameter.x
- the value.MathException
- if the algorithm fails to converge.public static double regularizedGammaP(double a, double x, double epsilon, int maxIterations) throws MathException
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.MathException
- if the algorithm fails to converge.public static double regularizedGammaQ(double a, double x) throws MathException
a
- the a parameter.x
- the value.MathException
- if the algorithm fails to converge.public static double regularizedGammaQ(double a, double x, double epsilon, int maxIterations) throws MathException
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.MathException
- 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
- the argumentpublic static double trigamma(double x)
Computes the trigamma function of x. This function is derived by taking the derivative of the implementation of digamma.
x
- the argumentdigamma(double)
Copyright (c) 2003-2016 Apache Software Foundation