org.apache.commons.math.special

## Class Gamma

- java.lang.Object
- - org.apache.commons.math.special.Gamma

-     public class Gamma
      extends java.lang.Object

  This is a utility class that provides computation methods related to the Gamma family of functions.
  Version:
    $Revision: 1042510 $ $Date: 2010-12-06 02:54:18 +0100 (lun. 06 déc. 2010) $

- - ### Field Summary

    Fields
    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` Euler-Mascheroni constant
    `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.

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `private` | `Gamma()` Default constructor.

  - ### Method Summary

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

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### GAMMA

          public static final double GAMMA

      Euler-Mascheroni constant
      Since:
        2.0
      See Also:
        Constant Field Values

    - #### DEFAULT_EPSILON

          private static final double DEFAULT_EPSILON

      Maximum allowed numerical error.
      See Also:
        Constant Field Values

    - #### LANCZOS

          private static final double[] LANCZOS

      Lanczos coefficients

    - #### HALF_LOG_2_PI

          private static final double HALF_LOG_2_PI

      Avoid repeated computation of log of 2 PI in logGamma

    - #### C_LIMIT

          private static final double C_LIMIT

      C limit.
      See Also:
        Constant Field Values

    - #### S_LIMIT

          private static final double S_LIMIT

      S limit.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Gamma

          private Gamma()

      Default constructor. Prohibit instantiation.

  - ### Method Detail

    - #### logGamma

          public static double logGamma(double x)

      Returns the natural logarithm of the gamma function Γ(x). The implementation of this method is based on:
      - Gamma Function, equation (28).
      - Lanczos Approximation, equations (1) through (5).
      - Paul Godfrey, A note on the computation of the convergent Lanczos complex Gamma approximation
      Parameters:
        `x` - the value.
      Returns:
        log(Γ(x))

    - #### regularizedGammaP

          public static double regularizedGammaP(double a,
                                 double x)
                                          throws MathException

      Returns the regularized gamma function P(a, x).
      Parameters:
        `a` - the a parameter.
        `x` - the value.
      Returns:
        the regularized gamma function P(a, x)
      Throws:
        `MathException` - if the algorithm fails to converge.

    - #### regularizedGammaP

          public static double regularizedGammaP(double a,
                                 double x,
                                 double epsilon,
                                 int maxIterations)
                                          throws MathException

      Returns the regularized gamma function P(a, x). The implementation of this method is based on:
      - Regularized Gamma Function, equation (1).
      - Incomplete Gamma Function, equation (4).
      - Confluent Hypergeometric Function of the First Kind, equation (1).
      Parameters:
        `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.
      Returns:
        the regularized gamma function P(a, x)
      Throws:
        `MathException` - if the algorithm fails to converge.

    - #### regularizedGammaQ

          public static double regularizedGammaQ(double a,
                                 double x)
                                          throws MathException

      Returns the regularized gamma function Q(a, x) = 1 - P(a, x).
      Parameters:
        `a` - the a parameter.
        `x` - the value.
      Returns:
        the regularized gamma function Q(a, x)
      Throws:
        `MathException` - if the algorithm fails to converge.

    - #### regularizedGammaQ

          public static double regularizedGammaQ(double a,
                                 double x,
                                 double epsilon,
                                 int maxIterations)
                                          throws MathException

      Returns the regularized gamma function Q(a, x) = 1 - P(a, x). The implementation of this method is based on:
      - Regularized Gamma Function, equation (1).
      - Regularized incomplete gamma function: Continued fraction representations (formula 06.08.10.0003)
      Parameters:
        `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.
      Returns:
        the regularized gamma function P(a, x)
      Throws:
        `MathException` - if the algorithm fails to converge.

    - #### digamma

          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.

      Parameters:
        `x` - the argument
      Returns:
        digamma(x) to within 10-8 relative or absolute error whichever is smaller
      Since:
        2.0
      See Also:
        Digamma at wikipedia , Bernardo's original article

    - #### trigamma

          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.

      Parameters:
        `x` - the argument
      Returns:
        trigamma(x) to within 10-8 relative or absolute error whichever is smaller
      Since:
        2.0
      See Also:
        Trigamma at wikipedia , `digamma(double)`

Copyright (c) 2003-2013 Apache Software Foundation