You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2013/10/13 23:33:14 UTC

svn commit: r1531756 - /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/

Author: psteitz
Date: Sun Oct 13 21:33:13 2013
New Revision: 1531756

URL: http://svn.apache.org/r1531756
Log:
Improved precision in reference data; decreased default tolerance in IntegerDistributionAbstract test.  JIRA: MATH-1037.

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/BinomialDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GeometricDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/IntegerDistributionAbstractTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/BinomialDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/BinomialDistributionTest.java?rev=1531756&r1=1531755&r2=1531756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/BinomialDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/BinomialDistributionTest.java Sun Oct 13 21:33:13 2013
@@ -24,6 +24,13 @@ import org.junit.Test;
  */
 public class BinomialDistributionTest extends IntegerDistributionAbstractTest {
 
+    /**
+     * Constructor to override default tolerance.
+     */
+    public BinomialDistributionTest() {
+        setTolerance(1e-12);
+    }
+    
     // -------------- Implementations for abstract methods
     // -----------------------
 
@@ -33,18 +40,21 @@ public class BinomialDistributionTest ex
         return new BinomialDistribution(10, 0.70);
     }
 
-    /** Creates the default probability density test input values */
+    /** Creates the default probability density test input values. */
     @Override
     public int[] makeDensityTestPoints() {
         return new int[] { -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
     }
 
-    /** Creates the default probability density test expected values */
+    /** 
+     * Creates the default probability density test expected values.
+     * Reference values are from R, version 2.15.3.
+     */
     @Override
     public double[] makeDensityTestValues() {
-        return new double[] { 0d, 0.0000059049d, 0.000137781d, 0.0014467d,
-                0.00900169d, 0.0367569d, 0.102919d, 0.200121d, 0.266828d,
-                0.233474d, 0.121061d, 0.0282475d, 0d };
+        return new double[] { 0d, 0.0000059049d, 0.000137781d, 0.0014467005,
+            0.009001692, 0.036756909, 0.1029193452, 0.200120949, 0.266827932,
+            0.2334744405, 0.121060821, 0.0282475249, 0d };
     }
 
     /** Creates the default cumulative probability density test input values */
@@ -53,11 +63,14 @@ public class BinomialDistributionTest ex
         return makeDensityTestPoints();
     }
 
-    /** Creates the default cumulative probability density test expected values */
+    /**
+     * Creates the default cumulative probability density test expected values.
+     * Reference values are from R, version 2.15.3.
+     */
     @Override
     public double[] makeCumulativeTestValues() {
-        return new double[] { 0d, 0.0000d, 0.0001d, 0.0016d, 0.0106d, 0.0473d,
-                0.1503d, 0.3504d, 0.6172d, 0.8507d, 0.9718d, 1d, 1d };
+        return new double[] { 0d, 5.9049e-06, 0.0001436859, 0.0015903864, 0.0105920784,  0.0473489874,
+            0.1502683326, 0.3503892816, 0.6172172136, 0.8506916541, 0.9717524751, 1d, 1d };
     }
 
     /** Creates the default inverse cumulative probability test input values */

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GeometricDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GeometricDistributionTest.java?rev=1531756&r1=1531755&r2=1531756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GeometricDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/GeometricDistributionTest.java Sun Oct 13 21:33:13 2013
@@ -26,10 +26,13 @@ import org.junit.Test;
  */
 public class GeometricDistributionTest extends IntegerDistributionAbstractTest {
 
+    /**
+     * Constructor to override default tolerance.
+     */
     public GeometricDistributionTest() {
-        setTolerance(1e-7);
+        setTolerance(1e-12);
     }
-
+    
     // -------------- Implementations for abstract methods --------------------
 
     /** Creates the default discrete distribution instance to use in tests. */
@@ -46,18 +49,20 @@ public class GeometricDistributionTest e
                            19, 20, 21, 22, 23, 24, 25, 26, 27, 28 };
     }
 
-    /** Creates the default probability density test expected values */
+    /**
+     * Creates the default probability density test expected values.
+     * Reference values are from R, version version 2.15.3.
+     */
     @Override
     public double[] makeDensityTestValues() {
         return new double[] {
-            0.000000e+00, 4.000000e-01, 2.400000e-01, 1.440000e-01,
-            8.640000e-02, 5.184000e-02, 3.110400e-02, 1.866240e-02,
-            1.119744e-02, 6.718464e-03, 4.031078e-03, 2.418647e-03,
-            1.451188e-03, 8.707129e-04, 5.224278e-04, 3.134567e-04,
-            1.880740e-04, 1.128444e-04, 6.770664e-05, 4.062398e-05,
-            2.437439e-05, 1.462463e-05, 8.774780e-06, 5.264868e-06,
-            3.158921e-06, 1.895353e-06, 1.137212e-06, 6.823269e-07,
-            4.093961e-07, 2.456377e-07
+            0d, 0.4, 0.24, 0.144, 0.0864, 0.05184, 0.031104, 0.0186624,
+            0.01119744, 0.006718464, 0.0040310784, 0.00241864704,
+            0.001451188224,0.0008707129344, 0.00052242776064, 0.000313456656384,
+            0.00018807399383, 0.000112844396298, 6.77066377789e-05, 4.06239826674e-05,
+            2.43743896004e-05, 1.46246337603e-05, 8.77478025615e-06, 5.26486815369e-06,
+            3.15892089221e-06, 1.89535253533e-06, 1.1372115212e-06, 6.82326912718e-07,
+            4.09396147631e-07, 2.45637688579e-07
         };
     }
 
@@ -70,14 +75,14 @@ public class GeometricDistributionTest e
     /** Creates the default cumulative probability density test expected values */
     @Override
     public double[] makeCumulativeTestValues() {
-        return new double[] {
-            0.0000000, 0.4000000, 0.6400000, 0.7840000, 0.8704000,
-            0.9222400, 0.9533440, 0.9720064, 0.9832038, 0.9899223,
-            0.9939534, 0.9963720, 0.9978232, 0.9986939, 0.9992164,
-            0.9995298, 0.9997179, 0.9998307, 0.9998984, 0.9999391,
-            0.9999634, 0.9999781, 0.9999868, 0.9999921, 0.9999953,
-            0.9999972, 0.9999983, 0.9999990, 0.9999994, 0.9999996
-        };
+        final double[] densities = makeDensityTestValues();
+        final int n = densities.length;
+        final double[] ret = new double[n];
+        ret[0] = densities[0];
+        for (int i = 1; i < n; i++) {
+            ret[i] = ret[i - 1] + densities[i];
+        }
+        return ret;
     }
 
     /** Creates the default inverse cumulative probability test input values */

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java?rev=1531756&r1=1531755&r2=1531756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/HypergeometricDistributionTest.java Sun Oct 13 21:33:13 2013
@@ -34,7 +34,14 @@ import org.junit.Test;
  */
 public class HypergeometricDistributionTest extends IntegerDistributionAbstractTest {
 
-//-------------- Implementations for abstract methods -----------------------
+    /**
+     * Constructor to override default tolerance.
+     */
+    public HypergeometricDistributionTest() {
+        setTolerance(1e-12);
+    }
+    
+    //-------------- Implementations for abstract methods -----------------------
 
     /** Creates the default discrete distribution instance to use in tests. */
     @Override
@@ -48,11 +55,14 @@ public class HypergeometricDistributionT
         return new int[] {-1, 0, 1, 2, 3, 4, 5, 10};
     }
 
-    /** Creates the default probability density test expected values */
+    /** 
+     * Creates the default probability density test expected values
+     * Reference values are from R, version 2.15.3.
+     */
     @Override
     public double[] makeDensityTestValues() {
-        return new double[] {0d, 0.003968d, 0.099206d, 0.396825d, 0.396825d,
-                0.099206d, 0.003968d, 0d};
+        return new double[] {0d, 0.00396825396825, 0.0992063492063, 0.396825396825, 0.396825396825,
+            0.0992063492063, 0.00396825396825, 0d};
     }
 
     /** Creates the default cumulative probability density test input values */
@@ -61,11 +71,14 @@ public class HypergeometricDistributionT
         return makeDensityTestPoints();
     }
 
-    /** Creates the default cumulative probability density test expected values */
+    /** 
+     * Creates the default cumulative probability density test expected values
+     * Reference values are from R, version 2.15.3.
+     */
     @Override
     public double[] makeCumulativeTestValues() {
-        return new double[] {0d, .003968d, .103175d, .50000d, .896825d, .996032d,
-                1.00000d, 1d};
+        return new double[] {0d, 0.00396825396825, 0.103174603175, .5, 0.896825396825, 0.996031746032,
+                1, 1};
     }
 
     /** Creates the default inverse cumulative probability test input values */

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/IntegerDistributionAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/IntegerDistributionAbstractTest.java?rev=1531756&r1=1531755&r2=1531756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/IntegerDistributionAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/IntegerDistributionAbstractTest.java Sun Oct 13 21:33:13 2013
@@ -52,7 +52,7 @@ public abstract class IntegerDistributio
     private IntegerDistribution distribution;
 
     /** Tolerance used in comparing expected and returned values */
-    private double tolerance = 1E-4;
+    private double tolerance = 1E-12;
 
     /** Arguments used to test probability density calculations */
     private int[] densityTestPoints;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java?rev=1531756&r1=1531755&r2=1531756&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/distribution/ZipfDistributionTest.java Sun Oct 13 21:33:13 2013
@@ -32,6 +32,13 @@ import org.junit.Test;
  */
 public class ZipfDistributionTest extends IntegerDistributionAbstractTest {
 
+    /**
+     * Constructor to override default tolerance.
+     */
+    public ZipfDistributionTest() {
+        setTolerance(1e-12);
+    }
+    
     @Test(expected=NotStrictlyPositiveException.class)
     public void testPreconditions1() {
         new ZipfDistribution(0, 1);
@@ -56,11 +63,14 @@ public class ZipfDistributionTest extend
         return new int[] {-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
     }
 
-    /** Creates the default probability density test expected values */
+    /** 
+     * Creates the default probability density test expected values.
+     *  Reference values are from R, version 2.15.3 (VGAM package 0.9-0).
+     */
     @Override
     public double[] makeDensityTestValues() {
-        return new double[] {0d, 0d, 0.3414d, 0.1707d, 0.1138d, 0.0854d, 0.0683d,
-                0.0569d, 0.0488d, 0.0427d, 0.0379d, 0.0341d, 0d};
+        return new double[] {0d, 0d, 0.341417152147, 0.170708576074, 0.113805717382, 0.0853542880369, 0.0682834304295,
+            0.0569028586912, 0.0487738788782, 0.0426771440184, 0.0379352391275, 0.0341417152147, 0};
     }
 
     /** Creates the default cumulative probability density test input values */
@@ -72,8 +82,8 @@ public class ZipfDistributionTest extend
     /** Creates the default cumulative probability density test expected values */
     @Override
     public double[] makeCumulativeTestValues() {
-        return new double[] {0d, 0.0000d, 0.3414d, 0.5121d, 0.6259d, 0.7113d,
-                0.7796d, 0.8365d, 0.8852d, 0.9279d, 0.9659d, 1d, 1d};
+        return new double[] {0, 0, 0.341417152147, 0.512125728221, 0.625931445604, 0.71128573364,
+            0.77956916407, 0.836472022761, 0.885245901639, 0.927923045658, 0.965858284785, 1d, 1d};
         }
 
     /** Creates the default inverse cumulative probability test input values */