Class Gamma

java.lang.Object
gov.nih.mipav.model.algorithms.Gamma

public class Gamma extends Object

This code calculates the gamma function of an input argument x.

A typical usage would be:

 double result[] = new double[1];
 Gamma gammaTest = new Gamma(5.0, result);
 gammaTest.run();
 Preferences.debug("Gamma(5.0) = " + result[0] + "\n");
 UI.setDataText("Gamma(5.0) = " + result[0] + "\n");
 


The FORTRAN code this class is based upon is from Computation of Special Functions by Shanjie Zhang and Jianming Jin and copyright 1996 John Wiley & Sons, Inc.

From the diskette that the FORTRAN code came on:

 DISCLAIMER OF WARRANTY
 
 Although we have made a great effort to test and validate the 
 computer programs, we make no warranties, express or implied, that 
 these  programs  are  free  of  error,  or are consistent with any 
 particular  standard  of  merchantability,  or that they will meet 
 your requirements for any particular application.  They should not 
 be relied on for  solving problems  whose incorrect solution could 
 result in  injury to  a person or loss of property.  If you do use 
 the programs in such a manner, it is at your own risk. The authors 
 and publisher  disclaim all liability for  direct or consequential 
 damages resulting from your use of the programs.
 

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private double
     
    private double
     
    static final int
     
    static final int
    Compute gamma function or log of gamma function for complex arguments
    private int
    In lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0
    static final int
    Compute gamma function for real x, x is not equal to 0 or a negative integer
    private double[]
    Imaginary part of outputted result
    private double
    Imaginary part of input argument
    static final int
    Compute incompete gamma functions and regularized gamma P function
    static final int
     
    static final int
    Compute gamma function or log of gamma function for real x > 0
    private double[]
     
    private double[]
    Real part of outputted result
    private double
    Real part of input argument
    private double[]
     
    private double[]
    output result
    private double[]
     
    private int
    GAMMA, LGAMMA, CGAMMA, or INCOG
    private double
    input argument Note that the gamma function is not defined for x equal to zero or a negative integer
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    Gamma(double x, double[] result)
     
    Gamma(double a, double x, double[] lowerIncompleteGamma, double[] upperIncompleteGamma, double[] regularizedGammaP)
     
    Gamma(double a, double b, double x, boolean inverse, double[] result)
     
    Gamma(double realX, double imagX, int functionCode, double[] realResult, double[] imagResult)
     
    Gamma(double x, int functionCode, double[] result)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    cdf()
     
    private void
    This code is a port of the FORTRAN routine CGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 51-52.
    void
    Cleanup memory.
    private void
    This code is a port of the FORTRAN routine GAMMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 49-50.
    private void
    This code is a port of the FORTRAN routine INCOG from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 63-64.
    private void
     
    private void
    This code is a port of the FORTRAN routine LGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 50-51.
    void
    run()
     
    void
     
    void
     
    void
     
    void
     
    void
     
    void
     

    Methods inherited from class java.lang.Object

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

    • GAMMA

      public static final int GAMMA
      Compute gamma function for real x, x is not equal to 0 or a negative integer
      See Also:
    • LGAMMA

      public static final int LGAMMA
      Compute gamma function or log of gamma function for real x > 0
      See Also:
    • CGAMMA

      public static final int CGAMMA
      Compute gamma function or log of gamma function for complex arguments
      See Also:
    • INCOG

      public static final int INCOG
      Compute incompete gamma functions and regularized gamma P function
      See Also:
    • CDF

      public static final int CDF
      See Also:
    • INVERSE_CDF

      public static final int INVERSE_CDF
      See Also:
    • x

      private double x
      input argument Note that the gamma function is not defined for x equal to zero or a negative integer
    • realX

      private double realX
      Real part of input argument
    • imagX

      private double imagX
      Imaginary part of input argument
    • functionCode

      private int functionCode
      In lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0
    • result

      private double[] result
      output result
    • realResult

      private double[] realResult
      Real part of outputted result
    • imagResult

      private double[] imagResult
      Imaginary part of outputted result
    • version

      private int version
      GAMMA, LGAMMA, CGAMMA, or INCOG
    • a

      private double a
    • b

      private double b
    • lowerIncompleteGamma

      private double[] lowerIncompleteGamma
    • upperIncompleteGamma

      private double[] upperIncompleteGamma
    • regularizedGammaP

      private double[] regularizedGammaP
  • Constructor Details

    • Gamma

      public Gamma()
    • Gamma

      public Gamma(double x, double[] result)
      Parameters:
      x - Input argument
      result - outputted gamma(x)
    • Gamma

      public Gamma(double x, int functionCode, double[] result)
      Parameters:
      x - input argument, must have x > 0
      functionCode - 1 for gamma(x), 0 for ln(gamma(x))
      result - outputted gamma(x) or ln(gamma(x))
    • Gamma

      public Gamma(double realX, double imagX, int functionCode, double[] realResult, double[] imagResult)
      Parameters:
      realX - real part of input argument
      imagX - imaginary part of input argument
      functionCode - 1 for gamma(x),0 for ln(gamma(x))
      realResult - real part of outputted gamma(x) or ln(gamma(x))
      imagResult - imaginary part of outputted gamma(x) or ln(gamma(x))
    • Gamma

      public Gamma(double a, double x, double[] lowerIncompleteGamma, double[] upperIncompleteGamma, double[] regularizedGammaP)
      Parameters:
      a -
      x -
      lowerIncompleteGamma -
      upperIncompleteGamma -
      regularizedGammaP -
    • Gamma

      public Gamma(double a, double b, double x, boolean inverse, double[] result)
  • Method Details

    • finalize

      public void finalize() throws Throwable
      Cleanup memory.
      Overrides:
      finalize in class Object
      Throws:
      Throwable - DOCUMENT ME!
    • testInverseCDF

      public void testInverseCDF()
    • testCDF

      public void testCDF()
    • testgamma

      public void testgamma()
    • testlgamma

      public void testlgamma()
    • testcgamma

      public void testcgamma()
    • testincog

      public void testincog()
    • run

      public void run()
    • inverseCumulativeDistributionFunction

      private void inverseCumulativeDistributionFunction()
    • cdf

      private void cdf()
    • gamma

      private void gamma()
      This code is a port of the FORTRAN routine GAMMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 49-50. x is not 0 or a negative integer
    • lgamma

      private void lgamma()
      This code is a port of the FORTRAN routine LGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 50-51. This routine calculates the gamma(x) for functionCode = 1 or the ln(gamma(x)) for the function code = 0. x must be greater than zero.
    • cgamma

      private void cgamma()
      This code is a port of the FORTRAN routine CGAMA from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 51-52. This routine calculates the gamma(x) for functionCode = 1 or the ln(gamma(x)) for the function code = 0. x is complex and the output is complex.
    • incog

      private void incog()
      This code is a port of the FORTRAN routine INCOG from the book Computation of Special Functions by Shanjie Zhang and Jianming Jin, John Wiley invalid input: '&' Sons, Inc., 1996, pp. 63-64. It calculates the incomplete gamma functions and the regularized gamma function P.