Class Gamma


public class Gamma extends GaussLegendreQuadrature
Defines the gamma function, which is a function that extends the concept of factorials from natural to real and complex numbers (except zero and negative integer values). If argument of gamma function is natural and positive, then it relates to factorials as: Gamma(n) = (n - 1)!
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final int
    Defines when to switch to quadrature method.
    private static final double[]
    Coefficients for computation of logarithm of gamma function.
    private static final int
    Default number of maximum iterations to compute incomplete gamma functions.
    private static final double
    Epsilon for double.
    private static boolean
    Indicates whether factorials have been initialized and stored in a table for future faster access.
    private static double[]
    Table where factorials are cached for faster future access.
    private static final double
    Constant related to machine precision.
    private double
    Logarithm of gamma function.
    private static boolean
    Indicates whether logarithm of factorials has been initialized and stored in a table for future faster access.
    private static double[]
    Table where logarithms of factorials are cached for faster future access.
    protected static final int
    Maximum number of logarithm of factorials cached.
    private static final int
    Maximum value supported to estimate factorials for.

    Fields inherited from class com.irurueta.statistics.GaussLegendreQuadrature

    N_GAU, W, Y
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    beta(double z, double w)
    Returns the value of the beta function B(z, w) (aka Euler integral).
    static double
    bico(int n, int k)
    Returns the binomial coefficient (n k) as a floating-point number, which indicates the discrete probability distribution of getting exactly k successes in n trials.
    static double
    factln(int n)
    Returns logarithm of n!
    static double
    factrl(int n)
    Returns the factorial of n (n!) as a floating-point number.
    static double
    gammln(double xx)
    Returns the value ln(gamma(xx)) for xx > 0.
    double
    gammp(double a, double x)
    Returns the incomplete gamma function P(a,x).
    private double
    gammpapprox(double a, double x, int psig)
    Incomplete gamma by quadrature.
    double
    gammq(double a, double x)
    Returns the incomplete gamma function Q(a, x) = 1 - P(a, x).
    private double
    gcf(double a, double x)
    Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.
    private double
    gcf(double a, double x, int maxIterations)
    Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.
    double
    Returns logarithm of gamma function.
    private double
    gser(double a, double x)
    Returns the incomplete gamma function P(a, x) evaluated by its series representation.
    private double
    gser(double a, double x, int maxIterations)
    Returns the incomplete gamma function P(a, x) evaluated by its series representation.
    double
    invgammp(double p, double a)
    Inverse function on x of P(a, x).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_CACHED_LOG_FACTORIALS

      protected static final int MAX_CACHED_LOG_FACTORIALS
      Maximum number of logarithm of factorials cached.
      See Also:
    • ASWITCH

      private static final int ASWITCH
      Defines when to switch to quadrature method.
      See Also:
    • EPS

      private static final double EPS
      Epsilon for double. It is related to machine precision.
    • FPMIN

      private static final double FPMIN
      Constant related to machine precision.
    • MAX_FACTORIALS

      private static final int MAX_FACTORIALS
      Maximum value supported to estimate factorials for.
      See Also:
    • DEFAULT_MAX_ITERATIONS

      private static final int DEFAULT_MAX_ITERATIONS
      Default number of maximum iterations to compute incomplete gamma functions.
      See Also:
    • COF

      private static final double[] COF
      Coefficients for computation of logarithm of gamma function.
    • factorialsInitialized

      private static boolean factorialsInitialized
      Indicates whether factorials have been initialized and stored in a table for future faster access.
    • factorialsTable

      private static double[] factorialsTable
      Table where factorials are cached for faster future access.
    • logarithmOfFactorialsInitialized

      private static boolean logarithmOfFactorialsInitialized
      Indicates whether logarithm of factorials has been initialized and stored in a table for future faster access.
    • logarithmOfFactorialsTable

      private static double[] logarithmOfFactorialsTable
      Table where logarithms of factorials are cached for faster future access.
    • gln

      private double gln
      Logarithm of gamma function.
  • Constructor Details

    • Gamma

      public Gamma()
  • Method Details

    • getGln

      public double getGln()
      Returns logarithm of gamma function.
      Returns:
      logarithm of gamma function.
    • gammln

      public static double gammln(double xx)
      Returns the value ln(gamma(xx)) for xx > 0.
      Parameters:
      xx - a value.
      Returns:
      the logarithm of gamma function.
      Throws:
      IllegalArgumentException - if value is negative.
    • factrl

      public static double factrl(int n)
      Returns the factorial of n (n!) as a floating-point number. Factorials up to 22! have exact double precision representations. Factorials from 23! to 170! are approximate due to IEEE double representation. Factorials equal or greater than 170! are out of range.
      Parameters:
      n - value to compute factorial for.
      Returns:
      factorial of n, (i.e. n!).
      Throws:
      IllegalArgumentException - if provided value generates a factorial that cannot be represented using double precision.
    • factln

      public static double factln(int n)
      Returns logarithm of n!
      Parameters:
      n - value to compute logarithm of factorial for.
      Returns:
      logarithm of factorial.
      Throws:
      IllegalArgumentException - if provided value is negative.
    • bico

      public static double bico(int n, int k)
      Returns the binomial coefficient (n k) as a floating-point number, which indicates the discrete probability distribution of getting exactly k successes in n trials.
      Parameters:
      n - number of trials.
      k - number of successes.
      Returns:
      binomial value.
      Throws:
      IllegalArgumentException - if either n or k are negative or if k is greater than n.
    • beta

      public static double beta(double z, double w)
      Returns the value of the beta function B(z, w) (aka Euler integral).
      Parameters:
      z - a parameter.
      w - a parameter.
      Returns:
      value of beta function.
      Throws:
      IllegalArgumentException - if either z or w are negative.
    • gammp

      public double gammp(double a, double x) throws MaxIterationsExceededException
      Returns the incomplete gamma function P(a,x).
      Parameters:
      a - a parameter.
      x - x parameter.
      Returns:
      value of incomplete gamma function.
      Throws:
      IllegalArgumentException - if provided values are invalid.
      MaxIterationsExceededException - if convergence cannot be reached.
    • gammq

      public double gammq(double a, double x) throws MaxIterationsExceededException
      Returns the incomplete gamma function Q(a, x) = 1 - P(a, x).
      Parameters:
      a - a parameter.
      x - x parameter.
      Returns:
      value of incomplete gamma function.
      Throws:
      IllegalArgumentException - if provided values are invalid.
      MaxIterationsExceededException - if convergence cannot be reached.
    • gser

      private double gser(double a, double x) throws MaxIterationsExceededException
      Returns the incomplete gamma function P(a, x) evaluated by its series representation.
      Parameters:
      a - a parameter to obtain its gamma logarithm.
      x - x parameter.
      Returns:
      incomplete gamma function.
      Throws:
      MaxIterationsExceededException - if maximum number of iterations is exceeded.
    • gser

      private double gser(double a, double x, int maxIterations) throws MaxIterationsExceededException
      Returns the incomplete gamma function P(a, x) evaluated by its series representation.
      Parameters:
      a - a parameter to obtain its gamma logarithm.
      x - x parameter.
      maxIterations - maximum number of iterations.
      Returns:
      incomplete gamma function.
      Throws:
      MaxIterationsExceededException - if maximum number of iterations is exceeded.
    • gcf

      private double gcf(double a, double x) throws MaxIterationsExceededException
      Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.
      Parameters:
      a - a parameter to obtain its gamma logarithm.
      x - x parameter.
      Returns:
      incomplete gamma function.
      Throws:
      MaxIterationsExceededException - if maximum number of iterations is exceeded.
    • gcf

      private double gcf(double a, double x, int maxIterations) throws MaxIterationsExceededException
      Returns the incomplete gamma function Q(a, x) evaluated by its continued fraction representation.
      Parameters:
      a - a parameter to obtain its gamma logarithm.
      x - x parameter.
      maxIterations - maximum number of iterations.
      Returns:
      incomplete gamma function.
      Throws:
      MaxIterationsExceededException - if maximum number of iterations is exceeded.
    • gammpapprox

      private double gammpapprox(double a, double x, int psig)
      Incomplete gamma by quadrature. Returns P(a, x) or Q(a, x), when psig is 1 or 0 respectively.
      Parameters:
      a - a parameter.
      x - x parameter.
      psig - a flag.
      Returns:
      incomplete gamma by quadrature.
    • invgammp

      public double invgammp(double p, double a) throws MaxIterationsExceededException
      Inverse function on x of P(a, x). Returns x such that P(a,x) = p for an argument p between 0 and 1.
      Parameters:
      p - argument p.
      a - a parameter.
      Returns:
      inverse value.
      Throws:
      IllegalArgumentException - if arguments are invalid.
      MaxIterationsExceededException - if maximum number of iterations is exceeded.