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 2024/07/05 14:50:15 UTC

(commons-statistics) branch master updated (5b50dce -> 20f951a)

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 5b50dce  Remove polyfill script
     new 934d5c9  Update to RNG 1.6-SNAPSHOT
     new 0d4e381  Use Commons RNG ArraySampler for shuffle
     new 20f951a  STATISTICS-60: Remove manipulation of p-values from the Pareto sampler

The 3 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:
 .../descriptive/BaseDoubleStatisticTest.java       |  13 +-
 .../descriptive/BaseIntStatisticTest.java          |  13 +-
 .../descriptive/BaseLongStatisticTest.java         |  13 +-
 .../commons/statistics/descriptive/MedianTest.java |   7 +-
 .../commons/statistics/descriptive/TestHelper.java | 131 ---------------------
 .../distribution/ParetoDistribution.java           |  40 +------
 .../jmh/descriptive/QuantilePerformance.java       |  35 +-----
 .../statistics/ranking/NaturalRankingTest.java     |   3 +-
 pom.xml                                            |   2 +-
 9 files changed, 34 insertions(+), 223 deletions(-)


(commons-statistics) 02/03: Use Commons RNG ArraySampler for shuffle

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 0d4e38106904d6b20725707fceea898508062224
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Jul 5 15:42:02 2024 +0100

    Use Commons RNG ArraySampler for shuffle
---
 .../descriptive/BaseDoubleStatisticTest.java       |  13 +-
 .../descriptive/BaseIntStatisticTest.java          |  13 +-
 .../descriptive/BaseLongStatisticTest.java         |  13 +-
 .../commons/statistics/descriptive/MedianTest.java |   7 +-
 .../commons/statistics/descriptive/TestHelper.java | 131 ---------------------
 .../jmh/descriptive/QuantilePerformance.java       |  35 +-----
 .../statistics/ranking/NaturalRankingTest.java     |   3 +-
 7 files changed, 31 insertions(+), 184 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 94d64ec..34431f5 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
@@ -25,6 +25,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Stream.Builder;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.statistics.distribution.DoubleTolerance;
 import org.apache.commons.statistics.distribution.DoubleTolerances;
 import org.apache.commons.statistics.distribution.TestUtils;
@@ -1130,7 +1131,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testAccept(TestHelper.shuffle(rng, values), expected, tol);
+                testAccept(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1150,7 +1151,7 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testArray(TestHelper.shuffle(rng, values), expected, tol);
+                testArray(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1171,9 +1172,9 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testAcceptAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1194,9 +1195,9 @@ abstract class BaseDoubleStatisticTest<S extends DoubleStatistic & StatisticAccu
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testArrayAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
index ed51ade..145e26a 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseIntStatisticTest.java
@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Stream.Builder;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.statistics.distribution.DoubleTolerance;
 import org.apache.commons.statistics.distribution.TestUtils;
 import org.junit.jupiter.api.Assertions;
@@ -1020,7 +1021,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testAccept(TestHelper.shuffle(rng, values), expected, tol);
+                testAccept(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1040,7 +1041,7 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testArray(TestHelper.shuffle(rng, values), expected, tol);
+                testArray(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1061,9 +1062,9 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testAcceptAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1084,9 +1085,9 @@ abstract class BaseIntStatisticTest<S extends IntStatistic & StatisticAccumulato
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testArrayAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
index 1988202..280e93a 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/BaseLongStatisticTest.java
@@ -26,6 +26,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.stream.Stream.Builder;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.statistics.distribution.DoubleTolerance;
 import org.apache.commons.statistics.distribution.TestUtils;
 import org.junit.jupiter.api.Assertions;
@@ -1020,7 +1021,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testAccept(TestHelper.shuffle(rng, values), expected, tol);
+                testAccept(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1040,7 +1041,7 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                testArray(TestHelper.shuffle(rng, values), expected, tol);
+                testArray(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1061,9 +1062,9 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testAcceptAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testAcceptAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
@@ -1084,9 +1085,9 @@ abstract class BaseLongStatisticTest<S extends LongStatistic & StatisticAccumula
         int repeat = 0;
         try {
             while (repeat++ < RANDOM_PERMUTATIONS) {
-                TestHelper.shuffle(rng, allValues);
+                ArraySampler.shuffle(rng, allValues);
                 TestHelper.unconcatenate(allValues, values);
-                testArrayAndCombine(TestHelper.shuffle(rng, values), expected, tol);
+                testArrayAndCombine(ArraySampler.shuffle(rng, values), expected, tol);
             }
         } catch (final AssertionError e) {
             rethrowWithSeedAndRepeat(e, seed, repeat);
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
index c691be3..1fc2ce0 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/MedianTest.java
@@ -20,6 +20,7 @@ package org.apache.commons.statistics.descriptive;
 import java.util.Arrays;
 import java.util.stream.Stream;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.rng.simple.RandomSource;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Assumptions;
@@ -108,7 +109,7 @@ class MedianTest {
             final double[] values = rng.doubles(size, -4.5, 1.5).toArray();
             final double expected = evaluate(values);
             for (int i = 0; i < 20; i++) {
-                x = TestHelper.shuffle(rng, values.clone());
+                x = ArraySampler.shuffle(rng, values.clone());
                 builder.add(Arguments.of(x, expected));
             }
             // Special values
@@ -122,7 +123,7 @@ class MedianTest {
             // Even: half -0.0
             x = new double[size];
             Arrays.fill(x, 0, (size + 1) / 2, -0.0);
-            TestHelper.shuffle(rng, x);
+            ArraySampler.shuffle(rng, x);
             builder.add(Arguments.of(x.clone(), (size & 0x1) == 1 ? -0.0 : 0.0));
         }
         // Special cases
@@ -198,7 +199,7 @@ class MedianTest {
             final int[] values = rng.ints(size, -4500, 1500).toArray();
             final double expected = evaluate(values);
             for (int i = 0; i < 20; i++) {
-                x = TestHelper.shuffle(rng, values.clone());
+                x = ArraySampler.shuffle(rng, values.clone());
                 builder.add(Arguments.of(x, expected));
             }
             // Special values
diff --git a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
index 8cf1dc6..aa080d1 100644
--- a/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
+++ b/commons-statistics-descriptive/src/test/java/org/apache/commons/statistics/descriptive/TestHelper.java
@@ -258,137 +258,6 @@ final class TestHelper {
         return RANDOM_SOURCE.create(seed);
     }
 
-    /**
-     * Shuffles the entries of the given array.
-     *
-     * <p>Uses Fisher-Yates shuffle copied from
-     * <a href="https://github.com/apache/commons-rng/blob/master/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/ArraySampler.java">
-     *     RNG ArraySampler.</a>
-     *
-     * <p>TODO: This can be removed when {@code commons-rng-sampling 1.6} is released.
-     *
-     * @param rng Source of randomness.
-     * @param array Array whose entries will be shuffled (in-place).
-     * @return Shuffled input array.
-     */
-    static double[] shuffle(UniformRandomProvider rng, double[] array) {
-        for (int i = array.length; i > 1; i--) {
-            swap(array, i - 1, rng.nextInt(i));
-        }
-        return array;
-    }
-
-    /**
-     * Shuffles the entries of the given array.
-     *
-     * <p>Uses Fisher-Yates shuffle copied from
-     * <a href="https://github.com/apache/commons-rng/blob/master/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/ArraySampler.java">
-     *     RNG ArraySampler.</a>
-     *
-     * <p>TODO: This can be removed when {@code commons-rng-sampling 1.6} is released.
-     *
-     * @param rng Source of randomness.
-     * @param array Array whose entries will be shuffled (in-place).
-     * @return Shuffled input array.
-     */
-    static int[] shuffle(UniformRandomProvider rng, int[] array) {
-        for (int i = array.length; i > 1; i--) {
-            swap(array, i - 1, rng.nextInt(i));
-        }
-        return array;
-    }
-
-    /**
-     * Shuffles the entries of the given array.
-     *
-     * <p>Uses Fisher-Yates shuffle copied from
-     * <a href="https://github.com/apache/commons-rng/blob/master/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/ArraySampler.java">
-     *     RNG ArraySampler.</a>
-     *
-     * <p>TODO: This can be removed when {@code commons-rng-sampling 1.6} is released.
-     *
-     * @param rng Source of randomness.
-     * @param array Array whose entries will be shuffled (in-place).
-     * @return Shuffled input array.
-     */
-    static long[] shuffle(UniformRandomProvider rng, long[] array) {
-        for (int i = array.length; i > 1; i--) {
-            swap(array, i - 1, rng.nextInt(i));
-        }
-        return array;
-    }
-
-    /**
-     * Shuffles the entries of the given array.
-     *
-     * <p>Uses Fisher-Yates shuffle copied from
-     * <a href="https://github.com/apache/commons-rng/blob/master/commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/ArraySampler.java">
-     *     RNG ArraySampler.</a>
-     *
-     * <p>TODO: This can be removed when {@code commons-rng-sampling 1.6} is released.
-     *
-     * @param rng Source of randomness.
-     * @param array Array whose entries will be shuffled (in-place).
-     * @return Shuffled input array.
-     */
-    static <T> T[] shuffle(UniformRandomProvider rng, T[] array) {
-        for (int i = array.length; i > 1; i--) {
-            swap(array, i - 1, rng.nextInt(i));
-        }
-        return array;
-    }
-
-    /**
-     * Swaps the two specified elements in the array.
-     *
-     * @param array Array.
-     * @param i First index.
-     * @param j Second index.
-     */
-    private static void swap(double[] array, int i, int j) {
-        final double tmp = array[i];
-        array[i] = array[j];
-        array[j] = tmp;
-    }
-
-    /**
-     * Swaps the two specified elements in the array.
-     *
-     * @param array Array.
-     * @param i First index.
-     * @param j Second index.
-     */
-    private static void swap(int[] array, int i, int j) {
-        final int tmp = array[i];
-        array[i] = array[j];
-        array[j] = tmp;
-    }
-
-    /**
-     * Swaps the two specified elements in the array.
-     *
-     * @param array Array.
-     * @param i First index.
-     * @param j Second index.
-     */
-    private static void swap(long[] array, int i, int j) {
-        final long tmp = array[i];
-        array[i] = array[j];
-        array[j] = tmp;
-    }
-    /**
-     * Swaps the two specified elements in the array.
-     *
-     * @param array Array.
-     * @param i First index.
-     * @param j Second index.
-     */
-    private static <T> void swap(T[] array, int i, int j) {
-        final T tmp = array[i];
-        array[i] = array[j];
-        array[j] = tmp;
-    }
-
     /**
      * Assert the results are equal. All result types are compared.
      *
diff --git a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/QuantilePerformance.java b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/QuantilePerformance.java
index ede1c07..0c2a98f 100644
--- a/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/QuantilePerformance.java
+++ b/commons-statistics-examples/examples-jmh/src/main/java/org/apache/commons/statistics/examples/jmh/descriptive/QuantilePerformance.java
@@ -29,6 +29,7 @@ import java.util.function.BiFunction;
 import java.util.function.BinaryOperator;
 import java.util.logging.Logger;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.rng.sampling.PermutationSampler;
 import org.apache.commons.rng.sampling.distribution.DiscreteUniformSampler;
 import org.apache.commons.rng.sampling.distribution.SharedStateDiscreteSampler;
@@ -448,7 +449,7 @@ public class QuantilePerformance {
                 // First call, create objects
                 order = PermutationSampler.natural(size());
             }
-            PermutationSampler.shuffle(rng, order);
+            ArraySampler.shuffle(rng, order);
         }
 
         /**
@@ -715,8 +716,8 @@ public class QuantilePerformance {
                 medianOf3Killer(x);
                 final int j = 4 * (31 - Integer.numberOfLeadingZeros(n));
                 final int n2 = n >>> 1;
-                shuffle(rng, x, j, n2);
-                shuffle(rng, x, n2 + j, n);
+                ArraySampler.shuffle(rng, x, j, n2);
+                ArraySampler.shuffle(rng, x, n2 + j, n);
             }
             if (dist.contains(Distribution.ORGANPIPE)) {
                 distData.add(x = new int[n]);
@@ -791,34 +792,6 @@ public class QuantilePerformance {
             return a;
         }
 
-        /**
-         * Shuffles the entries of the given array.
-         *
-         * @param rng Source of randomness.
-         * @param array Array whose entries will be shuffled (in-place).
-         * @param from Lower-bound (inclusive) of the sub-range.
-         * @param to Upper-bound (exclusive) of the sub-range.
-         */
-        private static void shuffle(UniformRandomProvider rng, int[] array, int from, int to) {
-            final int length = to - from;
-            for (int i = length; i > 1; i--) {
-                swap(array, from + i - 1, from + rng.nextInt(i));
-            }
-        }
-
-        /**
-         * Swaps the two specified elements in the array.
-         *
-         * @param array Array.
-         * @param i First index.
-         * @param j Second index.
-         */
-        private static void swap(int[] array, int i, int j) {
-            final int tmp = array[i];
-            array[i] = array[j];
-            array[j] = tmp;
-        }
-
         /**
          * Gets the minimum length of the data.
          * The actual length is enumerated in {@code [length, length + range]}.
diff --git a/commons-statistics-ranking/src/test/java/org/apache/commons/statistics/ranking/NaturalRankingTest.java b/commons-statistics-ranking/src/test/java/org/apache/commons/statistics/ranking/NaturalRankingTest.java
index 98017dd..9bc717f 100644
--- a/commons-statistics-ranking/src/test/java/org/apache/commons/statistics/ranking/NaturalRankingTest.java
+++ b/commons-statistics-ranking/src/test/java/org/apache/commons/statistics/ranking/NaturalRankingTest.java
@@ -27,6 +27,7 @@ import java.util.stream.IntStream;
 import java.util.stream.Stream;
 import org.apache.commons.math3.stat.inference.ChiSquareTest;
 import org.apache.commons.rng.UniformRandomProvider;
+import org.apache.commons.rng.sampling.ArraySampler;
 import org.apache.commons.rng.sampling.PermutationSampler;
 import org.apache.commons.rng.simple.RandomSource;
 import org.junit.jupiter.api.Assertions;
@@ -347,7 +348,7 @@ class NaturalRankingTest {
         final double[] expected = new double[values.length];
         final NaturalRanking ranking = new NaturalRanking(tiesStrategy);
         for (int i = 0; i < 3; i++) {
-            PermutationSampler.shuffle(rng, indices);
+            ArraySampler.shuffle(rng, indices);
             for (int j = 0; j < values.length; j++) {
                 data[j] = values[indices[j]];
                 expected[j] = indices[j] + 1;


(commons-statistics) 03/03: STATISTICS-60: Remove manipulation of p-values from the Pareto sampler

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 20f951a91698c84cc7965966d50ac0ebd528a478
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Jul 5 15:49:25 2024 +0100

    STATISTICS-60: Remove manipulation of p-values from the Pareto sampler
    
    Commons RNG 1.6 implements this adaption directly.
---
 .../distribution/ParetoDistribution.java           | 40 ++--------------------
 1 file changed, 2 insertions(+), 38 deletions(-)

diff --git a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ParetoDistribution.java b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ParetoDistribution.java
index 88d292b..c5af239 100644
--- a/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ParetoDistribution.java
+++ b/commons-statistics-distribution/src/main/java/org/apache/commons/statistics/distribution/ParetoDistribution.java
@@ -295,43 +295,7 @@ public final class ParetoDistribution extends AbstractContinuousDistribution {
     /** {@inheritDoc} */
     @Override
     public ContinuousDistribution.Sampler createSampler(final UniformRandomProvider rng) {
-        // Pareto distribution sampler.
-        // Commons RNG v1.5 uses nextDouble for (1 - p) effectively sampling from p in (0, 1].
-        // Ensure sampling is concentrated at the lower / upper bound at extreme shapes:
-        // Large shape should sample using p in [0, 1)  (lower bound)
-        // Small shape should sample using p in (0, 1]  (upper bound)
-        // Note: For small shape the input RNG is also wrapped to use nextLong as the source of
-        // randomness; this ensures the nextDouble method uses the interface output of [0, 1).
-        // Commons RNG v1.6 uses nextLong and will not be affected by changes to nextDouble.
-        final UniformRandomProvider wrappedRng = shape >= 1 ? new InvertedRNG(rng) : rng::nextLong;
-        return InverseTransformParetoSampler.of(wrappedRng, scale, shape)::sample;
-    }
-
-    /**
-     * Create a RNG that inverts the output from nextDouble() as (1 - nextDouble()).
-     */
-    private static class InvertedRNG implements UniformRandomProvider {
-        /** Source of randomness. */
-        private final UniformRandomProvider rng;
-
-        /**
-         * @param rng Source of randomness
-         */
-        InvertedRNG(UniformRandomProvider rng) {
-            this.rng = rng;
-        }
-
-        @Override
-        public long nextLong() {
-            // Delegate the source of randomness
-            return rng.nextLong();
-        }
-
-        @Override
-        public double nextDouble() {
-            // Return a value in (0, 1].
-            // This assumes the interface method outputs in [0, 1).
-            return 1 - UniformRandomProvider.super.nextDouble();
-        }
+        // Pareto distribution sampler
+        return InverseTransformParetoSampler.of(rng, scale, shape)::sample;
     }
 }


(commons-statistics) 01/03: Update to RNG 1.6-SNAPSHOT

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 934d5c95e18e6d8205d757011533ef13cefaf5ef
Author: Alex Herbert <ah...@apache.org>
AuthorDate: Fri Jul 5 15:34:05 2024 +0100

    Update to RNG 1.6-SNAPSHOT
---
 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pom.xml b/pom.xml
index 8b65405..f486e77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -135,7 +135,7 @@
     <doclint.javadoc.qualifier>-Xdoclint:all</doclint.javadoc.qualifier>
 
     <!-- Dependency versions -->
-    <statistics.commons.rng.version>1.5</statistics.commons.rng.version>
+    <statistics.commons.rng.version>1.6-SNAPSHOT</statistics.commons.rng.version>
     <statistics.commons.numbers.version>1.2-SNAPSHOT</statistics.commons.numbers.version>
     <statistics.commons.math3.version>3.6.1</statistics.commons.math3.version>
     <statistics.commons.math4.version>4.0-beta1</statistics.commons.math4.version>