You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2019/10/22 14:30:54 UTC

[commons-math] branch master updated (6ce5048 -> c7973fe)

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

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


    from 6ce5048  Grammar
     new d0d4fea  Use properties to define version of dependencies.
     new f8c031e  Upgrade to "Commons RNG" (v1.2).
     new 0346204  Use "BigFraction" class from "Commons Numbers".
     new 830f1d1  Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-math
     new c7973fe  Use "BigFraction" class from "Commons Numbers".

The 5 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:
 pom.xml                                            |  30 +++---
 .../analysis/polynomials/PolynomialsUtils.java     |  36 +++----
 .../stat/inference/KolmogorovSmirnovTest.java      | 105 +++++++++++----------
 3 files changed, 92 insertions(+), 79 deletions(-)


[commons-math] 01/05: Use properties to define version of dependencies.

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

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

commit d0d4feaf275b98458e1c02fe1d18b5178d96b710
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Oct 22 13:45:13 2019 +0200

    Use properties to define version of dependencies.
---
 pom.xml | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/pom.xml b/pom.xml
index 9839613..13405ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,6 +62,8 @@
     <math.checkstyle.version>2.17</math.checkstyle.version>
     <math.clirr.version>2.8</math.clirr.version>
     <math.mathjax.version>2.7.2</math.mathjax.version>
+    <math.commons.numbers.version>1.0-SNAPSHOT</math.commons.numbers.version>
+    <math.commons.rng.version>1.1</math.commons.rng.version>
 
     <commons.site.path>math</commons.site.path>
     <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math</commons.scmPubUrl>
@@ -114,67 +116,67 @@
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-core</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-complex</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-complex-streams</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-gamma</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-combinatorics</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-arrays</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-angle</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-numbers-rootfinder</artifactId>
-      <version>1.0-SNAPSHOT</version>
+      <version>${math.commons.numbers.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-client-api</artifactId>
-      <version>1.1</version>
+      <version>${math.commons.rng.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-simple</artifactId>
-      <version>1.1</version>
+      <version>${math.commons.rng.version}</version>
     </dependency>
 
     <dependency>
       <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-sampling</artifactId>
-      <version>1.1</version>
+      <version>${math.commons.rng.version}</version>
     </dependency>
 
     <dependency>


[commons-math] 04/05: Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-math

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

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

commit 830f1d1443b21bb17f76fba84eb1170d97ba369a
Merge: 0346204 6ce5048
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Oct 22 13:59:17 2019 +0200

    Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-math

 src/site/xdoc/userguide/ode.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[commons-math] 03/05: Use "BigFraction" class from "Commons Numbers".

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

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

commit 0346204c7c2a9a0e71daca0ea3aef676e34b38ac
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Oct 22 13:58:10 2019 +0200

    Use "BigFraction" class from "Commons Numbers".
---
 pom.xml                                            |   6 ++
 .../stat/inference/KolmogorovSmirnovTest.java      | 103 +++++++++++----------
 2 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/pom.xml b/pom.xml
index f161832..ad44243 100644
--- a/pom.xml
+++ b/pom.xml
@@ -163,6 +163,12 @@
 
     <dependency>
       <groupId>org.apache.commons</groupId>
+      <artifactId>commons-numbers-field</artifactId>
+      <version>${math.commons.numbers.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.commons</groupId>
       <artifactId>commons-rng-client-api</artifactId>
       <version>${math.commons.rng.version}</version>
     </dependency>
diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
index e4a5212..f9b0449 100644
--- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
+++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
@@ -18,12 +18,16 @@
 package org.apache.commons.math4.stat.inference;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.Arrays;
 
 import org.apache.commons.rng.simple.RandomSource;
 import org.apache.commons.rng.UniformRandomProvider;
 import org.apache.commons.statistics.distribution.ContinuousDistribution;
 import org.apache.commons.numbers.combinatorics.BinomialCoefficientDouble;
+import org.apache.commons.numbers.fraction.BigFraction;
+import org.apache.commons.numbers.field.BigFractionField;
+import org.apache.commons.numbers.field.FieldSquareMatrix;
 import org.apache.commons.math4.distribution.EnumeratedRealDistribution;
 import org.apache.commons.math4.distribution.AbstractRealDistribution;
 import org.apache.commons.math4.exception.InsufficientDataException;
@@ -35,11 +39,6 @@ import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.exception.TooManyIterationsException;
 import org.apache.commons.math4.exception.NotANumberException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.fraction.BigFraction;
-import org.apache.commons.math4.fraction.BigFractionField;
-import org.apache.commons.math4.fraction.FractionConversionException;
-import org.apache.commons.math4.linear.Array2DRowFieldMatrix;
-import org.apache.commons.math4.linear.FieldMatrix;
 import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.util.FastMath;
@@ -122,6 +121,8 @@ public class KolmogorovSmirnovTest {
     private static final double KS_SUM_CAUCHY_CRITERION = 1e-20;
     /** Convergence criterion for the sums in {@link #pelzGood(double, int)} */
     private static final double PG_SUM_RELATIVE_ERROR = 1e-10;
+    /** 1/2 */
+    private static final BigFraction ONE_HALF = BigFraction.of(1, 2);
 
     /**
      * When product of sample sizes exceeds this value, 2-sample K-S test uses asymptotic
@@ -406,11 +407,10 @@ public class KolmogorovSmirnovTest {
      * @param n sample size
      * @return \(P(D_n &lt; d)\)
      * @throws MathArithmeticException if algorithm fails to convert {@code h} to a
-     *         {@link org.apache.commons.math4.fraction.BigFraction} in expressing {@code d} as \((k
-     *         - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\)
+     * {@link BigFraction} in expressing {@code d} as
+     * \((k - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\)
      */
-    public double cdf(double d, int n)
-        throws MathArithmeticException {
+    public double cdf(double d, int n) {
         return cdf(d, n, false);
     }
 
@@ -425,11 +425,10 @@ public class KolmogorovSmirnovTest {
      * @param n sample size
      * @return \(P(D_n &lt; d)\)
      * @throws MathArithmeticException if the algorithm fails to convert {@code h} to a
-     *         {@link org.apache.commons.math4.fraction.BigFraction} in expressing {@code d} as \((k
-     *         - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\)
+     * {@link BigFraction} in expressing {@code d} as
+     * \((k - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\)
      */
-    public double cdfExact(double d, int n)
-        throws MathArithmeticException {
+    public double cdfExact(double d, int n) {
         return cdf(d, n, true);
     }
 
@@ -446,12 +445,10 @@ public class KolmogorovSmirnovTest {
      *        sure; {@code true} is almost solely for verification purposes.
      * @return \(P(D_n &lt; d)\)
      * @throws MathArithmeticException if algorithm fails to convert {@code h} to a
-     *         {@link org.apache.commons.math4.fraction.BigFraction} in expressing {@code d} as \((k
-     *         - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\).
+     * {@link BigFraction} in expressing {@code d} as
+     * \((k - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\).
      */
-    public double cdf(double d, int n, boolean exact)
-        throws MathArithmeticException {
-
+    public double cdf(double d, int n, boolean exact) {
         final double ninv = 1 / ((double) n);
         final double ninvhalf = 0.5 * ninv;
 
@@ -488,18 +485,21 @@ public class KolmogorovSmirnovTest {
      * @param n sample size
      * @return the two-sided probability of \(P(D_n &lt; d)\)
      * @throws MathArithmeticException if algorithm fails to convert {@code h} to a
-     *         {@link org.apache.commons.math4.fraction.BigFraction} in expressing {@code d} as \((k
-     *         - h) / m\) for integer {@code k, m} and \(0 \le h &lt; 1\).
+     * {@link BigFraction}.
      */
-    private double exactK(double d, int n)
-        throws MathArithmeticException {
-
+    private double exactK(double d, int n) {
         final int k = (int) Math.ceil(n * d);
 
-        final FieldMatrix<BigFraction> H = this.createExactH(d, n);
-        final FieldMatrix<BigFraction> Hpower = H.power(n);
+        final FieldSquareMatrix<BigFraction> H;
+        try {
+            H = createExactH(d, n);
+        } catch (ArithmeticException e) {
+            throw new MathArithmeticException(LocalizedFormats.FRACTION);
+        }
+
+        final FieldSquareMatrix<BigFraction> Hpower = H.pow(n);
 
-        BigFraction pFrac = Hpower.getEntry(k - 1, k - 1);
+        BigFraction pFrac = Hpower.get(k - 1, k - 1);
 
         for (int i = 1; i <= n; ++i) {
             pFrac = pFrac.multiply(i).divide(n);
@@ -510,7 +510,7 @@ public class KolmogorovSmirnovTest {
          * divides afterwards. That gives NaN quite easy. This does not (scale is the number of
          * digits):
          */
-        return pFrac.bigDecimalValue(20, BigDecimal.ROUND_HALF_UP).doubleValue();
+        return pFrac.bigDecimalValue(20, RoundingMode.HALF_UP).doubleValue();
     }
 
     /**
@@ -672,23 +672,20 @@ public class KolmogorovSmirnovTest {
         }
         return ret + (sqrtHalfPi / (sqrtN * n)) * (sum / (3240 * z6 * z4) +
                 + sum2 / (108 * z6));
-
     }
 
-    /***
+    /**
      * Creates {@code H} of size {@code m x m} as described in [1] (see above).
      *
      * @param d statistic
      * @param n sample size
      * @return H matrix
-     * @throws NumberIsTooLargeException if fractional part is greater than 1
-     * @throws FractionConversionException if algorithm fails to convert {@code h} to a
-     *         {@link org.apache.commons.math4.fraction.BigFraction} in expressing {@code d} as \((k
-     *         - h) / m\) for integer {@code k, m} and \(0 <= h < 1\).
+     * @throws NumberIsTooLargeException if fractional part is greater than 1.
+     * @throws ArithmeticException if algorithm fails to convert {@code h} to a
+     * {@link BigFraction}.
      */
-    private FieldMatrix<BigFraction> createExactH(double d, int n)
-        throws NumberIsTooLargeException, FractionConversionException {
-
+    private FieldSquareMatrix<BigFraction> createExactH(double d,
+                                                        int n) {
         final int k = (int) Math.ceil(n * d);
         final int m = 2 * k - 1;
         final double hDouble = k - n * d;
@@ -697,15 +694,15 @@ public class KolmogorovSmirnovTest {
         }
         BigFraction h = null;
         try {
-            h = new BigFraction(hDouble, 1.0e-20, 10000);
-        } catch (final FractionConversionException e1) {
+            h = BigFraction.from(hDouble, 1e-20, 10000);
+        } catch (final ArithmeticException e1) {
             try {
-                h = new BigFraction(hDouble, 1.0e-10, 10000);
-            } catch (final FractionConversionException e2) {
-                h = new BigFraction(hDouble, 1.0e-5, 10000);
+                h = BigFraction.from(hDouble, 1e-10, 10000);
+            } catch (final ArithmeticException e2) {
+                h = BigFraction.from(hDouble, 1e-5, 10000);
             }
         }
-        final BigFraction[][] Hdata = new BigFraction[m][m];
+        final FieldSquareMatrix<BigFraction> Hdata = FieldSquareMatrix.create(BigFractionField.get(), m);
 
         /*
          * Start by filling everything with either 0 or 1.
@@ -713,9 +710,9 @@ public class KolmogorovSmirnovTest {
         for (int i = 0; i < m; ++i) {
             for (int j = 0; j < m; ++j) {
                 if (i - j + 1 < 0) {
-                    Hdata[i][j] = BigFraction.ZERO;
+                    Hdata.set(i, j, BigFraction.ZERO);
                 } else {
-                    Hdata[i][j] = BigFraction.ONE;
+                    Hdata.set(i, j, BigFraction.ONE);
                 }
             }
         }
@@ -726,7 +723,7 @@ public class KolmogorovSmirnovTest {
          */
         final BigFraction[] hPowers = new BigFraction[m];
         hPowers[0] = h;
-        for (int i = 1; i < m; ++i) {
+        for (int i = 1; i < m; i++) {
             hPowers[i] = h.multiply(hPowers[i - 1]);
         }
 
@@ -734,16 +731,19 @@ public class KolmogorovSmirnovTest {
          * First column and last row has special values (each other reversed).
          */
         for (int i = 0; i < m; ++i) {
-            Hdata[i][0] = Hdata[i][0].subtract(hPowers[i]);
-            Hdata[m - 1][i] = Hdata[m - 1][i].subtract(hPowers[m - i - 1]);
+            Hdata.set(i, 0,
+                      Hdata.get(i, 0).subtract(hPowers[i]));
+            Hdata.set(m - 1, i,
+                      Hdata.get(m - 1, i).subtract(hPowers[m - i - 1]));
         }
 
         /*
          * [1] states: "For 1/2 < h < 1 the bottom left element of the matrix should be (1 - 2*h^m +
          * (2h - 1)^m )/m!" Since 0 <= h < 1, then if h > 1/2 is sufficient to check:
          */
-        if (h.compareTo(BigFraction.ONE_HALF) == 1) {
-            Hdata[m - 1][0] = Hdata[m - 1][0].add(h.multiply(2).subtract(1).pow(m));
+        if (h.compareTo(ONE_HALF) == 1) {
+            Hdata.set(m - 1, 0,
+                      Hdata.get(m - 1, 0).add(h.multiply(2).subtract(1).pow(m)));
         }
 
         /*
@@ -758,12 +758,13 @@ public class KolmogorovSmirnovTest {
             for (int j = 0; j < i + 1; ++j) {
                 if (i - j + 1 > 0) {
                     for (int g = 2; g <= i - j + 1; ++g) {
-                        Hdata[i][j] = Hdata[i][j].divide(g);
+                        Hdata.set(i, j,
+                                  Hdata.get(i, j).divide(g));
                     }
                 }
             }
         }
-        return new Array2DRowFieldMatrix<>(BigFractionField.getInstance(), Hdata);
+        return Hdata;
     }
 
     /***


Re: [commons-math] 02/05: Upgrade to "Commons RNG" (v1.2).

Posted by Gilles Sadowski <gi...@gmail.com>.
Hi.

2019-10-22 17:04 UTC+02:00, Alex Herbert <al...@gmail.com>:
>
> On 22/10/2019 15:30, erans@apache.org wrote:
>> This is an automated email from the ASF dual-hosted git repository.
>>
>> erans pushed a commit to branch master
>> in repository https://gitbox.apache.org/repos/asf/commons-math.git
>>
>> commit f8c031ee3810721e99534a1c111f567c3ec6ceb7
>> Author: Gilles Sadowski <gi...@harfang.homelinux.org>
>> AuthorDate: Tue Oct 22 13:49:45 2019 +0200
>>
>>      Upgrade to "Commons RNG" (v1.2).
>>
>>      Seed had to be modified in class "KolmogorovSmirnovTest" for a unit
>> test to pass.
>> ---
>>   pom.xml
>> | 2 +-
>>   .../org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
>> | 2 +-
>>   2 files changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/pom.xml b/pom.xml
>> index 13405ff..f161832 100644
>> --- a/pom.xml
>> +++ b/pom.xml
>> @@ -63,7 +63,7 @@
>>       <math.clirr.version>2.8</math.clirr.version>
>>       <math.mathjax.version>2.7.2</math.mathjax.version>
>>
>> <math.commons.numbers.version>1.0-SNAPSHOT</math.commons.numbers.version>
>> -    <math.commons.rng.version>1.1</math.commons.rng.version>
>> +    <math.commons.rng.version>1.2</math.commons.rng.version>
>>
>>       <commons.site.path>math</commons.site.path>
>>
>> <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math</commons.scmPubUrl>
>> diff --git
>> a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
>> b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
>> index 153d1d6..e4a5212 100644
>> ---
>> a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
>> +++
>> b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
>> @@ -1084,7 +1084,7 @@ public class KolmogorovSmirnovTest {
>>           if (hasTies(x, y)) {
>>               // Add jitter using a fixed seed (so same arguments always
>> give same results),
>>               // low-initialization-overhead generator.
>> -            final UniformRandomProvider rng =
>> RandomSource.create(RandomSource.TWO_CMRES, 7654321);
>> +            final UniformRandomProvider rng =
>> RandomSource.create(RandomSource.TWO_CMRES, 76543217);
>
> Hi Gilles,
>
> A minor nit, this is not a
>
> "low-initialization-overhead generator"
>
> It has the highest construction cost of all the generators.

You are quite right; this is one place where having a lower
overhead makes a lot of sense.

> It does have
> a minimum seed size but that is not the same thing. Would the test pass
> with RandomSource.SPLIT_MIX?

The generator does not matter (code calls "nextInt(int max)").
I've changed it.
[The game is to make the unit test pass with _some_ seed.  As
the test uses "extreme" values (a.o. MAX_VALUE), the hope is
that the same seed will work for the vast majority of useful
cases.]

Thanks,
Gilles

>
> Alex
>
>>
>>               // It is theoretically possible that jitter does not break
>> ties, so repeat
>>               // until all ties are gone.  Bound the loop and throw MIE if
>> bound is exceeded.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [commons-math] 02/05: Upgrade to "Commons RNG" (v1.2).

Posted by Alex Herbert <al...@gmail.com>.
On 22/10/2019 15:30, erans@apache.org wrote:
> This is an automated email from the ASF dual-hosted git repository.
>
> erans pushed a commit to branch master
> in repository https://gitbox.apache.org/repos/asf/commons-math.git
>
> commit f8c031ee3810721e99534a1c111f567c3ec6ceb7
> Author: Gilles Sadowski <gi...@harfang.homelinux.org>
> AuthorDate: Tue Oct 22 13:49:45 2019 +0200
>
>      Upgrade to "Commons RNG" (v1.2).
>      
>      Seed had to be modified in class "KolmogorovSmirnovTest" for a unit test to pass.
> ---
>   pom.xml                                                                 | 2 +-
>   .../org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java  | 2 +-
>   2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/pom.xml b/pom.xml
> index 13405ff..f161832 100644
> --- a/pom.xml
> +++ b/pom.xml
> @@ -63,7 +63,7 @@
>       <math.clirr.version>2.8</math.clirr.version>
>       <math.mathjax.version>2.7.2</math.mathjax.version>
>       <math.commons.numbers.version>1.0-SNAPSHOT</math.commons.numbers.version>
> -    <math.commons.rng.version>1.1</math.commons.rng.version>
> +    <math.commons.rng.version>1.2</math.commons.rng.version>
>   
>       <commons.site.path>math</commons.site.path>
>       <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math</commons.scmPubUrl>
> diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
> index 153d1d6..e4a5212 100644
> --- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
> +++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
> @@ -1084,7 +1084,7 @@ public class KolmogorovSmirnovTest {
>           if (hasTies(x, y)) {
>               // Add jitter using a fixed seed (so same arguments always give same results),
>               // low-initialization-overhead generator.
> -            final UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES, 7654321);
> +            final UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES, 76543217);

Hi Gilles,

A minor nit, this is not a

"low-initialization-overhead generator"

It has the highest construction cost of all the generators. It does have 
a minimum seed size but that is not the same thing. Would the test pass 
with RandomSource.SPLIT_MIX?

Alex

>   
>               // It is theoretically possible that jitter does not break ties, so repeat
>               // until all ties are gone.  Bound the loop and throw MIE if bound is exceeded.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[commons-math] 02/05: Upgrade to "Commons RNG" (v1.2).

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

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

commit f8c031ee3810721e99534a1c111f567c3ec6ceb7
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Oct 22 13:49:45 2019 +0200

    Upgrade to "Commons RNG" (v1.2).
    
    Seed had to be modified in class "KolmogorovSmirnovTest" for a unit test to pass.
---
 pom.xml                                                                 | 2 +-
 .../org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/pom.xml b/pom.xml
index 13405ff..f161832 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,7 +63,7 @@
     <math.clirr.version>2.8</math.clirr.version>
     <math.mathjax.version>2.7.2</math.mathjax.version>
     <math.commons.numbers.version>1.0-SNAPSHOT</math.commons.numbers.version>
-    <math.commons.rng.version>1.1</math.commons.rng.version>
+    <math.commons.rng.version>1.2</math.commons.rng.version>
 
     <commons.site.path>math</commons.site.path>
     <commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-math</commons.scmPubUrl>
diff --git a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
index 153d1d6..e4a5212 100644
--- a/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
+++ b/src/main/java/org/apache/commons/math4/stat/inference/KolmogorovSmirnovTest.java
@@ -1084,7 +1084,7 @@ public class KolmogorovSmirnovTest {
         if (hasTies(x, y)) {
             // Add jitter using a fixed seed (so same arguments always give same results),
             // low-initialization-overhead generator.
-            final UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES, 7654321);
+            final UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES, 76543217);
 
             // It is theoretically possible that jitter does not break ties, so repeat
             // until all ties are gone.  Bound the loop and throw MIE if bound is exceeded.


[commons-math] 05/05: Use "BigFraction" class from "Commons Numbers".

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

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

commit c7973fe10aeb6179ff10b1c828a02e45648e65fb
Author: Gilles Sadowski <gi...@harfang.homelinux.org>
AuthorDate: Tue Oct 22 16:05:26 2019 +0200

    Use "BigFraction" class from "Commons Numbers".
---
 .../analysis/polynomials/PolynomialsUtils.java     | 36 ++++++++++++----------
 1 file changed, 20 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
index 018df81..2076ef7 100644
--- a/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
+++ b/src/main/java/org/apache/commons/math4/analysis/polynomials/PolynomialsUtils.java
@@ -21,7 +21,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.commons.math4.fraction.BigFraction;
+import org.apache.commons.numbers.fraction.BigFraction;
 import org.apache.commons.numbers.combinatorics.BinomialCoefficient;
 import org.apache.commons.math4.util.FastMath;
 
@@ -31,6 +31,10 @@ import org.apache.commons.math4.util.FastMath;
  * @since 2.0
  */
 public class PolynomialsUtils {
+    /** -1 */
+    private static final BigFraction BF__MINUS_ONE = BigFraction.of(-1);
+    /** 2 */
+    private static final BigFraction BF__TWO = BigFraction.of(2);
 
     /** Coefficients for Chebyshev polynomials. */
     private static final List<BigFraction> CHEBYSHEV_COEFFICIENTS;
@@ -61,14 +65,14 @@ public class PolynomialsUtils {
         HERMITE_COEFFICIENTS = new ArrayList<>();
         HERMITE_COEFFICIENTS.add(BigFraction.ONE);
         HERMITE_COEFFICIENTS.add(BigFraction.ZERO);
-        HERMITE_COEFFICIENTS.add(BigFraction.TWO);
+        HERMITE_COEFFICIENTS.add(BF__TWO);
 
         // initialize recurrence for Laguerre polynomials
         // L0(X) = 1, L1(X) = 1 - 1 * X
         LAGUERRE_COEFFICIENTS = new ArrayList<>();
         LAGUERRE_COEFFICIENTS.add(BigFraction.ONE);
         LAGUERRE_COEFFICIENTS.add(BigFraction.ONE);
-        LAGUERRE_COEFFICIENTS.add(BigFraction.MINUS_ONE);
+        LAGUERRE_COEFFICIENTS.add(BF__MINUS_ONE);
 
         // initialize recurrence for Legendre polynomials
         // P0(X) = 1, P1(X) = 0 + 1 * X
@@ -106,7 +110,7 @@ public class PolynomialsUtils {
         return buildPolynomial(degree, CHEBYSHEV_COEFFICIENTS,
                 new RecurrenceCoefficientsGenerator() {
             /** Fixed recurrence coefficients. */
-            private final BigFraction[] coeffs = { BigFraction.ZERO, BigFraction.TWO, BigFraction.ONE };
+            private final BigFraction[] coeffs = { BigFraction.ZERO, BF__TWO, BigFraction.ONE };
             /** {@inheritDoc} */
             @Override
             public BigFraction[] generate(int k) {
@@ -138,8 +142,8 @@ public class PolynomialsUtils {
             public BigFraction[] generate(int k) {
                 return new BigFraction[] {
                         BigFraction.ZERO,
-                        BigFraction.TWO,
-                        new BigFraction(2 * k)};
+                        BF__TWO,
+                        BigFraction.of(2 * k)};
             }
         });
     }
@@ -166,9 +170,9 @@ public class PolynomialsUtils {
             public BigFraction[] generate(int k) {
                 final int kP1 = k + 1;
                 return new BigFraction[] {
-                        new BigFraction(2 * k + 1, kP1),
-                        new BigFraction(-1, kP1),
-                        new BigFraction(k, kP1)};
+                        BigFraction.of(2 * k + 1, kP1),
+                        BigFraction.of(-1, kP1),
+                        BigFraction.of(k, kP1)};
             }
         });
     }
@@ -196,8 +200,8 @@ public class PolynomialsUtils {
                 final int kP1 = k + 1;
                 return new BigFraction[] {
                         BigFraction.ZERO,
-                        new BigFraction(k + kP1, kP1),
-                        new BigFraction(k, kP1)};
+                        BigFraction.of(k + kP1, kP1),
+                        BigFraction.of(k, kP1)};
             }
         });
     }
@@ -235,8 +239,8 @@ public class PolynomialsUtils {
             list.add(BigFraction.ONE);
 
             // P1(x) = (v - w) / 2 + (2 + v + w) * X / 2
-            list.add(new BigFraction(v - w, 2));
-            list.add(new BigFraction(2 + v + w, 2));
+            list.add(BigFraction.of(v - w, 2));
+            list.add(BigFraction.of(2 + v + w, 2));
 
         }
 
@@ -253,9 +257,9 @@ public class PolynomialsUtils {
                 final int den      = 2 * k *  kvw * twoKvwM2;
 
                 return new BigFraction[] {
-                    new BigFraction(twoKvwM1 * (v * v - w * w), den),
-                    new BigFraction(twoKvwM1 * twoKvw * twoKvwM2, den),
-                    new BigFraction(2 * (k + v - 1) * (k + w - 1) * twoKvw, den)
+                    BigFraction.of(twoKvwM1 * (v * v - w * w), den),
+                    BigFraction.of(twoKvwM1 * twoKvw * twoKvwM2, den),
+                    BigFraction.of(2 * (k + v - 1) * (k + w - 1) * twoKvw, den)
                 };
             }
         });