Java Gamma gammaPdf(double x, double a)

Here you can find the source of gammaPdf(double x, double a)

Description

gamma Pdf

License

Open Source License

Declaration

public static double gammaPdf(double x, double a) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by      //

public class Main {
    private static final double[] cof = { 76.18009172947146,
            -86.50532032941677, 24.01409824083091, -1.231739572450155,
            0.1208650973866179e-2, -0.5395239384953e-5 };

    public static double gammaPdf(double x, double a) {

        if (x <= 0.0) {
            return 0.0;
        } else {/*from  www  . j  av  a  2  s .c om*/
            return Math.exp(Math.log(x) * (a - 1) - x - lngamma(a));
        }
    }

    /**
     * This is a more literal (that is, exact) copy of the log gamma method from
     * Numerical Recipes than the following one.  It was created by cutting and
     * pasting from the PDF version of the book and then converting C syntax to
     * Java. </p> The static double array above goes with this. </p> Converted
     * to Java by Frank Wimberly
     *
     * @return the value ln[?(xx)] for xx > 0
     */
    public static double lngamma(double xx) {
        //Returns the value ln[?(xx)] for xx > 0.

        if (xx <= 0)
            return Double.NaN;

        //Internal arithmetic will be done in double precision, a nicety that you can omit if ?ve-?gure
        //accuracy is good enough.
        double x, y, tmp, ser;

        int j;
        y = x = xx;
        tmp = x + 5.5;
        tmp -= (x + 0.5) * Math.log(tmp);
        ser = 1.000000000190015;
        for (j = 0; j <= 5; j++) {
            ser += cof[j] / ++y;
        }
        return -tmp + Math.log(2.5066282746310005 * ser / x);
    }
}

Related

  1. gammaFunction(double in)
  2. gammaFwd(double lc)
  3. gammaln(double x)
  4. gammaOfArgOn2Plus1(int d)
  5. gammaOfArgOn2Plus1IncludeDivisor(int d, double divisor)
  6. gammaRand(double a)