Package gov.nih.mipav.model.algorithms
Class Gamma
java.lang.Object
gov.nih.mipav.model.algorithms.Gamma
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
FieldsModifier and TypeFieldDescriptionprivate doubleprivate doublestatic final intstatic final intCompute gamma function or log of gamma function for complex argumentsprivate intIn lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0static final intCompute gamma function for real x, x is not equal to 0 or a negative integerprivate double[]Imaginary part of outputted resultprivate doubleImaginary part of input argumentstatic final intCompute incompete gamma functions and regularized gamma P functionstatic final intstatic final intCompute gamma function or log of gamma function for real x > 0private double[]private double[]Real part of outputted resultprivate doubleReal part of input argumentprivate double[]private double[]output resultprivate double[]private intGAMMA, LGAMMA, CGAMMA, or INCOGprivate doubleinput argument Note that the gamma function is not defined for x equal to zero or a negative integer -
Constructor Summary
ConstructorsConstructorDescriptionGamma()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 TypeMethodDescriptionprivate voidcdf()private voidcgamma()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.voidfinalize()Cleanup memory.private voidgamma()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 voidincog()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 voidprivate voidlgamma()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.voidrun()voidtestCDF()voidvoidvoidvoidvoid
-
Field Details
-
GAMMA
public static final int GAMMACompute gamma function for real x, x is not equal to 0 or a negative integer- See Also:
-
LGAMMA
public static final int LGAMMACompute gamma function or log of gamma function for real x > 0- See Also:
-
CGAMMA
public static final int CGAMMACompute gamma function or log of gamma function for complex arguments- See Also:
-
INCOG
public static final int INCOGCompute 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 xinput argument Note that the gamma function is not defined for x equal to zero or a negative integer -
realX
private double realXReal part of input argument -
imagX
private double imagXImaginary part of input argument -
functionCode
private int functionCodeIn lgamma and cgamma calculate gamma(x) for functionCode = 1 and calulate the ln(gamma(x)) for functionCode = 0 -
result
private double[] resultoutput result -
realResult
private double[] realResultReal part of outputted result -
imagResult
private double[] imagResultImaginary part of outputted result -
version
private int versionGAMMA, 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 argumentresult- outputted gamma(x)
-
Gamma
public Gamma(double x, int functionCode, double[] result) - Parameters:
x- input argument, must have x > 0functionCode- 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 argumentimagX- imaginary part of input argumentfunctionCode- 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
Cleanup memory. -
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.
-