Author: celestin
Date: Wed Aug 29 04:28:47 2012
New Revision: 1378440

URL: http://svn.apache.org/viewvc?rev=1378440&view=rev
Log:
In GammaDistributionTest, inlined previous implementation of
double Gamma.logGamma(doubl)) in order to allow for comparison with new
implementation.
This is in preparation of MATH-849.

Modified:
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java?rev=1378440&r1=1378439&r2=1378440&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GammaDistributionTest.java
 Wed Aug 29 04:28:47 2012
@@ -176,18 +176,40 @@ public class GammaDistributionTest exten
         Assert.assertEquals(dist.getNumericalVariance(), 1.1d * 4.2d * 4.2d, 
tol);
     }
 
+    private static final double HALF_LOG_2_PI = 0.5 * FastMath.log(2.0 * 
FastMath.PI);
+
+    public static double logGamma(double x) {
+        /*
+         * This is a copy of
+         * double Gamma.logGamma(double)
+         * prior to MATH-849
+         */
+        double ret;
+
+        if (Double.isNaN(x) || (x <= 0.0)) {
+            ret = Double.NaN;
+        } else {
+            double sum = Gamma.lanczos(x);
+            double tmp = x + Gamma.LANCZOS_G + .5;
+            ret = ((x + .5) * FastMath.log(tmp)) - tmp +
+                HALF_LOG_2_PI + FastMath.log(sum / x);
+        }
+
+        return ret;
+    }
+
     public static double density(final double x, final double shape,
                                  final double scale) {
         /*
          * This is a copy of
          * double GammaDistribution.density(double)
-         * prior to r1338548.
+         * prior to MATH-753.
          */
         if (x < 0) {
             return 0;
         }
         return FastMath.pow(x / scale, shape - 1) / scale *
-               FastMath.exp(-x / scale) / FastMath.exp(Gamma.logGamma(shape));
+               FastMath.exp(-x / scale) / FastMath.exp(logGamma(shape));
     }
 
     /*


Reply via email to