You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2021/12/20 22:23:52 UTC

[commons-statistics] branch master updated (3043296 -> 35036c2)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git.


    from 3043296  Add JMH benchmarking module
     new 5b9cc0a  STATISTICS-36: Update accuracy of inverse probability function
     new 35036c2  Javadoc mean and variance using abstract methods

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../AbstractContinuousDistribution.java            | 60 +++++++---------------
 .../statistics/distribution/TDistribution.java     | 55 ++++++++++----------
 .../distribution/BetaDistributionTest.java         | 32 +++++++-----
 .../distribution/ChiSquaredDistributionTest.java   |  5 ++
 .../statistics/distribution/FDistributionTest.java |  5 ++
 .../distribution/GammaDistributionTest.java        |  5 ++
 .../distribution/NakagamiDistributionTest.java     |  3 +-
 .../statistics/distribution/TDistributionTest.java |  5 ++
 .../statistics/distribution/test.beta.1.properties |  1 +
 .../distribution/test.beta.10.properties           |  1 +
 .../distribution/test.beta.11.properties           |  1 +
 .../distribution/test.beta.12.properties           |  1 +
 .../distribution/test.beta.13.properties           |  1 +
 .../distribution/test.beta.14.properties           |  1 +
 .../distribution/test.beta.15.properties           |  3 +-
 .../distribution/test.beta.16.properties           |  1 +
 .../distribution/test.beta.17.properties           |  1 +
 .../distribution/test.beta.18.properties           |  1 +
 .../distribution/test.beta.19.properties           |  1 +
 .../statistics/distribution/test.beta.2.properties |  1 +
 .../distribution/test.beta.20.properties           |  1 +
 .../distribution/test.beta.21.properties           |  3 +-
 .../distribution/test.beta.22.properties           |  1 +
 .../distribution/test.beta.23.properties           |  3 +-
 .../distribution/test.beta.24.properties           |  1 +
 .../distribution/test.beta.25.properties           |  1 +
 .../statistics/distribution/test.beta.3.properties |  1 +
 .../statistics/distribution/test.beta.4.properties |  1 +
 .../statistics/distribution/test.beta.5.properties |  3 +-
 .../statistics/distribution/test.beta.6.properties |  1 +
 .../statistics/distribution/test.beta.7.properties |  1 +
 .../statistics/distribution/test.beta.8.properties |  1 +
 .../statistics/distribution/test.beta.9.properties |  1 +
 .../distribution/test.chisquared.1.properties      |  7 ++-
 .../distribution/test.chisquared.2.properties      | 22 ++++----
 .../distribution/test.chisquared.3.properties      | 20 +++++---
 .../distribution/test.chisquared.4.properties      | 21 +++++---
 .../statistics/distribution/test.f.1.properties    |  2 -
 .../statistics/distribution/test.f.2.properties    |  2 -
 .../statistics/distribution/test.f.3.properties    |  2 -
 .../statistics/distribution/test.f.4.properties    |  2 -
 .../statistics/distribution/test.f.5.properties    |  2 -
 .../statistics/distribution/test.f.6.properties    |  6 +--
 .../distribution/test.gamma.1.properties           |  9 +++-
 .../distribution/test.nakagami.1.properties        | 17 ++++++
 .../distribution/test.nakagami.2.properties        | 30 ++++++-----
 .../distribution/test.nakagami.3.properties        | 19 ++++++-
 .../statistics/distribution/test.t.1.properties    | 25 ++++++---
 .../statistics/distribution/test.t.3.properties    |  4 +-
 .../statistics/distribution/test.t.4.properties    | 41 ++++++++++-----
 50 files changed, 260 insertions(+), 174 deletions(-)

[commons-statistics] 01/02: STATISTICS-36: Update accuracy of inverse probability function

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit 5b9cc0a230421ac01ca19c5de8b8cfeb535d7a27
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Dec 20 22:15:43 2021 +0000

    STATISTICS-36: Update accuracy of inverse probability function
    
    Changed the accuracy tolerances used by the BrentSolver. Inversion
    should be accurate to close to 1 ULP.
    
    Update test tolerances for the following distributions using the default
    inverse probability method:
    
    Beta
    ChiSquared
    F
    Gamma
    Nakagami
    T
    
    Fix the Beta distribution sampling test. Extreme parameterisations
    cannot be sampled using uniform expected bins due to low precision of
    values close to 1.
    
    More accurate test tolerances required:
    
    - SF values to be added for beta, chi-squared, gamma and t
    distributions.
    - Log density for F distribution test.
    - Extended precision of the test data for Nakagami(1.5, 2) including SF
    values.
    - Updated T distribution test for infinite degrees of freedom. The
    normal distribution from matlab more closely agrees with the current
    implementation than scipy or R.
---
 .../AbstractContinuousDistribution.java            | 60 +++++++---------------
 .../distribution/BetaDistributionTest.java         | 32 +++++++-----
 .../distribution/ChiSquaredDistributionTest.java   |  5 ++
 .../statistics/distribution/FDistributionTest.java |  5 ++
 .../distribution/GammaDistributionTest.java        |  5 ++
 .../distribution/NakagamiDistributionTest.java     |  3 +-
 .../statistics/distribution/TDistributionTest.java |  5 ++
 .../statistics/distribution/test.beta.1.properties |  1 +
 .../distribution/test.beta.10.properties           |  1 +
 .../distribution/test.beta.11.properties           |  1 +
 .../distribution/test.beta.12.properties           |  1 +
 .../distribution/test.beta.13.properties           |  1 +
 .../distribution/test.beta.14.properties           |  1 +
 .../distribution/test.beta.15.properties           |  3 +-
 .../distribution/test.beta.16.properties           |  1 +
 .../distribution/test.beta.17.properties           |  1 +
 .../distribution/test.beta.18.properties           |  1 +
 .../distribution/test.beta.19.properties           |  1 +
 .../statistics/distribution/test.beta.2.properties |  1 +
 .../distribution/test.beta.20.properties           |  1 +
 .../distribution/test.beta.21.properties           |  3 +-
 .../distribution/test.beta.22.properties           |  1 +
 .../distribution/test.beta.23.properties           |  3 +-
 .../distribution/test.beta.24.properties           |  1 +
 .../distribution/test.beta.25.properties           |  1 +
 .../statistics/distribution/test.beta.3.properties |  1 +
 .../statistics/distribution/test.beta.4.properties |  1 +
 .../statistics/distribution/test.beta.5.properties |  3 +-
 .../statistics/distribution/test.beta.6.properties |  1 +
 .../statistics/distribution/test.beta.7.properties |  1 +
 .../statistics/distribution/test.beta.8.properties |  1 +
 .../statistics/distribution/test.beta.9.properties |  1 +
 .../distribution/test.chisquared.1.properties      |  7 ++-
 .../distribution/test.chisquared.2.properties      | 22 ++++----
 .../distribution/test.chisquared.3.properties      | 20 +++++---
 .../distribution/test.chisquared.4.properties      | 21 +++++---
 .../statistics/distribution/test.f.1.properties    |  2 -
 .../statistics/distribution/test.f.2.properties    |  2 -
 .../statistics/distribution/test.f.3.properties    |  2 -
 .../statistics/distribution/test.f.4.properties    |  2 -
 .../statistics/distribution/test.f.5.properties    |  2 -
 .../statistics/distribution/test.f.6.properties    |  6 +--
 .../distribution/test.gamma.1.properties           |  9 +++-
 .../distribution/test.nakagami.1.properties        | 17 ++++++
 .../distribution/test.nakagami.2.properties        | 30 ++++++-----
 .../distribution/test.nakagami.3.properties        | 19 ++++++-
 .../statistics/distribution/test.t.1.properties    | 25 ++++++---
 .../statistics/distribution/test.t.3.properties    |  4 +-
 .../statistics/distribution/test.t.4.properties    | 41 ++++++++++-----
 49 files changed, 232 insertions(+), 147 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java
index d6670fd..1df9d03 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/AbstractContinuousDistribution.java
@@ -42,51 +42,29 @@ import org.apache.commons.rng.sampling.distribution.InverseTransformContinuousSa
  */
 abstract class AbstractContinuousDistribution
     implements ContinuousDistribution {
-    // XXX Values copied from defaults in class
-    // "o.a.c.math4.analysis.solvers.BaseAbstractUnivariateSolver"
 
-    // Note:
-    // Probability distributions may have very small CDF values.
-    // This creates issues when using the Brent solver.
+    // Notes on the inverse probability implementation:
     //
-    // 1. It cannot identify bracketing if the multiplication of the two
-    // end points creates a signed zero since the condition uses:
-    //   lower * upper < 0
-    // It should be changed to Double.compare(lower * upper, 0.0) < 0.
-    //
-    // 2. Function value accuracy determines if the Brent solver performs a
-    // search. Ideally set to zero to force a search (unless one of the the
-    // initial bracket values is correct). This can result in functions
-    // that evaluate very small p to raise a no-bracket exception due to [1].
-    //
-    // 3. Solver absolute accuracy is the minimum absolute difference between
-    // bracketing points to continue the search. To invert very small probability
-    // values (which map to very small x values) requires a very small absolute
-    // accuracy otherwise the search stops too soon. Set to zero to force
-    // stopping criteria based only on the relative difference between points.
-    //
-    // Note:
     // The Brent solver does not allow a stopping criteria for the proximity
-    // to the root. It is hard coded to 1 ULP (CDF(x) - p == 0). Thus we
-    // search until there is a small relative difference between the upper
-    // and lower bracket of the root.
-
-    // TODO:
-    // Extract the Brent solver code into this class and fix it for the known
-    // issues. These can be transferred back into the original class when the
-    // best solution is known.
-    //
-    // Changes to this class affect many samplers. Altering the accuracy
-    // thresholds can cause any test that uses the inverse CDF to fail. This
-    // includes sampling tests for distributions with use the inverse
-    // transform sampler which have been coded with fixed seeds that work.
+    // to the root; it uses equality to zero within 1 ULP. The search is
+    // iterated until there is a small difference between the upper
+    // and lower bracket of the root, expressed as a combination of relative
+    // and absolute thresholds.
 
-    /** BrentSolver relative accuracy. */
-    private static final double SOLVER_RELATIVE_ACCURACY = 1e-14;
-    /** BrentSolver absolute accuracy. */
-    private static final double SOLVER_ABSOLUTE_ACCURACY = 1e-9;
-    /** BrentSolver function value accuracy. */
-    private static final double SOLVER_FUNCTION_VALUE_ACCURACY = 1e-15;
+    /** BrentSolver relative accuracy.
+     * This is used with {@code tol = 2 * relEps * abs(b) + absEps} so the minimum
+     * non-zero value with an effect is half of machine epsilon (2^-53). */
+    private static final double SOLVER_RELATIVE_ACCURACY = 0x1.0p-53;
+    /** BrentSolver absolute accuracy.
+     * This is used with {@code tol = 2 * relEps * abs(b) + absEps} so set to MIN_VALUE
+     * so that when the relative epsilon has no effect (as b is too small) the tolerance
+     * is at least 1 ULP for sub-normal numbers. */
+    private static final double SOLVER_ABSOLUTE_ACCURACY = Double.MIN_VALUE;
+    /** BrentSolver function value accuracy.
+     * Determines if the Brent solver performs a search. It is not used during the search.
+     * Set to a very low value to search using Brent's method unless
+     * the starting point is correct, or within 1 ULP for sub-normal probabilities. */
+    private static final double SOLVER_FUNCTION_VALUE_ACCURACY = Double.MIN_VALUE;
 
     /** Cached value of the median. */
     private double median = Double.NaN;
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/BetaDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/BetaDistributionTest.java
index e9aef2b..f18c632 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/BetaDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/BetaDistributionTest.java
@@ -47,8 +47,7 @@ class BetaDistributionTest extends BaseContinuousDistributionTest {
 
     @Override
     protected double getRelativeTolerance() {
-        // Limited by the inverse SF mapping
-        return 5e-9;
+        return 5e-14;
     }
 
     @Override
@@ -163,7 +162,8 @@ class BetaDistributionTest extends BaseContinuousDistributionTest {
 
                 final double gT = gTest(betaDistribution, observed);
                 Assertions.assertFalse(gT < level,
-                    () -> "G goodness-of-fit (" + gT + ") test rejected null at alpha = " + level);
+                    () -> String.format("Beta(%s, %s): G goodness-of-fit (%s) test rejected null at alpha = %s",
+                                        alpha, beta, gT, level));
             }
         }
     }
@@ -171,22 +171,30 @@ class BetaDistributionTest extends BaseContinuousDistributionTest {
     private static double gTest(final ContinuousDistribution expectedDistribution, final double[] values) {
         final int numBins = values.length / 30;
         final double[] breaks = new double[numBins];
-        for (int b = 0; b < breaks.length; b++) {
-            breaks[b] = expectedDistribution.inverseCumulativeProbability((double) b / numBins);
+        for (int b = 0; b < numBins; b++) {
+            breaks[b] = expectedDistribution.inverseCumulativeProbability((double) (b + 1) / numBins);
         }
 
         final long[] observed = new long[numBins];
         for (final double value : values) {
-            int b = 0;
-            do {
-                b++;
-            } while (b < numBins && value >= breaks[b]);
-
-            observed[b - 1]++;
+            int b = Arrays.binarySearch(breaks, value);
+            if (b < 0) {
+                b = -(b + 1);
+            }
+            observed[b]++;
         }
 
         final double[] expected = new double[numBins];
-        Arrays.fill(expected, (double) values.length / numBins);
+        // This is not uniform for extreme parameterisations.
+        // E.g. beta(1000, 0.1).cdf(0.9999999999999999) = 0.94676.
+        // This is below the 29/30 = 0.96667 for the penultimate bin.
+        // So fill the expected using the CDF.
+        double x0 = 0;
+        for (int b = 0; b < numBins; b++) {
+            final double x1 = breaks[b];
+            expected[b] = expectedDistribution.probability(x0, x1);
+            x0 = x1;
+        }
 
         return new GTest().gTest(expected, observed);
     }
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ChiSquaredDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ChiSquaredDistributionTest.java
index 89d2472..57daa18 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ChiSquaredDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/ChiSquaredDistributionTest.java
@@ -43,6 +43,11 @@ class ChiSquaredDistributionTest extends BaseContinuousDistributionTest {
         return new String[] {"DegreesOfFreedom"};
     }
 
+    @Override
+    protected double getRelativeTolerance() {
+        return 5e-15;
+    }
+
     //-------------------- Additional test cases -------------------------------
 
     @Test
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/FDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/FDistributionTest.java
index a0230ac..44c57d8 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/FDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/FDistributionTest.java
@@ -46,6 +46,11 @@ class FDistributionTest extends BaseContinuousDistributionTest {
         return new String[] {"NumeratorDegreesOfFreedom", "DenominatorDegreesOfFreedom"};
     }
 
+    @Override
+    protected double getRelativeTolerance() {
+        return 1e-14;
+    }
+
     //-------------------- Additional test cases -------------------------------
 
     @Test
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
index af06961..2bd0d99 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/GammaDistributionTest.java
@@ -55,6 +55,11 @@ class GammaDistributionTest extends BaseContinuousDistributionTest {
         return new String[] {"Shape", "Scale"};
     }
 
+    @Override
+    protected double getRelativeTolerance() {
+        return 1e-15;
+    }
+
     //-------------------- Additional test cases -------------------------------
 
     @Test
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
index 46aefff..d21b34a 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/NakagamiDistributionTest.java
@@ -33,8 +33,7 @@ class NakagamiDistributionTest extends BaseContinuousDistributionTest {
 
     @Override
     protected double getRelativeTolerance() {
-        // Limited by the inverse CDF
-        return 1e-8;
+        return 5e-15;
     }
 
     @Override
diff --git a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java
index eba7d54..ab27303 100644
--- a/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java
+++ b/commons-statistics-distribution/src/test/java/org/apache/commons/statistics/distribution/TDistributionTest.java
@@ -43,6 +43,11 @@ class TDistributionTest extends BaseContinuousDistributionTest {
         return new String[] {"DegreesOfFreedom"};
     }
 
+    @Override
+    protected double getRelativeTolerance() {
+        return 1e-15;
+    }
+
     //-------------------- Additional test cases -------------------------------
 
     /**
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.1.properties
index 07ad349..f034f92 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.1.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.406385093936276 0.439709190223346 0.462804186115552 0.482120045609328 0.500000000000000 0.517879954390672 0.537195813884448 0.560290809776654 0.593614906063724 1 1
 pdf.values = 0  Infinity 0.442988958666524 0.263938762316795 0.206639715373253 0.183240320487425 0.176630277977874 0.183240320487425 0.206639715373253 0.263938762316795 0.442988958666524 Infinity 0
+sf.values = 1 1 0.593614906063724 0.560290809776654 0.537195813884448 0.517879954390672 0.500000000000000 0.482120045609328 0.462804186115552 0.439709190223346 0.406385093936276 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.10.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.10.properties
index 05096b0..fbe8b60 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.10.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.10.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.626625082597741 0.804984471899925 0.898778484206134 0.950264436880598 0.977796095859523 0.991483736629099 0.997455625383593 0.999522385942406 0.999971488851370 1 1
 pdf.values = 0  Inf 2.52142232809988  1.25219806739988  0.684938469046825 0.373544048607390 0.193349510480697 0.0903696114115064  0.0352965948694063  0.00978279740156159 0.00115291373026972 0 0
+sf.values = 1 1 0.373374917402260 0.195015528100075 0.101221515793866 0.0497355631194020  0.0222039041404773  0.00851626337090129 0.00254437461640681 0.000477614057594006  2.85111486302981e-05  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.11.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.11.properties
index d3b2e56..2231ec7 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.11.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.11.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.0104807417937856  0.0220672314570715  0.0350389048801824  0.0497997834943236  0.0669670084631926  0.0875564634445192  0.113431849434787 0.148660077479215 0.205671765275719 1 1
 pdf.values = 0  0.100000000000000 0.109946584245135 0.122241596067866 0.137851585017117 0.158366702750946 0.186606598307362 0.228110884138870 0.295522716855071 0.425669961260392 0.794328234724282 Inf 0
+sf.values = 1 1 0.989519258206214 0.977932768542929 0.964961095119818 0.950200216505676 0.933032991536807 0.912443536555481 0.886568150565213 0.851339922520785 0.794328234724282 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.12.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.12.properties
index 7cf9863..7abc208 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.12.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.12.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.051316701949486218 0.10557280900008409 0.16333997346592444 0.22540333075851654 0.2928932188134527 0.36754446796632401 0.45227744249483381 0.55278640450004213 0.68377223398316211 1 1
 pdf.values = 0 0.5 0.52704627669472992 0.55901699437494745 0.59761430466719689 0.64549722436790291 0.70710678118654768 0.79056941504209488 0.9128709291752769 1.1180339887498951 1.58113883008419 Inf 0
+sf.values = 1 1 0.948683298050514 0.894427190999916 0.836660026534076 0.774596669241483 0.707106781186547 0.632455532033676 0.547722557505166 0.447213595499958 0.316227766016838 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.13.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.13.properties
index 90ab21a..d867bca 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.13.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.13.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0.0, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.0
 pdf.values = 0 1 1 1 1 1 1 1 1 1 1 1 0
+sf.values = 1 1 0.900000000000000 0.800000000000000 0.700000000000000 0.600000000000000 0.500000000000000 0.400000000000000 0.300000000000000 0.200000000000000 0.100000000000000 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.14.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.14.properties
index 70bc714..e238b8b 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.14.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.14.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.19000000000000006 0.35999999999999999 0.51000000000000023 0.64000000000000001 0.75 0.83999999999999997 0.90999999999999992 0.95999999999999996 0.98999999999999999 1 1
 pdf.values = 0 2 1.8 1.6000000000000001 1.3999999999999999 1.2 1 0.80000000000000004 0.60000000000000009 0.39999999999999991 0.19999999999999996 0 0
+sf.values = 1 1 0.810000000000000 0.640000000000000 0.490000000000000 0.360000000000000 0.250000000000000 0.160000000000000 0.0900000000000000  0.0400000000000000  0.0100000000000000  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.15.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.15.properties
index d9509a6..5dc0e16 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.15.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.15.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 1.0 4.0
-# Limited by inverse sf mapping
-tolerance.relative = 5e-8
 # Computed using Matlab
 mean = 0.20000000000000001
 variance = 0.026666666666666672
@@ -24,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.34389999999999987 0.59040000000000026 0.75990000000000002 0.87040000000000006 0.9375 0.97440000000000004 0.9919 0.99839999999999995 0.99990000000000001 1 1
 pdf.values = 0 4 2.9160000000000008 2.0480000000000005 1.3719999999999999 0.8640000000000001 0.50000000000000022 0.25600000000000012 0.10800000000000005 0.031999999999999994 0.0039999999999999983 0 0
+sf.values = 1 1 0.656100000000000 0.409600000000000 0.240100000000000 0.129600000000000 0.0625000000000000  0.0256000000000000  0.00810000000000000 0.00160000000000000 9.99999999999999e-05  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.16.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.16.properties
index 57892ff..1eaf518 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.16.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.16.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.00058554921172346416 0.0025085760862129224 0.0060900720265878658 0.011791774834096561 0.020315358886352223 0.032809851251190306 0.051372078895221711 0.080552883677552423 0.13418222415053294 1 1
 pdf.values = 0 0 0.012094124266964851 0.026893151134930546 0.045491023055648561 0.069681349210416327 0.10263362906904888 0.15055318353165442 0.22755249197840488 0.37458956590914555 0.78638495237703931 Inf 0
+sf.values = 1 1 0.999414450788277 0.997491423913787 0.993909927973412 0.988208225165904 0.979684641113648 0.967190148748810 0.948627921104778 0.919447116322448 0.865817775849467 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.17.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.17.properties
index 469c8fd..bca61be 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.17.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.17.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.0038825370469605129 0.016130089900092535 0.0378409694858131 0.070483996910219962 0.1161165235168156 0.17780780835622126 0.26057454736802566 0.37390096630005898 0.54146973927558506 1 1
 pdf.values = 0 0 0.079056941504209499 0.16770509831248426 0.26892643710023856 0.38729833462074181 0.53033008588991071 0.71151247353788538 0.95851447563404069 1.3416407864998741 2.1345374206136567 Inf 0
+sf.values = 1 1 0.996117462953040 0.983869910099907 0.962159030514187 0.929516003089780 0.883883476483184 0.822192191643779 0.739425452631974 0.626099033699941 0.458530260724415 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.18.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.18.properties
index 23335fe..2a56be7 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.18.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.18.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.010000000000000009 0.040000000000000029 0.089999999999999983 0.16000000000000003 0.25000000000000006 0.35999999999999999 0.48999999999999977 0.64000000000000012 0.81000000000000005 1 1
 pdf.values = 0 0 0.20000000000000007 0.40000000000000002 0.59999999999999987 0.80000000000000004 1 1.2 1.3999999999999999 1.6000000000000001 1.8 2 0
+sf.values = 1 1 0.990000000000000 0.960000000000000 0.910000000000000 0.840000000000000 0.750000000000000 0.640000000000000 0.510000000000000 0.360000000000000 0.190000000000000 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.19.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.19.properties
index 80d4731..e4c3a7b 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.19.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.19.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.028000000000000008 0.10400000000000008 0.2159999999999998 0.35200000000000004 0.5 0.64799999999999991 0.78400000000000003 0.89600000000000002 0.97199999999999998 1 1
 pdf.values = 0 0 0.54000000000000004 0.96000000000000008 1.2599999999999998 1.4400000000000002 1.5 1.4400000000000002 1.26 0.95999999999999985 0.53999999999999981 0 0
+sf.values = 1 1 0.972000000000000 0.896000000000000 0.784000000000000 0.648000000000000 0.500000000000000 0.352000000000000 0.216000000000000 0.104000000000000 0.0280000000000000  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.2.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.2.properties
index c0e1c86..66edffa 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.2.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.2.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.704833622051221 0.759304219445319 0.795176530367368 0.823494838536657 0.848001712399770 0.870603436980005 0.892658587836406 0.915640640375004 0.942366288315790 1 1
 pdf.values = 0  Infinity 0.739458664410644 0.420303655461325 0.311944266317603 0.260079151351645 0.233065049073820 0.221140881157234 0.222272786172717 0.241401058813832 0.307055512274369 Infinity 0
+sf.values = 1 1 0.295166377948779 0.240695780554681 0.204823469632632 0.176505161463343 0.151998287600230 0.129396563019995 0.107341412163595 0.0843593596249964  0.0576337116842096  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.20.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.20.properties
index 32c8053..b2c9d57 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.20.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.20.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.081459999999999991 0.26272000000000001 0.47177999999999987 0.6630400000000003 0.81250000000000011 0.91295999999999999 0.96921999999999997 0.99328000000000005 0.99953999999999998 1 1
 pdf.values = 0 0 1.458 2.0479999999999996 2.0579999999999994 1.7279999999999998 1.25 0.7679999999999999 0.378 0.12799999999999995 0.017999999999999985 0 0
+sf.values = 1 1 0.918540000000000 0.737280000000000 0.528220000000000 0.336960000000000 0.187500000000000 0.0870400000000000  0.0307800000000000  0.00671999999999999 0.000460000000000000  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.21.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.21.properties
index c60ad15..9d87d65 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.21.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.21.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 4.0 0.1
-# Limited by CDF inverse mapping test
-tolerance.relative = 1e-7
 # Computed using Matlab
 mean = 0.97560975609756106
 variance = 0.0046657568440820708
@@ -24,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 3.2171282691062582e-06 5.5920702707254974e-05 0.00031043754736771468 0.0010887195953766145 0.002995933980950227 0.0071555887773963782 0.015771491525200323 0.033804105852091329 0.076500887893677594 1 1
 pdf.values = 0 0 0.00013122124829656863 0.001167162759255986 0.0044421984013840775 0.012096682222928267 0.027839371884979505 0.058806073487464187 0.12097828236031892 0.26011499456731058 0.69111441539656093 Inf 0
+sf.values = 1 1 0.999996782871731 0.999944079297293 0.999689562452632 0.998911280404623 0.997004066019050 0.992844411222604 0.984228508474800 0.966195894147909 0.923499112106322 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.22.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.22.properties
index 9e554fc..19381c2 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.22.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.22.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 2.8511148630298162e-05 0.00047761405759400596 0.002544374616406807 0.0085162633709012919 0.022203904140477276 0.049735563119401985 0.10122151579386635 0.1950155281000755 0.37337491740225981 1 1
 pdf.values = 0 0 0.0011529137302697221 0.0097827974015615871 0.035296594869406304 0.090369611411506442 0.19334951048069668 0.37354404860738988 0.68493846904682498 1.2521980673998829 2.5214223280998826 Inf 0
+sf.values = 1 1 0.999971488851370 0.999522385942406 0.997455625383593 0.991483736629099 0.977796095859523 0.950264436880598 0.898778484206134 0.804984471899925 0.626625082597740 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.23.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.23.properties
index 40ae745..cdc9362 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.23.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.23.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 4.0 1.0
-# Limited by CDF inverse mapping test
-tolerance.relative = 1e-7
 # Computed using Matlab
 mean = 0.80000000000000004
 variance = 0.026666666666666672
@@ -24,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.00010000000000000006 0.0016000000000000007 0.0080999999999999944 0.025600000000000001 0.062500000000000028 0.12959999999999997 0.24009999999999992 0.40960000000000019 0.65610000000000024 1 1
 pdf.values = 0 0 0.0040000000000000018 0.032000000000000021 0.10799999999999996 0.25600000000000012 0.50000000000000022 0.8640000000000001 1.3719999999999999 2.0480000000000005 2.9160000000000008 4 0
+sf.values = 1 1 0.999900000000000 0.998400000000000 0.991900000000000 0.974400000000000 0.937500000000000 0.870400000000000 0.759900000000000 0.590400000000000 0.343900000000000 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.24.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.24.properties
index cd0a91b..d782b4e 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.24.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.24.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.00046000000000000056 0.0067200000000000037 0.030779999999999971 0.087040000000000006 0.18749999999999992 0.33695999999999976 0.52822000000000002 0.73728000000000005 0.91854000000000002 1 1
 pdf.values = 0 0 0.018000000000000016 0.12800000000000006 0.37799999999999967 0.7679999999999999 1.25 1.7279999999999998 2.0579999999999994 2.0479999999999996 1.4579999999999993 0 0
+sf.values = 1 1 0.999540000000000 0.993280000000000 0.969220000000000 0.912960000000000 0.812500000000000 0.663040000000000 0.471780000000000 0.262720000000000 0.0814600000000000  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.25.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.25.properties
index bf8b88b..8211a13 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.25.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.25.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0 0 0.0027280000000000021 0.033344000000000061 0.12603599999999995 0.28979200000000022 0.49999999999999967 0.71020799999999973 0.87396399999999996 0.96665599999999996 0.99727200000000005 1 1
 pdf.values = 0 0 0.10206000000000011 0.57344000000000062 1.2965399999999996 1.9353600000000017 2.1875000000000018 1.9353600000000017 1.2965400000000007 0.57344000000000017 0.10206000000000001 0 0
+sf.values = 1 1 0.997272000000000 0.966656000000000 0.873964000000000 0.710208000000000 0.500000000000000 0.289792000000000 0.126036000000000 0.0333440000000000  0.00272800000000000 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.3.properties
index 5e80d84..f0a3f7d 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.3.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.794328234724282 0.851339922520785 0.886568150565213 0.912443536555481 0.933032991536807 0.950200216505676 0.964961095119818 0.977932768542929 0.989519258206214 1 1
 pdf.values = 0  Infinity 0.794328234724282 0.425669961260392 0.295522716855071 0.228110884138870 0.186606598307362 0.158366702750946 0.137851585017117 0.122241596067866 0.109946584245135 0.100000000000000 0
+sf.values = 1 1 0.205671765275719 0.148660077479215 0.113431849434787 0.0875564634445192  0.0669670084631926  0.0497997834943236  0.0350389048801824  0.0220672314570715  0.0104807417937856  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.4.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.4.properties
index 842b234..f0ba541 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.4.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.4.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.865817775849467 0.919447116322448 0.948627921104778 0.967190148748810 0.979684641113648 0.988208225165904 0.993909927973412 0.997491423913787 0.999414450788277 1 1
 pdf.values = 0  Infinity 0.786384952377039 0.374589565909146 0.227552491978405 0.150553183531654 0.102633629069049 0.0696813492104163  0.0454910230556486  0.0268931511349305  0.0120941242669649  0 0
+sf.values = 1 1 0.134182224150533 0.0805528836775524  0.0513720788952217  0.0328098512511903  0.0203153588863522  0.0117917748340966  0.00609007202658787 0.00250857608621292 0.000585549211723463  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.5.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.5.properties
index baa8be7..9194496 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.5.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.5.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 0.1 4.0
-# Limited by inverse sf mapping
-tolerance.relative = 5e-8
 # Computed using Matlab
 mean = 0.024390243902439
 variance = 0.004665756844082
@@ -24,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.923499112106323 0.966195894147909 0.984228508474800 0.992844411222604 0.997004066019050 0.998911280404623 0.999689562452632 0.999944079297293 0.999996782871731 1 1
 pdf.values = 0  Infinity 0.691114415396561 0.260114994567311 0.120978282360319 0.0588060734874642  0.0278393718849795  0.0120966822229283  0.00444219840138409 0.00116716275925599 0.000131221248296568  0 0
+sf.values = 1 1 0.0765008878936770  0.0338041058520913  0.0157714915252003  0.00715558877739638 0.00299593398095023 0.00108871959537661 0.000310437547367715  5.59207027072550e-05  3.21712826910625e-06  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.6.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.6.properties
index ff7bed5..aeaacde 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.6.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.6.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.0576337116842096  0.0843593596249964  0.107341412163594 0.129396563019995 0.151998287600230 0.176505161463343 0.204823469632632 0.240695780554681 0.295166377948779 1 1
 pdf.values = 0  Infinity 0.307055512274369 0.241401058813832 0.222272786172717 0.221140881157234 0.233065049073820 0.260079151351645 0.311944266317603 0.420303655461325 0.739458664410645 Infinity 0
+sf.values = 1 1 0.942366288315790 0.915640640375004 0.892658587836406 0.870603436980005 0.848001712399770 0.823494838536657 0.795176530367368 0.759304219445319 0.704833622051221 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.7.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.7.properties
index 75ea975..d4c3cc0 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.7.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.7.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.204832764699133 0.295167235300867 0.369010119565545 0.435905783151025 0.500000000000000 0.564094216848975 0.630989880434455 0.704832764699133 0.795167235300867 1 1
 pdf.values = 0  Infinity 1.06103295394597  0.795774715459477 0.694609118042857 0.649747334361397 0.636619772367582 0.649747334361397 0.694609118042857 0.795774715459477 1.06103295394597  Infinity 0
+sf.values = 1 1 0.795167235300867 0.704832764699133 0.630989880434455 0.564094216848975 0.500000000000000 0.435905783151025 0.369010119565545 0.295167235300867 0.204832764699133 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.8.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.8.properties
index 6081a60..5f1c437 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.8.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.8.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.316227766016838 0.447213595499958 0.547722557505166 0.632455532033676 0.707106781186547 0.774596669241483 0.836660026534075 0.894427190999916 0.948683298050514 1 1
 pdf.values = 0  Infinity 1.58113883008419  1.11803398874990  0.912870929175277 0.790569415042095 0.707106781186548 0.645497224367903 0.597614304667197 0.559016994374948 0.527046276694730 0.500000000000000 0
+sf.values = 1 1 0.683772233983162 0.552786404500042 0.452277442494834 0.367544467966324 0.292893218813453 0.225403330758517 0.163339973465925 0.105572809000084 0.0513167019494862  0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.9.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.9.properties
index c580a5a..4f096f6 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.9.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.beta.9.properties
@@ -22,3 +22,4 @@ upper = 1
 cdf.points = -0.1, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1
 cdf.values = 0  0 0.458530260724415 0.626099033699941 0.739425452631974 0.822192191643779 0.883883476483184 0.929516003089780 0.962159030514187 0.983869910099907 0.996117462953040 1 1
 pdf.values = 0  Inf 2.13453742061366  1.34164078649987  0.958514475634041 0.711512473537885 0.530330085889911 0.387298334620742 0.268926437100239 0.167705098312484 0.0790569415042095  0 0
+sf.values = 1 1 0.541469739275585 0.373900966300059 0.260574547368026 0.177807808356221 0.116116523516816 0.0704839969102200  0.0378409694858131  0.0161300899000925  0.00388253704696051 0 0
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.1.properties
index 68a8e26..8f1c73e 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.1.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 5.0
-# Limited by the CDF inverse mapping.
-tolerance.relative = 1e-9
 mean = 5
 variance = 10
 lower = 0
@@ -37,6 +35,11 @@ pdf.values = \
   0.00043363007636076326013 0.00412780610309495914201 \
   0.00999340341044542557203 0.01932464389366777765544 \
   0.03684600892155488055524 0.0
+sf.values = \
+  1.0000000000000000000000 0.9990000000000024416025 0.9900000000000115374377 \
+  0.9749999999999774402681 0.9500000000001627142865 0.9000000000002820188527 \
+  0.0010000000000142579299 0.0099999999999545435142 0.0250000000003000877324 \
+  0.0500000000003160416373 0.1000000000000411948253 0.0000000000000000000000
 # Created using WolframAlpha
 cdf.hp.points = 1e-7, 4e-7, 9e-8
 cdf.hp.values = 1.6820882879388572e-19, 5.382681944688393e-18, 1.292572946953654e-19
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.2.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.2.properties
index 78a1d39..3edd20f 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.2.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.2.properties
@@ -24,19 +24,19 @@ cdf.points = \
   5.4729171974573481e+00 2.1752548001836174e+00 1.1343475235077167e+00 \
   5.3186460485168197e-01 1.5263422781837696e-01                    Inf
 cdf.values = \
-  0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900, 1
+  0.0000000000000000000000 0.0010000000000000000208 0.0100000000000000054123 \
+  0.0250000000000000048572 0.0500000000000000166533 0.1000000000000000471845 \
+  0.9989999999999999991118 0.9899999999999999911182 0.9749999999999998667732 \
+  0.9499999999999998445688 0.9000000000000000222045 1.0000000000000000000000
 pdf.values = \
   Inf 4.2774292299259904e+55 4.2774292299259657e+36 \
   1.1757707938231455e+29 2.2426048160994400e+23 4.2774292299259878e+17 \
   6.3950485031051161e-04 7.9908952673546779e-03 2.4960391325813031e-02 \
   6.9275023117637585e-02 2.7413671677094120e-01 0.0000000000000000e+00
-
-# TODO: Sampling test fails
-# The sampler is OK. The inverse CDF to generate the quartiles fails.
-disable.sample = true
-
-# TODO: CDF inverse test fails
-disable.cdf.inverse = true
-
-# TODO: SF inverse test fails
-disable.sf.inverse = true
+sf.values = \
+  1.00000000000000000000000 0.99899999999999999911182 \
+  0.98999999999999999111822 0.97499999999999997779554 \
+  0.94999999999999995559108 0.90000000000000002220446 \
+  0.00099999999999999980398 0.00999999999999998979983 \
+  0.02500000000000001873501 0.05000000000000005134781 \
+  0.09999999999999997779554 0.00000000000000000000000
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.3.properties
index 26d6a85..f4360de 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.3.properties
@@ -14,21 +14,27 @@
 # limitations under the License.
 
 parameters = 2.0
-# Limited by CDF inverse mapping test
-tolerance.relative = 1.5e-8
 mean = 2.0
 variance = 4.0
 lower = 0
 # Computed with R version 1.8.1 (linux version)
 cdf.points = \
-   0.000000000000000000  0.002001000667167067  0.020100671707002884 \
-   0.050635615968579753  0.102586588775101073  0.210721031315652618 \
-   13.815510557964271854 9.210340371976181828  7.377758908227870727 \
-   5.991464547107979932  4.605170185988091802                   Inf
+  0.000000000000000000,  0.002001000667167067,  0.020100671707002884 \
+  0.050635615968579753,  0.102586588775101073,  0.210721031315652618 \
+  13.815510557964271854, 9.210340371976181828,  7.377758908227870727 \
+  5.991464547107979932,  4.605170185988091802,                   Inf
 cdf.values = \
-  0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900, 1
+  0.0000000000000000000000 0.0010000000000000000208 0.0100000000000000002082 \
+  0.0250000000000000013878 0.0500000000000000027756 0.1000000000000000055511 \
+  0.9989999999999999991118 0.9899999999999999911182 0.9749999999999999777955 \
+  0.9499999999999999555911 0.9000000000000000222045 1.0000000000000000000000
 pdf.values = \
   0.5 0.49949999999999999956 0.49499999999999999556 \
   0.48749999999999998890 0.47499999999999997780 0.45000000000000001110 \
   0.00050000000000000055 0.00500000000000000184 0.01250000000000001110 \
   0.02500000000000002567 0.04999999999999998890 0.00000000000000000000
+sf.values = \
+  1.000000000000000000000 0.998999999999999999112 0.989999999999999991118 \
+  0.975000000000000088818 0.950000000000000066613 0.900000000000000022204 \
+  0.001000000000000001105 0.010000000000000003678 0.025000000000000022204 \
+  0.050000000000000051348 0.099999999999999977796 0.000000000000000000000
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.4.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.4.properties
index 81fb55c..a5e5d44 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.4.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.chisquared.4.properties
@@ -14,22 +14,27 @@
 # limitations under the License.
 
 parameters = 1.0
-# TODO: Limited by the CDF inverse mapping.
-tolerance.relative = 5e-7
-tolerance.absolute = 2e-10
 mean = 1.0
 variance = 2.0
 lower = 0
 # Computed with R version 1.8.1 (linux version)
 cdf.points = \
-  0.0000000000000000e+00 1.5707971492624904e-06 1.5708785790970206e-04 \
-  9.8206911717525617e-04 3.9321400000195249e-03 1.5790774093431229e-02 \
-  1.0827566170662729e+01 6.6348966010212127e+00 5.0238861873148846e+00 \
-  3.8414588206941240e+00 2.7055434540954155e+00                    Inf
+  0.0000000000000000e+00, 1.5707971492624904e-06, 1.5708785790970206e-04 \
+  9.8206911717525617e-04, 3.9321400000195249e-03, 1.5790774093431229e-02 \
+  1.0827566170662729e+01, 6.6348966010212127e+00, 5.0238861873148846e+00 \
+  3.8414588206941240e+00, 2.7055434540954155e+00,                    Inf
 cdf.values = \
-  0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999, 0.990, 0.975, 0.950, 0.900, 1
+  0.0000000000000000000000 0.0010000000000000000208 0.0100000000000000002082 \
+  0.0250000000000000013878 0.0500000000000000027756 0.1000000000000000194289 \
+  0.9989999999999999991118 0.9899999999999999911182 0.9749999999999999777955 \
+  0.9500000000000000666134 0.8999999999999999111822 1.0000000000000000000000
 pdf.values = \
                      Inf 3.1830955285046593e+02 3.1827655293772658e+01 \
   1.2724062250397644e+01 6.3495321486567917e+00 3.1497742813794667e+00 \
   5.4009296746280165e-04 5.6136262628098937e-03 1.4436673856220024e-02 \
   2.9819461105429837e-02 6.2702017179802227e-02 0.0000000000000000e+00
+sf.values = \
+  1.0000000000000000000000 0.9989999999999999991118 0.9899999999999999911182 \
+  0.9750000000000000888178 0.9499999999999999555911 0.9000000000000000222045 \
+  0.0010000000000000017555 0.0100000000000000227596 0.0250000000000000222045 \
+  0.0499999999999999819589 0.1000000000000001026956 0.0000000000000000000000
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.1.properties
index b942156..7a93d9c 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.1.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 5.0 6.0
-# Limited by CDF inverse mapping
-tolerance.relative = 1e-7
 # Computed using R 2.9.2
 mean = 1.5
 variance = 4.05
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.2.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.2.properties
index d32a86f..2aaaff9 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.2.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.2.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 1.0 2.0
-# Limited by the CDF inverse mapping.
-tolerance.relative = 1e-9
 # Computed using scipy.stats f
 mean = NaN
 variance = NaN
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.3.properties
index 80aaa3e..1f7fa43 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.3.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 2.0 1.0
-# Limited by CDF inverse mapping
-tolerance.relative = 1e-8
 # Computed using scipy.stats f
 mean = NaN
 variance = NaN
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.4.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.4.properties
index 2552811..9b66af5 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.4.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.4.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 5.0 2.0
-# Limited by CDF inverse mapping
-tolerance.relative = 1e-7
 # Computed using scipy.stats f
 mean = NaN
 variance = NaN
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.5.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.5.properties
index 7791cad..3c4125c 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.5.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.5.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 10.0 1.0
-# Limited by CDF inverse mapping
-tolerance.relative = 1e-7
 # Computed using scipy.stats f
 mean = NaN
 variance = NaN
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.6.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.6.properties
index e06f368..ed0ee31 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.6.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.f.6.properties
@@ -14,8 +14,8 @@
 # limitations under the License.
 
 parameters = 100.0 100.0
-# Limited by inverse sf mapping
-tolerance.relative = 5e-9
+# Limited by logpdf values
+tolerance.relative = 6e-13
 # Computed using scipy.stats f
 mean = 1.0204081632653061
 variance = 0.04295085381091212
@@ -72,5 +72,3 @@ sf.values = \
   1.3286199631860416e-11, 2.0324013825740018e-12,\
   3.2917389024730059e-13, 5.6335109943945702e-14,\
   1.0165268915392895e-14
-# TODO: CDF inverse test fails for x=0.01
-disable.cdf.inverse = true
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.gamma.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.gamma.1.properties
index 46c8707..1ef2a72 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.gamma.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.gamma.1.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 4.0 2.0
-# Limited by the CDF inverse mapping.
-tolerance.relative = 5e-11
 # Computed using R 2.9.2 gamma(4, 0.5) using rate = 1/scale
 mean = 8
 variance = 16
@@ -35,6 +33,13 @@ pdf.values = \
   0.00039446885281587437504 0.00366559696760836075530 \
   0.00874649473311463546144 0.01667125081284889440147 \
   0.03117982279541961151970, 0.0
+sf.values = \
+  1.00000000000000000000000 0.99899999999999933297801 \
+  0.99000000000001575628517 0.97500000000009612310947 \
+  0.94999999999998163691117 0.89999999999998636646126 \
+  0.00099999999999058871228 0.00999999999986522260242 \
+  0.02499999999986575460742 0.04999999999942410233711 \
+  0.10000000000036562974870 0.00000000000000000000000
 # Computed using WolframAlpha
 cdf.hp.points = 1e-4, 9e-5
 cdf.hp.values = 2.6040625021701086e-19, 1.7085322417782863e-19
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties
index 0b020d4..7cfb3a6 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.1.properties
@@ -28,11 +28,28 @@ cdf.values = \
   6.82689492137085852e-01, 7.69860659556583560e-01,\
   8.38486681532458089e-01, 8.90401416600884343e-01,\
   9.28139361774148575e-01, 9.54499736103641472e-01
+# pdf adjusted to return 0 for x=0.
+# scioy and matlab compute a value.
+# WolframAlpha returns zero.
 pdf.values = \
   0.0,                 0.79788416186068489, 0.78208538795091187,\
   0.73654028060664678, 0.66644920578359934, 0.57938310552296557,\
   0.48394144903828679, 0.38837210996642596, 0.29945493127148981,\
   0.22184166935891111, 0.15790031660178833, 0.10798193302637614,
+logpdf.values = \
+  -inf,                    -0.22579185264472717565,\
+  -0.24579135264472729006, -0.30579135264472723232,\
+  -0.40579135264472732114, -0.54579135264472722344,\
+  -0.72579135264472727229, -0.94579135264472724565,\
+  -1.20579135264472703248, -1.50579135264472752098,\
+  -1.84579135264472737887, -2.22579135264472727229
+sf.values = \
+  1.                    ,  0.99920211557217786247,\
+  0.84148058112179402457,  0.68915651677935163555,\
+  0.54850623550014709906,  0.42371079716679338478,\
+  0.31731050786291403742,  0.23013934044341644025,\
+  0.16151331846754191091,  0.10959858339911565661,\
+  0.07186063822585142535,  0.04550026389635852819
 # Computed using WolframAlpha
 cdf.hp.points = 1e-16, 4e-17
 cdf.hp.values = 7.978845608028653e-17, 3.1915382432114614e-17
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties
index 741643a..eacb7ab 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.2.properties
@@ -21,18 +21,20 @@ lower = 0
 upper = Infinity
 cdf.points = 0, 1e-3, 0.2, 0.4, 0.6, 0.8, 1, 1.2, 1.4, 1.6, 1.8, 2
 cdf.values = \
-  0.0,               4.886022920318481e-10,\
-  0.003839209349952, 0.029112642643164,\
-  0.089980307387723, 0.189070530913232,\
-  0.317729669663787, 0.460129965238200,\
-  0.599031192110653, 0.720732382881390,\
-  0.817659600745483, 0.888389774905287,
+  0 4.88602292031848e-10  0.00383920934995174 0.0291126426431637 \
+  0.0899803073877229  0.189070530913232 0.317729669663787 \
+  0.460129965238200 0.599031192110653 0.720732382881390 \
+  0.817659600745483 0.888389774905288
+# pdf adjusted to return 0 for x=0.
+# scioy and matlab compute a value.
+# WolframAlpha returns zero.
 pdf.values = \
-  0.0,               0.000001465806436,\
-  0.056899455042812, 0.208008745554258,\
-  0.402828269545621, 0.580491109555755,\
-  0.692398452624549, 0.716805620039994,\
-  0.660571957322857, 0.550137830087772,\
-  0.418105970486118, 0.291913039977849,
-
-disable.cdf.inverse = true
+  0 1.46580643635352e-06  0.0568994550428125  0.208008745554258 \
+  0.402828269545621 0.580491109555755 0.692398452624549 \
+  0.716805620039994 0.660571957322858 0.550137830087772 \
+  0.418105970486118 0.291913039977849
+sf.values = \
+  1 0.999999999511398 0.996160790650048 0.970887357356836 \
+  0.910019692612277 0.810929469086768 0.682270330336213 \
+  0.539870034761800 0.400968807889347 0.279267617118610 \
+  0.182340399254517 0.111610225094713
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties
index 30a96ec..21d4db9 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.nakagami.3.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 0.3333333333333333333 1.0
-# Required to pass the CDF inverse mapping test
-tolerance.relative = 1e-7
 # Computed using matlab
 mean = 0.729810132407137
 variance = 0.467377170635876
@@ -28,8 +26,25 @@ cdf.values = \
   0.41599060641445568, 0.53633771818837206, 0.63551561797542433,\
   0.71746556659624028, 0.7845448997061909,  0.83861986211366601,\
   0.88141004735798412, 0.91458032800205946, 0.93973541101651015
+# pdf adjusted to return 0 for x=0.
+# scioy and matlab compute a value.
+# WolframAlpha returns zero.
 pdf.values = \
   0.0,                 5.17638635039373352, 0.8734262427029803,\
   0.66605658341650675, 0.54432849968092045, 0.45048535438453824,\
   0.3709044132031733,  0.30141976583757241, 0.24075672187548078,\
   0.18853365020699897, 0.14451001716499515, 0.10829893529327907
+logpdf.values = \
+                     -inf,  1.64410719707018770919,\
+  -0.13533159177915807247, -0.40638065196580652749,\
+  -0.60820235466852801132, -0.79742971215245506134,\
+  -0.99181089592385818232, -1.19925141485517627871,\
+  -1.42396830813092911683, -1.66847877233910368844,\
+  -1.93440645089123131051, -2.22285995611050690712
+sf.values = \
+  1.                    ,  0.99223541853326424622,\
+  0.73533681536286321645,  0.58400939358554437852,\
+  0.46366228181162794098,  0.36448438202457567048,\
+  0.28253443340375983261,  0.21545510029380909867,\
+  0.16138013788633398526,  0.11858995264201588338,\
+  0.08541967199794076038,  0.06026458898348985294
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.1.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.1.properties
index cb02c2d..dd00c9a 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.1.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.1.properties
@@ -14,24 +14,33 @@
 # limitations under the License.
 
 parameters = 5.0
+# Limited by SF
+tolerance.relative = 2e-15
 # Computed using R version 2.9.2
 mean = 0.0
 variance = 1.666666666666667
-# Limited by CDF inverse mapping test
-tolerance.absolute = 1e-8
 cdf.points = \
-                 -Inf -5.8934295313560101 -3.3649299989072183 \
-  -2.5705818356363150 -2.0150483733330233 -1.4758840488244802 \
-   5.8934295313560083  3.3649299989072174  2.5705818356363137 \
-   2.0150483733330224  1.4758840488244804                 Inf
+                 -Inf, -5.8934295313560101, -3.3649299989072183, \
+  -2.5705818356363150, -2.0150483733330233, -1.4758840488244802, \
+   5.8934295313560083,  3.3649299989072174,  2.5705818356363137, \
+   2.0150483733330224,  1.4758840488244804,                 Inf
 cdf.values = \
-  0.0, 0.001, 0.01, 0.025, 0.05, 0.1, 0.999,\
-  0.990, 0.975, 0.950, 0.900, 1.0
+  0.00000000000000000000000 0.00099999999999999915345 \
+  0.01000000000000000194289 0.02499999999999999097944 \
+  0.05000000000000000971445 0.10000000000000000555112 \
+  0.99899999999999999911182 0.98999999999999999111822 \
+  0.97499999999999997779554 0.94999999999999995559108 \
+  0.90000000000000002220446 1.00000000000000000000000
 pdf.values = \
   0.00000000000000000000 0.00075649456551990285 0.01091097529195102916 \
   0.03033778780070596481 0.06379679889497483214 0.12828949200431755129 \
   0.00075649456551990513 0.01091097529195104131 0.03033778780070600645 \
   0.06379679889497488765 0.12828949200431755129 0.00000000000000000000
+sf.values = \
+  1.0000000000000000000000 0.9989999999999999991118 0.9899999999999999911182 \
+  0.9750000000000000888178 0.9499999999999999555911 0.9000000000000000222045 \
+  0.0010000000000000000208 0.0100000000000000140860 0.0250000000000000395517 \
+  0.0500000000000000652256 0.0999999999999999500400 0.0000000000000000000000
 # Computed using WolframAlpha
 cdf.hp.points = -4200, -6400
 cdf.hp.values = 7.261513520181652e-18, 8.838404680725267e-19
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.3.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.3.properties
index 33bc48e..3598897 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.3.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.3.properties
@@ -14,8 +14,6 @@
 # limitations under the License.
 
 parameters = 2.0
-# Limited by sf inverse mapping
-tolerance.relative = 5e-11
 # Computed using scipy stats
 mean = 0
 variance = Infinity
@@ -30,6 +28,6 @@ pdf.values = \
   0.19245008972987523,  0.06804138174397717,  0.02741012223434215,\
   0.0130945700219731 ,  0.00712778110110649
 sf.values = \
-0.90824829046386302,  0.78867513459481287,  0.5                ,\
+  0.90824829046386302,  0.78867513459481287,  0.5                ,\
   0.21132486540518713,  0.09175170953613696,  0.04773298313335456,\
   0.02859547920896831,  0.01887477567531186
diff --git a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.4.properties b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.4.properties
index a44fda5..b120527 100644
--- a/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.4.properties
+++ b/commons-statistics-distribution/src/test/resources/org/apache/commons/statistics/distribution/test.t.4.properties
@@ -15,22 +15,37 @@
 
 # Special case for large degrees of freedom is the standard normal distribution
 parameters = Infinity
+# Limited by inverse mapping test
+tolerance.relative = 2e-15
 mean = 0
 variance = 1
-# normal(0, 1) computed using R
+# normcdf/normpdf/normpdf('upper') computed using matlab
 cdf.points = \
   -2, -1, 0, 1, 2, 3, 4, 5
 cdf.values = \
-  0.022750131948179212055 0.158655253931457046468 0.500000000000000000000 \
-  0.841344746068542925777 0.977249868051820791415 0.998650101968369896532 \
-  0.999968328758166880021 0.999999713348428076465
+  0.022750131948179219 \
+  0.15865525393145707 \
+  0.5 \
+  0.84134474606854293 \
+  0.97724986805182079 \
+  0.9986501019683699 \
+  0.99996832875816688 \
+  0.99999971334842808
 pdf.values = \
-  5.3990966513188062836e-02 2.4197072451914336533e-01 \
-  3.9894228040143270286e-01 2.4197072451914336533e-01 \
-  5.3990966513188062836e-02 4.4318484119380075273e-03 \
-  1.3383022576488536764e-04 1.4867195147342976779e-06
-sf.values =  \
-  9.7724986805182079141e-01 8.4134474606854292578e-01 \
-  5.0000000000000000000e-01 1.5865525393145704647e-01 \
-  2.2750131948179212055e-02 1.3498980316300945772e-03 \
-  3.1671241833119924327e-05 2.8665157187919391185e-07
+  0.053990966513188063 \
+  0.24197072451914337 \
+  0.3989422804014327 \
+  0.24197072451914337 \
+  0.053990966513188063 \
+  0.0044318484119380075 \
+  0.00013383022576488537 \
+  1.4867195147342979e-06
+sf.values = \
+  0.97724986805182079 \
+  0.84134474606854293 \
+  0.5 \
+  0.15865525393145707 \
+  0.022750131948179219 \
+  0.0013498980316300957 \
+  3.1671241833119965e-05 \
+  2.866515718791946e-07

[commons-statistics] 02/02: Javadoc mean and variance using abstract methods

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-statistics.git

commit 35036c2e1dda9b990ff2804e35607ba4b5e62c88
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Mon Dec 20 22:22:30 2021 +0000

    Javadoc mean and variance using abstract methods
---
 .../statistics/distribution/TDistribution.java     | 55 +++++++++++-----------
 1 file changed, 28 insertions(+), 27 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
index c7143d5..0ce37a1 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/TDistribution.java
@@ -151,20 +151,17 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
             }
         }
 
-        /** {@inheritDoc} */
         @Override
         public double density(double x) {
             return Math.exp(logDensity(x));
         }
 
-        /** {@inheritDoc} */
         @Override
         public double logDensity(double x) {
             final double nPlus1Over2 = dofOver2 + 0.5;
             return factor - nPlus1Over2 * Math.log1p(x * x / getDegreesOfFreedom());
         }
 
-        /** {@inheritDoc} */
         @Override
         public double cumulativeProbability(double x) {
             if (x == 0) {
@@ -202,40 +199,16 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
                 1 - 0.5 * p;
         }
 
-        /**
-         * {@inheritDoc}
-         *
-         * <p>For degrees of freedom parameter {@code df}, the mean is
-         * <ul>
-         *  <li>zero if {@code df > 1}, and</li>
-         *  <li>undefined ({@code NaN}) otherwise.</li>
-         * </ul>
-         *
-         * @return the mean, or {@code NaN} if it is not defined.
-         */
         @Override
         public double getMean() {
             return mean;
         }
 
-        /**
-         * {@inheritDoc}
-         *
-         * <p>For degrees of freedom parameter {@code df}, the variance is
-         * <ul>
-         *  <li>{@code df / (df - 2)} if {@code df > 2},</li>
-         *  <li>positive infinity if {@code 1 < df <= 2}, and</li>
-         *  <li>undefined ({@code NaN}) otherwise.</li>
-         * </ul>
-         *
-         * @return the mean, or {@code NaN} if it is not defined.
-         */
         @Override
         public double getVariance() {
             return variance;
         }
 
-        /** {@inheritDoc} */
         @Override
         double getMedian() {
             // Overridden for the probability(double, double) method.
@@ -294,6 +267,34 @@ public abstract class TDistribution extends AbstractContinuousDistribution {
         // Exploit symmetry
         return -inverseCumulativeProbability(p);
     }
+    /**
+     * {@inheritDoc}
+     *
+     * <p>For degrees of freedom parameter {@code df}, the mean is
+     * <ul>
+     *  <li>zero if {@code df > 1}, and</li>
+     *  <li>undefined ({@code NaN}) otherwise.</li>
+     * </ul>
+     *
+     * @return the mean, or {@code NaN} if it is not defined.
+     */
+    @Override
+    public abstract double getMean();
+
+    /**
+     * {@inheritDoc}
+     *
+     * <p>For degrees of freedom parameter {@code df}, the variance is
+     * <ul>
+     *  <li>{@code df / (df - 2)} if {@code df > 2},</li>
+     *  <li>positive infinity if {@code 1 < df <= 2}, and</li>
+     *  <li>undefined ({@code NaN}) otherwise.</li>
+     * </ul>
+     *
+     * @return the variance, or {@code NaN} if it is not defined.
+     */
+    @Override
+    public abstract double getVariance();
 
     /**
      * {@inheritDoc}