Gamma implements IContinuousDistribution { @Override public double getDensity(double x) throws DStatException { if (x < 0) { throw new IllegalArgumentException(); } if (x == 0) { if (alpha == 1.0) { return 1/beta; } else { return 0.0; } } if (alpha == 1.0) { return Math.exp(-x / beta) / beta; } return Math.exp((alpha - 1.0) * Math.log(x / beta) - x / beta - logGamma(alpha)) / beta; } Gamma(double alpha, double beta); @Override double getDensity(double x); double getShape(); double getScale(); @Override double getLeftBound(); @Override double getRightBound(); @Override String getDescription(); @Override double getExpectation(); @Override double getProbability(double x, ProbabilityType pt); @Override double getProbabilityInverse(double p, ProbabilityType pt); @Override double getVariance(); @Override BoundaryType hasLeftBound(); @Override BoundaryType hasRightBound(); @Override boolean isSymmetrical(); @Override double random(IRandomNumberGenerator rng); static double beta(double a, double b); static double gamma(double x); static double incompleteBeta(double aa, double bb, double xx); static double incompleteBetaFraction1(double a, double b, double x); static double incompleteGamma(double a, double x); static double incompleteGammaComplement(double a, double x); static double logGamma(double x); static final double MAXGAM; }
@Test public void testDensity(){ int nf=12; Gamma dist = new Gamma(nf/2,2); Chi2 chi=new Chi2(nf); for (double d=0; d<100; d+=.05){ assertEquals(dist.getDensity(d),chi.getDensity(d), 1e-6); } }