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 |
|---|---|
| private static final double | C_LIMIT
C limit. |
| private static final double | DEFAULT_EPSILON
Maximum allowed numerical error. |
| public static final double | |
| private static final double | HALF_LOG_2_PI
Avoid repeated computation of log of 2 PI in logGamma |
| private static final double | INV_GAMMA1P_M1_A0
The constant |
| private static final double | INV_GAMMA1P_M1_A1
The constant |
| private static final double | INV_GAMMA1P_M1_B1
The constant |
| private static final double | INV_GAMMA1P_M1_B2
The constant |
| private static final double | INV_GAMMA1P_M1_B3
The constant |
| private static final double | INV_GAMMA1P_M1_B4
The constant |
| private static final double | INV_GAMMA1P_M1_B5
The constant |
| private static final double | INV_GAMMA1P_M1_B6
The constant |
| private static final double | INV_GAMMA1P_M1_B7
The constant |
| private static final double | INV_GAMMA1P_M1_B8
The constant |
| private static final double | INV_GAMMA1P_M1_C
The constant |
| private static final double | INV_GAMMA1P_M1_C0
The constant |
| private static final double | INV_GAMMA1P_M1_C1
The constant |
| private static final double | INV_GAMMA1P_M1_C10
The constant |
| private static final double | INV_GAMMA1P_M1_C11
The constant |
| private static final double | INV_GAMMA1P_M1_C12
The constant |
| private static final double | INV_GAMMA1P_M1_C13
The constant |
| private static final double | INV_GAMMA1P_M1_C2
The constant |
| private static final double | INV_GAMMA1P_M1_C3
The constant |
| private static final double | INV_GAMMA1P_M1_C4
The constant |
| private static final double | INV_GAMMA1P_M1_C5
The constant |
| private static final double | INV_GAMMA1P_M1_C6
The constant |
| private static final double | INV_GAMMA1P_M1_C7
The constant |
| private static final double | INV_GAMMA1P_M1_C8
The constant |
| private static final double | INV_GAMMA1P_M1_C9
The constant |
| private static final double | INV_GAMMA1P_M1_P0
The constant |
| private static final double | INV_GAMMA1P_M1_P1
The constant |
| private static final double | INV_GAMMA1P_M1_P2
The constant |
| private static final double | INV_GAMMA1P_M1_P3
The constant |
| private static final double | INV_GAMMA1P_M1_P4
The constant |
| private static final double | INV_GAMMA1P_M1_P5
The constant |
| private static final double | INV_GAMMA1P_M1_P6
The constant |
| private static final double | INV_GAMMA1P_M1_Q1
The constant |
| private static final double | INV_GAMMA1P_M1_Q2
The constant |
| private static final double | INV_GAMMA1P_M1_Q3
The constant |
| private static final double | INV_GAMMA1P_M1_Q4
The constant |
| private static final double[] | LANCZOS
Lanczos coefficients |
| public static final double | LANCZOS_G
The value of the |
| private static final double | S_LIMIT
S limit. |
| private static final double | SQRT_TWO_PI
The constant value of √(2π). |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static double | Returns: digamma(x) to within 10-8 relative or absolute error whichever is smaller.Argument. x)Computes the digamma function of x. |
| public static double | |
| public static double | Returns: The value of1.0 / Gamma(1.0 + x) - 1.0.Argument. x)Returns the value of 1 / Γ(1 + x) - 1 for -0.5 ≤ x ≤ 1.5. |
| public static double | Returns: The Lanczos approximation.Argument. x)Returns the Lanczos approximation used to compute the gamma function.</center> |
| public static double | Returns: the value oflog(Gamma(x)), Double.NaN if
x <= 0.0.Argument. x)Returns the value of log Γ(x) for x > 0. |
| public static double | Returns: The value oflog(Gamma(1 + x)).Argument. x)Returns the value of log Γ(1 + x) for -0.5 ≤ x ≤ 1.5. |
| public static double | Returns: the regularized gamma function P(a, x).Parameter. a, double Value. x)Returns the regularized gamma function P(a, x). |
| public static double | Returns: the regularized gamma function P(a, x)the a parameter. a, double the value. x, 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 gamma function P(a, x). |
| public static double | Returns: the regularized gamma function Q(a, x)the a parameter. a, double the value. x)Returns the regularized gamma function Q(a, x) = 1 - P(a, x). |
| public static double | Returns: the regularized gamma function P(a, x)the a parameter. a, double the value. x, 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 gamma function Q(a, x) = 1 - P(a, x). |
| public static double | Returns: trigamma(x) to within 10-8 relative or absolute error whichever is smallerArgument. x)Computes the trigamma function of x. |
| C_LIMIT | back to summary |
|---|---|
| private static final double C_LIMIT C limit. | |
| DEFAULT_EPSILON | back to summary |
|---|---|
| private static final double DEFAULT_EPSILON Maximum allowed numerical error. | |
| GAMMA | back to summary |
|---|---|
public static final double GAMMA
| |
| HALF_LOG_2_PI | back to summary |
|---|---|
| private static final double HALF_LOG_2_PI Avoid repeated computation of log of 2 PI in logGamma | |
| INV_GAMMA1P_M1_A0 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_A0 The constant | |
| INV_GAMMA1P_M1_A1 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_A1 The constant | |
| INV_GAMMA1P_M1_B1 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B1 The constant | |
| INV_GAMMA1P_M1_B2 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B2 The constant | |
| INV_GAMMA1P_M1_B3 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B3 The constant | |
| INV_GAMMA1P_M1_B4 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B4 The constant | |
| INV_GAMMA1P_M1_B5 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B5 The constant | |
| INV_GAMMA1P_M1_B6 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B6 The constant | |
| INV_GAMMA1P_M1_B7 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B7 The constant | |
| INV_GAMMA1P_M1_B8 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_B8 The constant | |
| INV_GAMMA1P_M1_C | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C The constant | |
| INV_GAMMA1P_M1_C0 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C0 The constant | |
| INV_GAMMA1P_M1_C1 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C1 The constant | |
| INV_GAMMA1P_M1_C10 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C10 The constant | |
| INV_GAMMA1P_M1_C11 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C11 The constant | |
| INV_GAMMA1P_M1_C12 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C12 The constant | |
| INV_GAMMA1P_M1_C13 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C13 The constant | |
| INV_GAMMA1P_M1_C2 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C2 The constant | |
| INV_GAMMA1P_M1_C3 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C3 The constant | |
| INV_GAMMA1P_M1_C4 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C4 The constant | |
| INV_GAMMA1P_M1_C5 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C5 The constant | |
| INV_GAMMA1P_M1_C6 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C6 The constant | |
| INV_GAMMA1P_M1_C7 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C7 The constant | |
| INV_GAMMA1P_M1_C8 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C8 The constant | |
| INV_GAMMA1P_M1_C9 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_C9 The constant | |
| INV_GAMMA1P_M1_P0 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P0 The constant | |
| INV_GAMMA1P_M1_P1 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P1 The constant | |
| INV_GAMMA1P_M1_P2 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P2 The constant | |
| INV_GAMMA1P_M1_P3 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P3 The constant | |
| INV_GAMMA1P_M1_P4 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P4 The constant | |
| INV_GAMMA1P_M1_P5 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P5 The constant | |
| INV_GAMMA1P_M1_P6 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_P6 The constant | |
| INV_GAMMA1P_M1_Q1 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_Q1 The constant | |
| INV_GAMMA1P_M1_Q2 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_Q2 The constant | |
| INV_GAMMA1P_M1_Q3 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_Q3 The constant | |
| INV_GAMMA1P_M1_Q4 | back to summary |
|---|---|
| private static final double INV_GAMMA1P_M1_Q4 The constant | |
| LANCZOS | back to summary |
|---|---|
| private static final double[] LANCZOS Lanczos coefficients | |
| LANCZOS_G | back to summary |
|---|---|
| public static final double LANCZOS_G The value of the
| |
| S_LIMIT | back to summary |
|---|---|
| private static final double S_LIMIT S limit. | |
| SQRT_TWO_PI | back to summary |
|---|---|
| private static final double SQRT_TWO_PI The constant value of √(2π). | |
| Gamma | back to summary |
|---|---|
| private Gamma() Default constructor. Prohibit instantiation. | |
| digamma | back to summary |
|---|---|
| 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.
| |
| gamma | back to summary |
|---|---|
| public static double gamma(final double x) Returns the value of Γ(x). Based on the NSWC Library of
Mathematics Subroutines double precision implementation,
| |
| invGamma1pm1 | back to summary |
|---|---|
| public static double invGamma1pm1(final double x) Returns the value of 1 / Γ(1 + x) - 1 for -0.5 ≤ x ≤
1.5. This implementation is based on the double precision
implementation in the NSWC Library of Mathematics Subroutines,
| |
| lanczos | back to summary |
|---|---|
| public static double lanczos(final 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.
| |
| logGamma | back to summary |
|---|---|
| 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,
| |
| logGamma1p | back to summary |
|---|---|
| public static double logGamma1p(final double x) throws NumberIsTooSmallException, NumberIsTooLargeException Returns the value of log Γ(1 + x) for -0.5 ≤ x ≤ 1.5.
This implementation is based on the double precision implementation in
the NSWC Library of Mathematics Subroutines,
| |
| regularizedGammaP | back to summary |
|---|---|
| public static double regularizedGammaP(double a, double x) Returns the regularized gamma function P(a, x).
| |
| regularizedGammaP | back to summary |
|---|---|
| public static double regularizedGammaP(double a, double x, double epsilon, int maxIterations) Returns the regularized gamma function P(a, x). The implementation of this method is based on:
| |
| regularizedGammaQ | back to summary |
|---|---|
| public static double regularizedGammaQ(double a, double x) Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
| |
| regularizedGammaQ | back to summary |
|---|---|
| public static double regularizedGammaQ(final double a, double x, double epsilon, int maxIterations) Returns the regularized gamma function Q(a, x) = 1 - P(a, x). The implementation of this method is based on:
| |
| trigamma | back to summary |
|---|---|
| public static double trigamma(double x) Computes the trigamma function of x. This function is derived by taking the derivative of the implementation of digamma.
| |