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


The following commit(s) were added to refs/heads/master by this push:
     new c6e4a25  Update test tolerances.
c6e4a25 is described below

commit c6e4a254f9b802bfbc97f23e30703703155a197b
Author: Alex Herbert <aherb...@apache.org>
AuthorDate: Sat Oct 14 07:39:10 2023 +0100

    Update test tolerances.
    
    Random order tests pass at 5000 permutations.
---
 .../descriptive/BaseDoubleStatisticTest.java       | 29 ++++++++++++++--------
 .../commons/statistics/descriptive/MeanTest.java   |  7 +++---
 .../statistics/descriptive/ProductTest.java        |  2 +-
 .../statistics/descriptive/SkewnessTest.java       |  2 +-
 .../descriptive/SumOfFourthDeviationsTest.java     |  8 +++---
 .../statistics/descriptive/VarianceTest.java       |  6 ++---
 6 files changed, 31 insertions(+), 23 deletions(-)

diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
index de02458..d57870f 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseDoubleStatisticTest.java
@@ -1127,12 +1127,13 @@ abstract class BaseDoubleStatisticTest<S extends 
DoubleStatistic & DoubleStatist
         // Obtain a seed so that it can be logged to allow repeats
         final long[] seed = TestHelper.createRNGSeed();
         final UniformRandomProvider rng = TestHelper.createRNG(seed);
+        int repeat = 0;
         try {
-            for (int i = 1; i <= RANDOM_PERMUTATIONS; i++) {
+            while (repeat++ < RANDOM_PERMUTATIONS) {
                 testAccept(TestHelper.shuffle(rng, values), expected, tol);
             }
         } catch (AssertionError e) {
-            rethrowWithSeed(e, seed);
+            rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
 
@@ -1146,12 +1147,13 @@ abstract class BaseDoubleStatisticTest<S extends 
DoubleStatistic & DoubleStatist
         // Obtain a seed so that it can be logged to allow repeats
         final long[] seed = TestHelper.createRNGSeed();
         final UniformRandomProvider rng = TestHelper.createRNG(seed);
+        int repeat = 0;
         try {
-            for (int i = 1; i <= RANDOM_PERMUTATIONS; i++) {
+            while (repeat++ < RANDOM_PERMUTATIONS) {
                 testArray(TestHelper.shuffle(rng, values), expected, tol);
             }
         } catch (AssertionError e) {
-            rethrowWithSeed(e, seed);
+            rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
 
@@ -1166,14 +1168,15 @@ abstract class BaseDoubleStatisticTest<S extends 
DoubleStatistic & DoubleStatist
         final long[] seed = TestHelper.createRNGSeed();
         final UniformRandomProvider rng = TestHelper.createRNG(seed);
         final double[] allValues = TestHelper.concatenate(values);
+        int repeat = 0;
         try {
-            for (int i = 1; i <= RANDOM_PERMUTATIONS; i++) {
+            while (repeat++ < RANDOM_PERMUTATIONS) {
                 TestHelper.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
                 testAcceptAndCombine(TestHelper.shuffle(rng, values), 
expected, tol);
             }
         } catch (AssertionError e) {
-            rethrowWithSeed(e, seed);
+            rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
 
@@ -1188,14 +1191,15 @@ abstract class BaseDoubleStatisticTest<S extends 
DoubleStatistic & DoubleStatist
         final long[] seed = TestHelper.createRNGSeed();
         final UniformRandomProvider rng = TestHelper.createRNG(seed);
         final double[] allValues = TestHelper.concatenate(values);
+        int repeat = 0;
         try {
-            for (int i = 1; i <= RANDOM_PERMUTATIONS; i++) {
+            while (repeat++ < RANDOM_PERMUTATIONS) {
                 TestHelper.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
                 testArrayAndCombine(TestHelper.shuffle(rng, values), expected, 
tol);
             }
         } catch (AssertionError e) {
-            rethrowWithSeed(e, seed);
+            rethrowWithSeedAndRepeat(e, seed, repeat);
         }
     }
 
@@ -1362,12 +1366,15 @@ abstract class BaseDoubleStatisticTest<S extends 
DoubleStatistic & DoubleStatist
     }
 
     /**
-     * Re-throw the error wrapped in an AssertionError with a message that 
appends the seed.
+     * Re-throw the error wrapped in an AssertionError with a message that 
appends the seed
+     * and repeat for the random order test.
      *
      * @param e Error.
      * @param seed Seed.
+     * @param repeat Repeat of the total random permutations.
      */
-    private void rethrowWithSeed(AssertionError e, long[] seed) {
-        throw new AssertionError(e.getMessage() + "; Seed=" + 
Arrays.toString(seed), e);
+    private void rethrowWithSeedAndRepeat(AssertionError e, long[] seed, int 
repeat) {
+        throw new AssertionError(String.format("%s; Seed=%s; Repeat=%d/%d",
+            e.getMessage(), Arrays.toString(seed), repeat, 
RANDOM_PERMUTATIONS), e);
     }
 }
diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
index a8ec637..4373076 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MeanTest.java
@@ -53,16 +53,17 @@ final class MeanTest extends BaseDoubleStatisticTest<Mean> {
         return Arrays.stream(values).average().orElse(getEmptyValue());
     }
 
-    // Different precision for full-array method
+    // The full-array method should be more accurate on average;
+    // however the tolerance is for the max error which is similar
 
     @Override
     protected DoubleTolerance getToleranceAccept() {
-        return DoubleTolerances.ulps(6);
+        return DoubleTolerances.ulps(8);
     }
 
     @Override
     protected DoubleTolerance getToleranceArray() {
-        return DoubleTolerances.ulps(5);
+        return DoubleTolerances.ulps(8);
     }
 
     @Override
diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/ProductTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/ProductTest.java
index 5be7320..78b6b93 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/ProductTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/ProductTest.java
@@ -55,7 +55,7 @@ final class ProductTest extends 
BaseDoubleStatisticTest<Product> {
 
     @Override
     protected DoubleTolerance getTolerance() {
-        return DoubleTolerances.ulps(15);
+        return DoubleTolerances.ulps(20);
     }
 
     @Override
diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SkewnessTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SkewnessTest.java
index a1a0e7c..282fc2e 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SkewnessTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SkewnessTest.java
@@ -82,7 +82,7 @@ final class SkewnessTest extends 
BaseDoubleStatisticTest<Skewness> {
             1, 2, 3, 4, 5));
         builder.accept(addReference(0.3305821804079746, 
DoubleTolerances.ulps(10), 2, 8, 0, 4, 1, 9, 9, 0));
         // Matlab v2023a: skewness(x, 0)   %% 0 is for bias correction
-        builder.accept(addReference(3.1210230430100503, 
DoubleTolerances.ulps(5), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50));
+        builder.accept(addReference(3.1210230430100503, 
DoubleTolerances.ulps(10), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 50));
         return builder.build();
     }
 
diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
index 951bfff..c6c3e4d 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/SumOfFourthDeviationsTest.java
@@ -76,22 +76,22 @@ final class SumOfFourthDeviationsTest extends 
BaseDoubleStatisticTest<SumOfFourt
 
     @Override
     protected DoubleTolerance getToleranceAccept() {
-        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(20));
+        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(30));
     }
 
     @Override
     protected DoubleTolerance getToleranceArray() {
-        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(15));
+        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(20));
     }
 
     @Override
     protected DoubleTolerance getToleranceAcceptAndCombine() {
-        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(25));
+        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(35));
     }
 
     @Override
     protected DoubleTolerance getToleranceArrayAndCombine() {
-        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(20));
+        return TestHelper.equalsOrNonFinite(DoubleTolerances.ulps(25));
     }
 
     @Override
diff --git 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
index 3d3af22..f089776 100644
--- 
a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
+++ 
b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/VarianceTest.java
@@ -59,7 +59,7 @@ final class VarianceTest extends 
BaseDoubleStatisticTest<Variance> {
 
     @Override
     protected DoubleTolerance getToleranceAccept() {
-        return DoubleTolerances.ulps(10);
+        return DoubleTolerances.ulps(15);
     }
 
     @Override
@@ -69,7 +69,7 @@ final class VarianceTest extends 
BaseDoubleStatisticTest<Variance> {
 
     @Override
     protected DoubleTolerance getToleranceAcceptAndCombine() {
-        return DoubleTolerances.ulps(10);
+        return DoubleTolerances.ulps(15);
     }
 
     @Override
@@ -85,7 +85,7 @@ final class VarianceTest extends 
BaseDoubleStatisticTest<Variance> {
         builder.accept(addReference(Double.NaN, DoubleTolerances.equals(), 0, 
0x1.0p1023));
         // Python Numpy v1.25.1: numpy.var(x, ddof=1)
         builder.accept(addReference(1.6666666666666667, 
DoubleTolerances.ulps(2), 1, 2, 3, 4));
-        builder.accept(addReference(7.454545454545454, 
DoubleTolerances.ulps(6),
+        builder.accept(addReference(7.454545454545454, 
DoubleTolerances.ulps(10),
             14, 8, 11, 10, 7, 9, 10, 11, 10, 15, 5, 10));
         final double[] a = new double[2 * 512 * 512];
         Arrays.fill(a, 0, a.length / 2, 1.0);

Reply via email to