Gamma implements IContinuousDistribution { public Gamma(double alpha, double beta) { this.alpha = alpha; this.beta = 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 testGamma(){ double g1=Gamma.gamma(10); double g2=SpecialFunctions.gamma(10); for (double d=0.1; d<10; d+=.01){ assertEquals(Gamma.gamma(d), SpecialFunctions.gamma(d), 1e-3); } }
@Test @Ignore public void stressTestGamma() { double s = 0; int N = 10000000; long t0 = System.currentTimeMillis(); for (int i = 0; i < N; ++i) { Gamma.gamma(1+i%10); } long t1 = System.currentTimeMillis(); System.out.println("New gamma"); System.out.println(t1 - t0); t0 = System.currentTimeMillis(); for (int i = 0; i < N; ++i) { SpecialFunctions.gamma(1+i%10); } t1 = System.currentTimeMillis(); System.out.println("Old gamma"); System.out.println(t1 - t0); }