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 2016/05/17 15:49:34 UTC

[01/25] [math] MATH-1335

Repository: commons-math
Updated Branches:
  refs/heads/develop 57e01f404 -> 0e89d6c31


MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/8e71711c
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/8e71711c
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/8e71711c

Branch: refs/heads/develop
Commit: 8e71711c1caaa404d84ec6682f1b7b266064c2e9
Parents: 0caba08
Author: Gilles <er...@apache.org>
Authored: Thu May 12 17:08:28 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/random/StableRandomGenerator.java     | 10 ++++------
 .../commons/math4/random/StableRandomGeneratorTest.java | 12 ++++--------
 2 files changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/8e71711c/src/main/java/org/apache/commons/math4/random/StableRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/StableRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/StableRandomGenerator.java
index a93df01..3199c0f 100644
--- a/src/main/java/org/apache/commons/math4/random/StableRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/StableRandomGenerator.java
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math4.random;
 
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
@@ -33,28 +34,25 @@ import org.apache.commons.math4.util.FastMath;
  */
 public class StableRandomGenerator implements NormalizedRandomGenerator {
     /** Underlying generator. */
-    private final RandomGenerator generator;
-
+    private final UniformRandomProvider generator;
     /** stability parameter */
     private final double alpha;
-
     /** skewness parameter */
     private final double beta;
-
     /** cache of expression value used in generation */
     private final double zeta;
 
     /**
      * Create a new generator.
      *
-     * @param generator underlying random generator to use
+     * @param generator Underlying random generator
      * @param alpha Stability parameter. Must be in range (0, 2]
      * @param beta Skewness parameter. Must be in range [-1, 1]
      * @throws NullArgumentException if generator is null
      * @throws OutOfRangeException if {@code alpha <= 0} or {@code alpha > 2}
      * or {@code beta < -1} or {@code beta > 1}
      */
-    public StableRandomGenerator(final RandomGenerator generator,
+    public StableRandomGenerator(final UniformRandomProvider generator,
                                  final double alpha, final double beta)
         throws NullArgumentException, OutOfRangeException {
         if (generator == null) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/8e71711c/src/test/java/org/apache/commons/math4/random/StableRandomGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/StableRandomGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/StableRandomGeneratorTest.java
index f6c9f3e..5ad14f0 100644
--- a/src/test/java/org/apache/commons/math4/random/StableRandomGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/StableRandomGeneratorTest.java
@@ -17,22 +17,18 @@
 package org.apache.commons.math4.random;
 
 import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.StableRandomGenerator;
-import org.apache.commons.math4.random.Well19937c;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.StatUtils;
 import org.apache.commons.math4.stat.descriptive.DescriptiveStatistics;
 import org.junit.Assert;
 import org.junit.Test;
 
 /**
- * The class <code>StableRandomGeneratorTest</code> contains tests for the class
- * {@link StableRandomGenerator}
- *
+ * Tests for the class {@link StableRandomGenerator}.
  */
 public class StableRandomGeneratorTest {
-
-    private RandomGenerator rg = new Well19937c(100);
+    private final UniformRandomProvider rg = RandomSource.create(RandomSource.WELL_19937_C, 100);
     private final static int sampleSize = 10000;
 
     /**


[23/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a9fdcd64
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a9fdcd64
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a9fdcd64

Branch: refs/heads/develop
Commit: a9fdcd64bf0a982901d298596151d13e56442a11
Parents: b720481
Author: Gilles <er...@apache.org>
Authored: Thu May 12 15:13:06 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/random/GaussianRandomGenerator.java   | 34 +++++++++++---------
 .../MultiStartMultivariateOptimizerTest.java    | 20 +++++-------
 .../CorrelatedRandomVectorGeneratorTest.java    | 16 +++------
 .../random/GaussianRandomGeneratorTest.java     |  9 ++----
 .../UncorrelatedRandomVectorGeneratorTest.java  |  8 ++---
 .../GLSMultipleLinearRegressionTest.java        | 13 ++++----
 6 files changed, 45 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/main/java/org/apache/commons/math4/random/GaussianRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/GaussianRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/GaussianRandomGenerator.java
index f3172c2..c70a7df 100644
--- a/src/main/java/org/apache/commons/math4/random/GaussianRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/GaussianRandomGenerator.java
@@ -17,31 +17,35 @@
 
 package org.apache.commons.math4.random;
 
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.NormalDistribution;
+
 /**
- * This class is a gaussian normalized random generator for scalars.
- * <p>This class is a simple wrapper around the {@link
- * RandomGenerator#nextGaussian} method.</p>
+ * Random generator that generates normally distributed samples.
+ *
  * @since 1.2
  */
-
 public class GaussianRandomGenerator implements NormalizedRandomGenerator {
+    /** Gaussian distribution sampler. */
+    private final RealDistribution.Sampler sampler;
 
-    /** Underlying generator. */
-    private final RandomGenerator generator;
-
-    /** Create a new generator.
-     * @param generator underlying random generator to use
+    /**
+     * Creates a new generator.
+     *
+     * @param generator Underlying random generator.
      */
-    public GaussianRandomGenerator(final RandomGenerator generator) {
-        this.generator = generator;
+    public GaussianRandomGenerator(final UniformRandomProvider generator) {
+        sampler = new NormalDistribution().createSampler(generator);
     }
 
-    /** Generate a random scalar with null mean and unit standard deviation.
-     * @return a random scalar with null mean and unit standard deviation
+    /**
+     * Generates a random scalar with zero mean and unit standard deviation.
+     *
+     * @return a random value sampled from a normal distribution.
      */
     @Override
     public double nextNormalizedDouble() {
-        return generator.nextGaussian();
+        return sampler.sample();
     }
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/MultiStartMultivariateOptimizerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/MultiStartMultivariateOptimizerTest.java b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/MultiStartMultivariateOptimizerTest.java
index cdaf3b9..d5b2b84 100644
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/MultiStartMultivariateOptimizerTest.java
+++ b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/MultiStartMultivariateOptimizerTest.java
@@ -30,8 +30,9 @@ import org.apache.commons.math4.optim.nonlinear.scalar.gradient.CircleScalar;
 import org.apache.commons.math4.optim.nonlinear.scalar.gradient.NonLinearConjugateGradientOptimizer;
 import org.apache.commons.math4.optim.nonlinear.scalar.noderiv.NelderMeadSimplex;
 import org.apache.commons.math4.optim.nonlinear.scalar.noderiv.SimplexOptimizer;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.random.GaussianRandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
 import org.apache.commons.math4.random.RandomVectorGenerator;
 import org.apache.commons.math4.random.UncorrelatedRandomVectorGenerator;
 import org.junit.Assert;
@@ -52,8 +53,7 @@ public class MultiStartMultivariateOptimizerTest {
         GradientMultivariateOptimizer underlying
             = new NonLinearConjugateGradientOptimizer(NonLinearConjugateGradientOptimizer.Formula.POLAK_RIBIERE,
                                                       new SimpleValueChecker(1e-10, 1e-10));
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(753289573253l);
+        UniformRandomProvider g = RandomSource.create(RandomSource.MT_64, 753289573253l);
         RandomVectorGenerator generator
             = new UncorrelatedRandomVectorGenerator(new double[] { 50, 50 },
                                                     new double[] { 10, 10 },
@@ -73,15 +73,12 @@ public class MultiStartMultivariateOptimizerTest {
         for (PointValuePair o : optima) {
             // we check the results of all intermediate restarts here (there are 10 such results)
             Vector2D center = new Vector2D(o.getPointRef()[0], o.getPointRef()[1]);
-            Assert.assertTrue(69.9592 < circle.getRadius(center));
-            Assert.assertTrue(69.9602 > circle.getRadius(center));
-            Assert.assertTrue(96.0745 < center.getX());
-            Assert.assertTrue(96.0762 > center.getX());
-            Assert.assertTrue(48.1344 < center.getY());
-            Assert.assertTrue(48.1354 > center.getY());
+            Assert.assertEquals(69.9597, circle.getRadius(center), 1e-3);
+            Assert.assertEquals(96.07535, center.getX(), 1.4e-3);
+            Assert.assertEquals(48.1349, center.getY(), 5e-3);
         }
 
-        Assert.assertTrue(optimizer.getEvaluations() > 850);
+        Assert.assertTrue(optimizer.getEvaluations() > 800);
         Assert.assertTrue(optimizer.getEvaluations() < 900);
 
         Assert.assertEquals(3.1267527, optimum.getValue(), 1e-8);
@@ -97,8 +94,7 @@ public class MultiStartMultivariateOptimizerTest {
                 { 0.9, 1.2 } ,
                 {  3.5, -2.3 }
             });
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(16069223052l);
+        UniformRandomProvider g = RandomSource.create(RandomSource.MT_64, 16069223052l);
         RandomVectorGenerator generator
             = new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
         int nbStarts = 10;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/test/java/org/apache/commons/math4/random/CorrelatedRandomVectorGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/CorrelatedRandomVectorGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/CorrelatedRandomVectorGeneratorTest.java
index 9b2dd82..18b6543 100644
--- a/src/test/java/org/apache/commons/math4/random/CorrelatedRandomVectorGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/CorrelatedRandomVectorGeneratorTest.java
@@ -25,9 +25,9 @@ import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.random.CorrelatedRandomVectorGenerator;
 import org.apache.commons.math4.random.GaussianRandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
 import org.apache.commons.math4.random.NormalizedRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.correlation.StorelessCovariance;
 import org.apache.commons.math4.stat.descriptive.moment.VectorialCovariance;
 import org.apache.commons.math4.stat.descriptive.moment.VectorialMean;
@@ -61,9 +61,7 @@ public class CorrelatedRandomVectorGeneratorTest {
             }
         }
 
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(17399225432l);
-        GaussianRandomGenerator rawGenerator = new GaussianRandomGenerator(rg);
+        GaussianRandomGenerator rawGenerator = new GaussianRandomGenerator(RandomSource.create(RandomSource.WELL_1024_A, 17399225432l));
         generator = new CorrelatedRandomVectorGenerator(mean,
                                                         covariance,
                                                         1.0e-12 * covariance.getNorm(),
@@ -85,9 +83,7 @@ public class CorrelatedRandomVectorGeneratorTest {
                 { 6, 2, -1, 197 }
         };
         RealMatrix covRM = MatrixUtils.createRealMatrix(cov);
-        JDKRandomGenerator jg = new JDKRandomGenerator();
-        jg.setSeed(5322145245211l);
-        NormalizedRandomGenerator rg = new GaussianRandomGenerator(jg);
+        NormalizedRandomGenerator rg = new GaussianRandomGenerator(RandomSource.create(RandomSource.WELL_1024_A, 5322145245211l));
         CorrelatedRandomVectorGenerator sg =
             new CorrelatedRandomVectorGenerator(mean, covRM, 0.00001, rg);
 
@@ -181,7 +177,7 @@ public class CorrelatedRandomVectorGeneratorTest {
                 new double[cov.length],
                 matrix,
                 small,
-                new GaussianRandomGenerator(new Well1024a(0x366a26b94e520f41l)));
+                new GaussianRandomGenerator(RandomSource.create(RandomSource.WELL_1024_A, 0x366a26b94e520f41l)));
     }
 
     private void testSampler(final double[][] covMatrix, int samples, double epsilon) {
@@ -196,7 +192,5 @@ public class CorrelatedRandomVectorGeneratorTest {
         for (int r = 0; r < covMatrix.length; ++r) {
             TestUtils.assertEquals(covMatrix[r], sampleCov[r], epsilon);
         }
-
     }
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/test/java/org/apache/commons/math4/random/GaussianRandomGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/GaussianRandomGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/GaussianRandomGeneratorTest.java
index 9c46f0d..031f55d 100644
--- a/src/test/java/org/apache/commons/math4/random/GaussianRandomGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/GaussianRandomGeneratorTest.java
@@ -18,8 +18,8 @@
 package org.apache.commons.math4.random;
 
 import org.apache.commons.math4.random.GaussianRandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.StatUtils;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,9 +29,7 @@ public class GaussianRandomGeneratorTest {
 
     @Test
     public void testMeanAndStandardDeviation() {
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(17399225432l);
-        GaussianRandomGenerator generator = new GaussianRandomGenerator(rg);
+        GaussianRandomGenerator generator = new GaussianRandomGenerator(RandomSource.create(RandomSource.MT, 17399225432l));
         double[] sample = new double[10000];
         for (int i = 0; i < sample.length; ++i) {
             sample[i] = generator.nextNormalizedDouble();
@@ -39,5 +37,4 @@ public class GaussianRandomGeneratorTest {
         Assert.assertEquals(0.0, StatUtils.mean(sample), 0.012);
         Assert.assertEquals(1.0, StatUtils.variance(sample), 0.01);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/test/java/org/apache/commons/math4/random/UncorrelatedRandomVectorGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/UncorrelatedRandomVectorGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/UncorrelatedRandomVectorGeneratorTest.java
index bc80769..2c2df9d 100644
--- a/src/test/java/org/apache/commons/math4/random/UncorrelatedRandomVectorGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/UncorrelatedRandomVectorGeneratorTest.java
@@ -18,9 +18,8 @@
 package org.apache.commons.math4.random;
 
 import org.apache.commons.math4.linear.RealMatrix;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.random.GaussianRandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UncorrelatedRandomVectorGenerator;
 import org.apache.commons.math4.stat.descriptive.moment.VectorialCovariance;
 import org.apache.commons.math4.stat.descriptive.moment.VectorialMean;
@@ -35,11 +34,10 @@ public class UncorrelatedRandomVectorGeneratorTest {
     public UncorrelatedRandomVectorGeneratorTest() {
         mean              = new double[] {0.0, 1.0, -3.0, 2.3};
         standardDeviation = new double[] {1.0, 2.0, 10.0, 0.1};
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(17399225432l);
         generator =
             new UncorrelatedRandomVectorGenerator(mean, standardDeviation,
-                    new GaussianRandomGenerator(rg));
+                                                  new GaussianRandomGenerator(RandomSource.create(RandomSource.MT,
+                                                                                                  17399225432l)));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/commons-math/blob/a9fdcd64/src/test/java/org/apache/commons/math4/stat/regression/GLSMultipleLinearRegressionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/regression/GLSMultipleLinearRegressionTest.java b/src/test/java/org/apache/commons/math4/stat/regression/GLSMultipleLinearRegressionTest.java
index 06fbc26..a5b61d1 100644
--- a/src/test/java/org/apache/commons/math4/stat/regression/GLSMultipleLinearRegressionTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/regression/GLSMultipleLinearRegressionTest.java
@@ -27,8 +27,10 @@ import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.linear.RealVector;
 import org.apache.commons.math4.random.CorrelatedRandomVectorGenerator;
 import org.apache.commons.math4.random.GaussianRandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.NormalDistribution;
 import org.apache.commons.math4.stat.correlation.Covariance;
 import org.apache.commons.math4.stat.descriptive.DescriptiveStatistics;
 import org.apache.commons.math4.stat.regression.GLSMultipleLinearRegression;
@@ -220,8 +222,8 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs
      */
     @Test
     public void testGLSEfficiency() {
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(200);  // Seed has been selected to generate non-trivial covariance
+        final UniformRandomProvider rg = RandomSource.create(RandomSource.MT, 123456789L);
+        final RealDistribution.Sampler gauss = new NormalDistribution().createSampler(rg);
 
         // Assume model has 16 observations (will use Longley data).  Start by generating
         // non-constant variances for the 16 error terms.
@@ -237,7 +239,7 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs
         RealMatrix errorSeeds = MatrixUtils.createRealMatrix(numSeeds, nObs);
         for (int i = 0; i < numSeeds; i++) {
             for (int j = 0; j < nObs; j++) {
-                errorSeeds.setEntry(i, j, rg.nextGaussian() * sigma[j]);
+                errorSeeds.setEntry(i, j, gauss.sample() * sigma[j]);
             }
         }
 
@@ -297,5 +299,4 @@ public class GLSMultipleLinearRegressionTest extends MultipleLinearRegressionAbs
         assert(olsBetaStats.getMean() > 1.5 * glsBetaStats.getMean());
         assert(olsBetaStats.getStandardDeviation() > glsBetaStats.getStandardDeviation());
     }
-
 }


[20/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/b7204813
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/b7204813
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/b7204813

Branch: refs/heads/develop
Commit: b720481312289d9fb311caeb4593c10561af317d
Parents: ae7ade3
Author: Gilles <er...@apache.org>
Authored: Thu May 12 14:04:19 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/geometry/enclosing/WelzlEncloser2DTest.java        | 6 +++---
 .../math4/geometry/euclidean/threed/FieldVector3DTest.java   | 7 ++++---
 .../math4/geometry/euclidean/threed/PolyhedronsSetTest.java  | 6 +++---
 .../math4/geometry/euclidean/threed/Vector3DTest.java        | 7 ++++---
 .../twod/hull/ConvexHullGenerator2DAbstractTest.java         | 8 ++++----
 5 files changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/b7204813/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser2DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser2DTest.java b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser2DTest.java
index 3729574..2d39da5 100644
--- a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser2DTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser2DTest.java
@@ -25,8 +25,8 @@ import org.apache.commons.math4.geometry.enclosing.WelzlEncloser;
 import org.apache.commons.math4.geometry.euclidean.twod.DiskGenerator;
 import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
 import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -84,7 +84,7 @@ public class WelzlEncloser2DTest {
 
     @Test
     public void testLargeSamples() {
-        RandomGenerator random = new Well1024a(0xa2a63cad12c01fb2l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 0xa2a63cad12c01fb2l);
         for (int k = 0; k < 100; ++k) {
             int nbPoints = random.nextInt(10000);
             List<Vector2D> points = new ArrayList<Vector2D>();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b7204813/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
index 24e5515..2cf235f 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldVector3DTest.java
@@ -27,7 +27,8 @@ import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.geometry.euclidean.threed.FieldVector3D;
 import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
 import org.junit.Assert;
@@ -592,7 +593,7 @@ public class FieldVector3DTest {
     public void testDotProduct() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(553267312521321234l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 553267312521321237l);
         for (int i = 0; i < 10000; ++i) {
             double ux = 10000 * random.nextDouble();
             double uy = 10000 * random.nextDouble();
@@ -649,7 +650,7 @@ public class FieldVector3DTest {
     public void testCrossProduct() {
         // we compare accurate versus naive cross product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(885362227452043214l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 885362227452043214l);
         for (int i = 0; i < 10000; ++i) {
             double ux = random.nextDouble();
             double uy = random.nextDouble();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b7204813/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java
index b1b902a..c0aaa13 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/PolyhedronsSetTest.java
@@ -50,8 +50,8 @@ import org.apache.commons.math4.geometry.partitioning.RegionDumper;
 import org.apache.commons.math4.geometry.partitioning.RegionFactory;
 import org.apache.commons.math4.geometry.partitioning.RegionParser;
 import org.apache.commons.math4.geometry.partitioning.SubHyperplane;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -440,7 +440,7 @@ public class PolyhedronsSetTest {
     public void testIssue1211() throws IOException, ParseException {
 
         PolyhedronsSet polyset = RegionParser.parsePolyhedronsSet(loadTestData("issue-1211.bsp"));
-        RandomGenerator random = new Well1024a(0xb97c9d1ade21e40al);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 0xb97c9d1ade21e40al);
         int nrays = 1000;
         for (int i = 0; i < nrays; i++) {
             Vector3D origin    = Vector3D.ZERO;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b7204813/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java
index 41b0e3a..f9bf79b 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/Vector3DTest.java
@@ -28,7 +28,8 @@ import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.geometry.Space;
 import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
 import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
 import org.junit.Assert;
@@ -350,7 +351,7 @@ public class Vector3DTest {
     public void testDotProduct() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(553267312521321234l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 553267312521321237l);
         for (int i = 0; i < 10000; ++i) {
             double ux = 10000 * random.nextDouble();
             double uy = 10000 * random.nextDouble();
@@ -392,7 +393,7 @@ public class Vector3DTest {
     public void testCrossProduct() {
         // we compare accurate versus naive cross product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(885362227452043214l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 885362227452043215l);
         for (int i = 0; i < 10000; ++i) {
             double ux = 10000 * random.nextDouble();
             double uy = 10000 * random.nextDouble();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/b7204813/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
index 717b264..ea32b9c 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
@@ -29,8 +29,8 @@ import org.apache.commons.math4.geometry.euclidean.twod.hull.ConvexHull2D;
 import org.apache.commons.math4.geometry.euclidean.twod.hull.ConvexHullGenerator2D;
 import org.apache.commons.math4.geometry.partitioning.Region;
 import org.apache.commons.math4.geometry.partitioning.Region.Location;
-import org.apache.commons.math4.random.MersenneTwister;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.Precision;
@@ -45,7 +45,7 @@ import org.junit.Test;
 public abstract class ConvexHullGenerator2DAbstractTest {
 
     protected ConvexHullGenerator2D generator;
-    protected RandomGenerator random;
+    protected UniformRandomProvider random;
 
     protected abstract ConvexHullGenerator2D createConvexHullGenerator(boolean includeCollinearPoints);
 
@@ -58,7 +58,7 @@ public abstract class ConvexHullGenerator2DAbstractTest {
     public void setUp() {
         // by default, do not include collinear points
         generator = createConvexHullGenerator(false);
-        random = new MersenneTwister(10);
+        random = RandomSource.create(RandomSource.MT, 10);
     }
 
     // ------------------------------------------------------------------------------


[10/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/829a4e9c
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/829a4e9c
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/829a4e9c

Branch: refs/heads/develop
Commit: 829a4e9ce35d43670a7061b957ac951901c31ad3
Parents: 63a9488
Author: Gilles <er...@apache.org>
Authored: Wed May 11 15:03:03 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../random/UnitSphereRandomVectorGenerator.java | 18 +++++++++------
 .../geometry/enclosing/WelzlEncloser3DTest.java |  7 +++---
 .../euclidean/threed/FieldRotationDSTest.java   | 11 +++++-----
 .../euclidean/threed/FieldRotationDfpTest.java  | 11 +++++-----
 .../euclidean/threed/SphereGeneratorTest.java   |  8 +++----
 .../euclidean/twod/DiskGeneratorTest.java       |  6 +++--
 .../geometry/spherical/twod/CircleTest.java     | 10 +++++----
 .../twod/SphericalPolygonsSetTest.java          | 23 +++++++++++++-------
 .../UnitSphereRandomVectorGeneratorTest.java    |  7 +++---
 9 files changed, 59 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java b/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
index 34d66cb..13c42a8 100644
--- a/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/UnitSphereRandomVectorGenerator.java
@@ -17,6 +17,10 @@
 
 package org.apache.commons.math4.random;
 
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.NormalDistribution;
 import org.apache.commons.math4.util.FastMath;
 
 
@@ -28,9 +32,9 @@ import org.apache.commons.math4.util.FastMath;
 public class UnitSphereRandomVectorGenerator
     implements RandomVectorGenerator {
     /**
-     * RNG used for generating the individual components of the vectors.
+     * Sampler used for generating the individual components of the vectors.
      */
-    private final RandomGenerator rand;
+    private final RealDistribution.Sampler rand;
     /**
      * Space dimension.
      */
@@ -38,12 +42,12 @@ public class UnitSphereRandomVectorGenerator
 
     /**
      * @param dimension Space dimension.
-     * @param rand RNG for the individual components of the vectors.
+     * @param rng RNG for the individual components of the vectors.
      */
     public UnitSphereRandomVectorGenerator(final int dimension,
-                                           final RandomGenerator rand) {
+                                           final UniformRandomProvider rng) {
         this.dimension = dimension;
-        this.rand = rand;
+        this.rand = new NormalDistribution().createSampler(rng);
     }
     /**
      * Create an object that will use a default RNG ({@link MersenneTwister}),
@@ -52,7 +56,7 @@ public class UnitSphereRandomVectorGenerator
      * @param dimension Space dimension.
      */
     public UnitSphereRandomVectorGenerator(final int dimension) {
-        this(dimension, new MersenneTwister());
+        this(dimension, RandomSource.create(RandomSource.MT_64));
     }
 
     /** {@inheritDoc} */
@@ -65,7 +69,7 @@ public class UnitSphereRandomVectorGenerator
         // normalizing to unit length.
         double normSq = 0;
         for (int i = 0; i < dimension; i++) {
-            final double comp = rand.nextGaussian();
+            final double comp = rand.sample();
             v[i] = comp;
             normSq += comp * comp;
         }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
index aaa4c43..0860db2 100644
--- a/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/enclosing/WelzlEncloser3DTest.java
@@ -26,9 +26,9 @@ import org.apache.commons.math4.geometry.enclosing.WelzlEncloser;
 import org.apache.commons.math4.geometry.euclidean.threed.Euclidean3D;
 import org.apache.commons.math4.geometry.euclidean.threed.SphereGenerator;
 import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -104,7 +104,8 @@ public class WelzlEncloser3DTest {
 
     @Test
     public void testLargeSamples() throws IOException {
-        RandomGenerator random = new Well1024a(0x35ddecfc78131e1dl);
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                                 0x35ddecfc78131e1dl);
         final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
         for (int k = 0; k < 50; ++k) {
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
index 5b352eb..2398d0d 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDSTest.java
@@ -30,7 +30,8 @@ import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
@@ -959,8 +960,8 @@ public class FieldRotationDSTest {
 
     @Test
     public void testDoubleVectors() throws MathIllegalArgumentException {
-
-        Well1024a random = new Well1024a(0x180b41cfeeffaf67l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0x180b41cfeeffaf67l);
         UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 10; ++i) {
             double[] unit = g.nextVector();
@@ -994,8 +995,8 @@ public class FieldRotationDSTest {
 
     @Test
     public void testDoubleRotations() throws MathIllegalArgumentException {
-
-        Well1024a random = new Well1024a(0x180b41cfeeffaf67l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0x180b41cfeeffaf67l);
         UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 10; ++i) {
             double[] unit1 = g.nextVector();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
index e7df1b0..6dde9f3 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/FieldRotationDfpTest.java
@@ -29,7 +29,8 @@ import org.apache.commons.math4.geometry.euclidean.threed.Rotation;
 import org.apache.commons.math4.geometry.euclidean.threed.RotationOrder;
 import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
@@ -800,8 +801,8 @@ public class FieldRotationDfpTest {
 
     @Test
     public void testDoubleVectors() throws MathIllegalArgumentException {
-
-        Well1024a random = new Well1024a(0x180b41cfeeffaf67l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0x180b41cfeeffaf67l);
         UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 10; ++i) {
             double[] unit = g.nextVector();
@@ -835,9 +836,9 @@ public class FieldRotationDfpTest {
 
     @Test
     public void testDoubleRotations() throws MathIllegalArgumentException {
-
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0x180b41cfeeffaf67l);
         DfpField field = new DfpField(20);
-        Well1024a random = new Well1024a(0x180b41cfeeffaf67l);
         UnitSphereRandomVectorGenerator g = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 10; ++i) {
             double[] unit1 = g.nextVector();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
index 5fdc4f6..8fd36dc 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/threed/SphereGeneratorTest.java
@@ -24,9 +24,9 @@ import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
 import org.apache.commons.math4.geometry.euclidean.threed.Euclidean3D;
 import org.apache.commons.math4.geometry.euclidean.threed.SphereGenerator;
 import org.apache.commons.math4.geometry.euclidean.threed.Vector3D;
-import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -137,7 +137,8 @@ public class SphereGeneratorTest {
 
     @Test
     public void testRandom() {
-        final RandomGenerator random = new Well1024a(0xd015982e9f31ee04l);
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                                 0xd015982e9f31ee04l);
         final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 100; ++i) {
             double d = 25 * random.nextDouble();
@@ -151,7 +152,6 @@ public class SphereGeneratorTest {
             Assert.assertEquals(0.0, refCenter.distance(sphere.getCenter()), 4e-7 * refRadius);
             Assert.assertEquals(refRadius, sphere.getRadius(), 1e-7 * refRadius);
         }
-
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
index 5ca9295..94b1ffb 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
@@ -26,7 +26,8 @@ import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
 import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
 import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -102,7 +103,8 @@ public class DiskGeneratorTest {
 
     @Test
     public void testRandom() {
-        final RandomGenerator random = new Well1024a(0x12faa818373ffe90l);
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                                 0x12faa818373ffe90l);
         final UnitSphereRandomVectorGenerator sr = new UnitSphereRandomVectorGenerator(2, random);
         for (int i = 0; i < 500; ++i) {
             double d = 25 * random.nextDouble();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
index 352bdd9..29b1d57 100644
--- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
@@ -30,7 +30,8 @@ import org.apache.commons.math4.geometry.spherical.twod.S2Point;
 import org.apache.commons.math4.geometry.spherical.twod.Sphere2D;
 import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
@@ -135,8 +136,8 @@ public class CircleTest {
 
     @Test
     public void testInsideArc() {
-        RandomGenerator random = new Well1024a(0xbfd34e92231bbcfel);
-        UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
+        UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                                                               0xbfd34e92231bbcfel));
         for (int i = 0; i < 100; ++i) {
             Circle c1 = new Circle(new Vector3D(sphRandom.nextVector()), 1.0e-10);
             Circle c2 = new Circle(new Vector3D(sphRandom.nextVector()), 1.0e-10);
@@ -158,7 +159,8 @@ public class CircleTest {
 
     @Test
     public void testTransform() {
-        RandomGenerator random = new Well1024a(0x16992fc4294bf2f1l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0x16992fc4294bf2f1l);
         UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
         for (int i = 0; i < 100; ++i) {
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
index e9fbe47..b8480ec 100644
--- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/SphericalPolygonsSetTest.java
@@ -35,7 +35,7 @@ import org.apache.commons.math4.geometry.spherical.twod.SphericalPolygonsSet;
 import org.apache.commons.math4.geometry.spherical.twod.SubCircle;
 import org.apache.commons.math4.geometry.spherical.twod.Vertex;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
@@ -47,7 +47,8 @@ public class SphericalPolygonsSetTest {
     public void testFullSphere() {
         SphericalPolygonsSet full = new SphericalPolygonsSet(1.0e-10);
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0x852fd2a0ed8d2f6dl));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0x852fd2a0ed8d2f6dl));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v)));
@@ -64,7 +65,8 @@ public class SphericalPolygonsSetTest {
         SphericalPolygonsSet empty =
             (SphericalPolygonsSet) new RegionFactory<Sphere2D>().getComplement(new SphericalPolygonsSet(1.0e-10));
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0x76d9205d6167b6ddl));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0x76d9205d6167b6ddl));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             Assert.assertEquals(Location.OUTSIDE, empty.checkPoint(new S2Point(v)));
@@ -82,7 +84,8 @@ public class SphericalPolygonsSetTest {
         double sinTol = FastMath.sin(tol);
         SphericalPolygonsSet south = new SphericalPolygonsSet(Vector3D.MINUS_K, tol);
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0x6b9d4a6ad90d7b0bl));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0x6b9d4a6ad90d7b0bl));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             if (v.getZ() < -sinTol) {
@@ -117,7 +120,8 @@ public class SphericalPolygonsSetTest {
         SphericalPolygonsSet octant =
                 (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ);
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0x9c9802fde3cbcf25l));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0x9c9802fde3cbcf25l));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
@@ -181,7 +185,8 @@ public class SphericalPolygonsSetTest {
         double sinTol = FastMath.sin(tol);
         SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0xb8fc5acc91044308l));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
@@ -206,7 +211,8 @@ public class SphericalPolygonsSetTest {
                 (SphericalPolygonsSet) factory.difference(plusZ, factory.intersection(plusX, plusY));
 
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0x9c9802fde3cbcf25l));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0x9c9802fde3cbcf25l));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             if (((v.getX() < -sinTol) || (v.getY() < -sinTol)) && (v.getZ() > sinTol)) {
@@ -339,7 +345,8 @@ public class SphericalPolygonsSetTest {
         SphericalPolygonsSet polygon = new SphericalPolygonsSet(boundary, tol);
 
         UnitSphereRandomVectorGenerator random =
-                new UnitSphereRandomVectorGenerator(3, new Well1024a(0xcc5ce49949e0d3ecl));
+                new UnitSphereRandomVectorGenerator(3, RandomSource.create(RandomSource.WELL_1024_A,
+                                                                           0xcc5ce49949e0d3ecl));
         for (int i = 0; i < 1000; ++i) {
             Vector3D v = new Vector3D(random.nextVector());
             if ((v.getX() < -sinTol) && (v.getY() < -sinTol) && (v.getZ() < -sinTol)) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/829a4e9c/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
index 453de34..e5ab5bb 100644
--- a/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/UnitSphereRandomVectorGeneratorTest.java
@@ -16,8 +16,8 @@
  */
 package org.apache.commons.math4.random;
 
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
@@ -31,8 +31,7 @@ public class UnitSphereRandomVectorGeneratorTest {
     @Test
     public void test2DDistribution() {
 
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(17399225432l);
+        UniformRandomProvider rg = RandomSource.create(RandomSource.XOR_SHIFT_1024_S, 17399225432L);
         UnitSphereRandomVectorGenerator generator = new UnitSphereRandomVectorGenerator(2, rg);
 
         // In 2D, angles with a given vector should be uniformly distributed


[08/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/11409e62
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/11409e62
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/11409e62

Branch: refs/heads/develop
Commit: 11409e628b0461be3c268f81642ce36bc4b0bf84
Parents: 0c9af5f
Author: Gilles <er...@apache.org>
Authored: Wed May 11 14:06:15 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../nonlinear/scalar/noderiv/CMAESOptimizer.java  | 18 ++++++++++--------
 .../scalar/noderiv/CMAESOptimizerTest.java        |  8 ++++----
 2 files changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/11409e62/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
index 727fd18..8fe9afe 100644
--- a/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
+++ b/src/main/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizer.java
@@ -35,7 +35,9 @@ import org.apache.commons.math4.optim.OptimizationData;
 import org.apache.commons.math4.optim.PointValuePair;
 import org.apache.commons.math4.optim.nonlinear.scalar.GoalType;
 import org.apache.commons.math4.optim.nonlinear.scalar.MultivariateOptimizer;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.distribution.RealDistribution;
+import org.apache.commons.math4.distribution.NormalDistribution;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 
@@ -195,8 +197,8 @@ public class CMAESOptimizer
     /** Size of history queue of best values. */
     private int historySize;
 
-    /** Random generator. */
-    private final RandomGenerator random;
+    /** Gaussian sampler. */
+    private final RealDistribution.Sampler random;
 
     /** History of sigma values. */
     private final List<Double> statisticsSigmaHistory = new ArrayList<Double>();
@@ -216,7 +218,7 @@ public class CMAESOptimizer
      * remains diagonal.
      * @param checkFeasableCount Determines how often new random objective variables are
      * generated in case they are out of bounds.
-     * @param random Random generator.
+     * @param rng Random generator.
      * @param generateStatistics Whether statistic data is collected.
      * @param checker Convergence checker.
      *
@@ -227,7 +229,7 @@ public class CMAESOptimizer
                           boolean isActiveCMA,
                           int diagonalOnly,
                           int checkFeasableCount,
-                          RandomGenerator random,
+                          UniformRandomProvider rng,
                           boolean generateStatistics,
                           ConvergenceChecker<PointValuePair> checker) {
         super(checker);
@@ -236,7 +238,7 @@ public class CMAESOptimizer
         this.isActiveCMA = isActiveCMA;
         this.diagonalOnly = diagonalOnly;
         this.checkFeasableCount = checkFeasableCount;
-        this.random = random;
+        this.random = new NormalDistribution().createSampler(rng);
         this.generateStatistics = generateStatistics;
     }
 
@@ -1335,7 +1337,7 @@ public class CMAESOptimizer
     private double[] randn(int size) {
         final double[] randn = new double[size];
         for (int i = 0; i < size; i++) {
-            randn[i] = random.nextGaussian();
+            randn[i] = random.sample();
         }
         return randn;
     }
@@ -1349,7 +1351,7 @@ public class CMAESOptimizer
         final double[][] d = new double[size][popSize];
         for (int r = 0; r < size; r++) {
             for (int c = 0; c < popSize; c++) {
-                d[r][c] = random.nextGaussian();
+                d[r][c] = random.sample();
             }
         }
         return new Array2DRowRealMatrix(d, false);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/11409e62/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
index 51617d6..50cf6dc 100644
--- a/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
+++ b/src/test/java/org/apache/commons/math4/optim/nonlinear/scalar/noderiv/CMAESOptimizerTest.java
@@ -34,7 +34,7 @@ import org.apache.commons.math4.optim.SimpleBounds;
 import org.apache.commons.math4.optim.nonlinear.scalar.GoalType;
 import org.apache.commons.math4.optim.nonlinear.scalar.ObjectiveFunction;
 import org.apache.commons.math4.optim.nonlinear.scalar.noderiv.CMAESOptimizer;
-import org.apache.commons.math4.random.MersenneTwister;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -368,7 +368,7 @@ public class CMAESOptimizerTest {
     public void testMath864() {
         final CMAESOptimizer optimizer
             = new CMAESOptimizer(30000, 0, true, 10,
-                                 0, new MersenneTwister(), false, null);
+                                 0, RandomSource.create(RandomSource.MT_64), false, null);
         final MultivariateFunction fitnessFunction = new MultivariateFunction() {
                 public double value(double[] parameters) {
                     final double target = 1;
@@ -399,7 +399,7 @@ public class CMAESOptimizerTest {
     public void testFitAccuracyDependsOnBoundary() {
         final CMAESOptimizer optimizer
             = new CMAESOptimizer(30000, 0, true, 10,
-                                 0, new MersenneTwister(), false, null);
+                                 0, RandomSource.create(RandomSource.MT_64), false, null);
         final MultivariateFunction fitnessFunction = new MultivariateFunction() {
                 public double value(double[] parameters) {
                     final double target = 11.1;
@@ -486,7 +486,7 @@ public class CMAESOptimizerTest {
         int dim = startPoint.length;
         // test diagonalOnly = 0 - slow but normally fewer feval#
         CMAESOptimizer optim = new CMAESOptimizer(30000, stopValue, isActive, diagonalOnly,
-                                                  0, new MersenneTwister(), false, null);
+                                                  0, RandomSource.create(RandomSource.MT_64), false, null);
         PointValuePair result = boundaries == null ?
             optim.optimize(new MaxEval(maxEvaluations),
                            new ObjectiveFunction(func),


[14/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f9f632e7
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f9f632e7
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f9f632e7

Branch: refs/heads/develop
Commit: f9f632e7056cd9d2b3c88bad50fe0597610e2eca
Parents: 0484bdb
Author: Gilles <er...@apache.org>
Authored: Thu May 12 12:43:04 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/filter/KalmanFilterTest.java   | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f9f632e7/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java b/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
index 2db564d..131da51 100644
--- a/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
+++ b/src/test/java/org/apache/commons/math4/filter/KalmanFilterTest.java
@@ -27,9 +27,6 @@ import org.apache.commons.math4.linear.MatrixDimensionMismatchException;
 import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.linear.RealVector;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
@@ -129,19 +126,20 @@ public class KalmanFilterTest {
         RealVector pNoise = new ArrayRealVector(1);
         RealVector mNoise = new ArrayRealVector(1);
 
-        RandomGenerator rand = new JDKRandomGenerator();
+        final RealDistribution.Sampler rand = new NormalDistribution().createSampler(RandomSource.create(RandomSource.WELL_19937_C));
+
         // iterate 60 steps
         for (int i = 0; i < 60; i++) {
             filter.predict();
 
             // Simulate the process
-            pNoise.setEntry(0, processNoise * rand.nextGaussian());
+            pNoise.setEntry(0, processNoise * rand.sample());
 
             // x = A * x + p_noise
             x = A.operate(x).add(pNoise);
 
             // Simulate the measurement
-            mNoise.setEntry(0, measurementNoise * rand.nextGaussian());
+            mNoise.setEntry(0, measurementNoise * rand.sample());
 
             // z = H * x + m_noise
             RealVector z = H.operate(x).add(mNoise);
@@ -217,7 +215,7 @@ public class KalmanFilterTest {
         double[] expectedInitialState = new double[] { 0.0, 0.0 };
         assertVectorEquals(expectedInitialState, filter.getStateEstimation());
 
-        RandomGenerator rand = new JDKRandomGenerator();
+        final RealDistribution.Sampler rand = new NormalDistribution().createSampler(RandomSource.create(RandomSource.WELL_19937_C));
 
         RealVector tmpPNoise = new ArrayRealVector(
                 new double[] { FastMath.pow(dt, 2d) / 2d, dt });
@@ -227,13 +225,13 @@ public class KalmanFilterTest {
             filter.predict(u);
 
             // Simulate the process
-            RealVector pNoise = tmpPNoise.mapMultiply(accelNoise * rand.nextGaussian());
+            RealVector pNoise = tmpPNoise.mapMultiply(accelNoise * rand.sample());
 
             // x = A * x + B * u + pNoise
             x = A.operate(x).add(B.operate(u)).add(pNoise);
 
             // Simulate the measurement
-            double mNoise = measurementNoise * rand.nextGaussian();
+            double mNoise = measurementNoise * rand.sample();
 
             // z = H * x + m_noise
             RealVector z = H.operate(x).mapAdd(mNoise);
@@ -394,8 +392,7 @@ public class KalmanFilterTest {
         final MeasurementModel mm = new DefaultMeasurementModel(H, R);
         final KalmanFilter filter = new KalmanFilter(pm, mm);
 
-        final UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_19937_C, 1000);
-        final RealDistribution.Sampler dist = new NormalDistribution(0, measurementNoise).createSampler(rng);
+        final RealDistribution.Sampler dist = new NormalDistribution(0, measurementNoise).createSampler(RandomSource.create(RandomSource.WELL_19937_C, 1000));
 
         for (int i = 0; i < iterations; i++) {
             // get the "real" cannonball position


[25/25] [math] Merge branch 'task-MATH-1360' into develop

Posted by er...@apache.org.
Merge branch 'task-MATH-1360' into develop

Completes issue MATH-1360 (see JIRA).


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0e89d6c3
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0e89d6c3
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0e89d6c3

Branch: refs/heads/develop
Commit: 0e89d6c31f1585e7976c891b65322e5562299e15
Parents: 57e01f4 8e71711
Author: Gilles <er...@apache.org>
Authored: Tue May 17 17:02:00 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 17:02:00 2016 +0200

----------------------------------------------------------------------
 .../math4/genetics/GeneticAlgorithm.java        | 18 +++++-----
 .../commons/math4/genetics/NPointCrossover.java |  4 +--
 .../math4/genetics/OrderedCrossover.java        |  4 +--
 .../math4/genetics/UniformCrossover.java        |  4 +--
 .../ml/clustering/FuzzyKMeansClusterer.java     | 12 +++----
 .../ml/clustering/KMeansPlusPlusClusterer.java  | 14 ++++----
 .../scalar/noderiv/CMAESOptimizer.java          | 18 +++++-----
 .../MultiStartUnivariateOptimizer.java          |  6 ++--
 .../math4/random/GaussianRandomGenerator.java   | 34 ++++++++++--------
 .../math4/random/StableRandomGenerator.java     | 10 +++---
 .../math4/random/UniformRandomGenerator.java    | 36 +++++++++++---------
 .../random/UnitSphereRandomVectorGenerator.java | 18 ++++++----
 .../math4/util/RandomPivotingStrategy.java      |  6 ++--
 .../math4/ExtendedFieldElementAbstractTest.java | 22 ++++++------
 .../DerivativeStructureTest.java                |  7 ++--
 .../differentiation/SparseGradientTest.java     |  9 +++--
 .../math4/analysis/function/LogitTest.java      | 13 ++++---
 .../distribution/BetaDistributionTest.java      |  3 --
 .../commons/math4/filter/KalmanFilterTest.java  | 19 +++++------
 .../geometry/enclosing/WelzlEncloser2DTest.java |  6 ++--
 .../geometry/enclosing/WelzlEncloser3DTest.java |  7 ++--
 .../euclidean/threed/FieldRotationDSTest.java   | 11 +++---
 .../euclidean/threed/FieldRotationDfpTest.java  | 11 +++---
 .../euclidean/threed/FieldVector3DTest.java     |  7 ++--
 .../euclidean/threed/PolyhedronsSetTest.java    |  6 ++--
 .../euclidean/threed/SphereGeneratorTest.java   |  8 ++---
 .../geometry/euclidean/threed/Vector3DTest.java |  7 ++--
 .../euclidean/twod/DiskGeneratorTest.java       |  7 ++--
 .../hull/ConvexHullGenerator2DAbstractTest.java |  8 ++---
 .../geometry/spherical/twod/CircleTest.java     | 11 +++---
 .../twod/SphericalPolygonsSetTest.java          | 23 ++++++++-----
 .../ml/clustering/FuzzyKMeansClustererTest.java |  6 ++--
 .../clustering/KMeansPlusPlusClustererTest.java | 11 +++---
 .../math4/ode/events/EventFilterTest.java       |  6 ++--
 .../MultiStartMultivariateOptimizerTest.java    | 20 +++++------
 .../scalar/noderiv/CMAESOptimizerTest.java      |  8 ++---
 .../MultiStartUnivariateOptimizerTest.java      | 23 +++++--------
 .../CorrelatedRandomVectorGeneratorTest.java    | 16 +++------
 .../random/GaussianRandomGeneratorTest.java     |  9 ++---
 .../math4/random/StableRandomGeneratorTest.java | 12 +++----
 .../UncorrelatedRandomVectorGeneratorTest.java  |  8 ++---
 .../random/UniformRandomGeneratorTest.java      |  8 ++---
 .../UnitSphereRandomVectorGeneratorTest.java    |  7 ++--
 .../correlation/KendallsCorrelationTest.java    |  6 ++--
 .../correlation/StorelessCovarianceTest.java    |  5 +--
 .../descriptive/rank/PSquarePercentileTest.java |  5 ++-
 .../stat/descriptive/rank/PercentileTest.java   |  5 ++-
 .../GLSMultipleLinearRegressionTest.java        | 13 +++----
 .../stat/regression/SimpleRegressionTest.java   |  5 +--
 .../commons/math4/util/ArithmeticUtilsTest.java | 18 ++++------
 .../apache/commons/math4/util/FastMathTest.java | 15 ++++----
 .../commons/math4/util/MathArraysTest.java      |  5 +--
 .../commons/math4/util/MathUtilsTest.java       | 15 ++++----
 53 files changed, 293 insertions(+), 302 deletions(-)
----------------------------------------------------------------------



[04/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.

Unit tests rewritten to avoid unnecessary usage of "RandomDataGenerator" (cf. MATH-1341).


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0484bdb3
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0484bdb3
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0484bdb3

Branch: refs/heads/develop
Commit: 0484bdb3f61d309ff62da4df4be92cf139d19f6b
Parents: 11a7e62
Author: Gilles <er...@apache.org>
Authored: Wed May 11 17:26:37 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/util/ArithmeticUtilsTest.java   | 18 ++++++------------
 .../apache/commons/math4/util/MathUtilsTest.java  | 15 ++++++++-------
 2 files changed, 14 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0484bdb3/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java b/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
index fece225..2de8ee1 100644
--- a/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/util/ArithmeticUtilsTest.java
@@ -22,8 +22,6 @@ import java.math.BigInteger;
 
 import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.random.RandomDataGenerator;
-import org.apache.commons.math4.util.ArithmeticUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -125,17 +123,13 @@ public class ArithmeticUtilsTest {
     @Test
     public void testGcdConsistency() {
         int[] primeList = {19, 23, 53, 67, 73, 79, 101, 103, 111, 131};
-        ArrayList<Integer> primes = new ArrayList<Integer>();
-        for (int i = 0; i < primeList.length; i++) {
-            primes.add(Integer.valueOf(primeList[i]));
-        }
-        RandomDataGenerator randomData = new RandomDataGenerator();
+
         for (int i = 0; i < 20; i++) {
-            Object[] sample = randomData.nextSample(primes, 4);
-            int p1 = ((Integer) sample[0]).intValue();
-            int p2 = ((Integer) sample[1]).intValue();
-            int p3 = ((Integer) sample[2]).intValue();
-            int p4 = ((Integer) sample[3]).intValue();
+            MathArrays.shuffle(primeList);
+            int p1 = primeList[0];
+            int p2 = primeList[1];
+            int p3 = primeList[2];
+            int p4 = primeList[3];
             int i1 = p1 * p2 * p3;
             int i2 = p1 * p2 * p4;
             int gcd = p1 * p2;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0484bdb3/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
index 8ce9a2d..f83476f 100644
--- a/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathUtilsTest.java
@@ -19,10 +19,8 @@ import org.apache.commons.math4.exception.MathArithmeticException;
 import org.apache.commons.math4.exception.NotFiniteNumberException;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.RandomDataGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
-import org.apache.commons.math4.util.FastMath;
-import org.apache.commons.math4.util.MathUtils;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -97,23 +95,26 @@ public final class MathUtilsTest {
     public void testPermutedArrayHash() {
         double[] original = new double[10];
         double[] permuted = new double[10];
-        RandomDataGenerator random = new RandomDataGenerator();
+
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_512_A,
+                                                                 64925784252L);
 
         // Generate 10 distinct random values
         for (int i = 0; i < 10; i++) {
             final RealDistribution.Sampler u
-                = new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(RandomSource.create(RandomSource.WELL_512_A,
-                                                                                                   64925784252L));
+                = new UniformRealDistribution(i + 0.5, i + 0.75).createSampler(random);
             original[i] = u.sample();
         }
 
         // Generate a random permutation, making sure it is not the identity
         boolean isIdentity = true;
         do {
-            int[] permutation = random.nextPermutation(10, 10);
+            int[] permutation = MathArrays.natural(10);
+            MathArrays.shuffle(permutation, random);
             for (int i = 0; i < 10; i++) {
                 if (i != permutation[i]) {
                     isIdentity = false;
+                    break;
                 }
                 permuted[i] = original[permutation[i]];
             }


[21/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/11a7e62a
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/11a7e62a
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/11a7e62a

Branch: refs/heads/develop
Commit: 11a7e62a898e54d66936d1b8b67cb5e62578ba98
Parents: 7331773
Author: Gilles <er...@apache.org>
Authored: Wed May 11 16:53:19 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/math4/util/FastMathTest.java  | 15 ++++++++-------
 .../apache/commons/math4/util/MathArraysTest.java    |  5 +++--
 2 files changed, 11 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/11a7e62a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/FastMathTest.java b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
index 26c1cd9..cc95c9c 100644
--- a/src/test/java/org/apache/commons/math4/util/FastMathTest.java
+++ b/src/test/java/org/apache/commons/math4/util/FastMathTest.java
@@ -28,9 +28,8 @@ import org.apache.commons.math4.dfp.Dfp;
 import org.apache.commons.math4.dfp.DfpField;
 import org.apache.commons.math4.dfp.DfpMath;
 import org.apache.commons.math4.exception.MathArithmeticException;
-import org.apache.commons.math4.random.MersenneTwister;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.Precision;
 import org.junit.Assert;
@@ -45,12 +44,12 @@ public class FastMathTest {
 
 
     private DfpField field;
-    private RandomGenerator generator;
+    private UniformRandomProvider generator;
 
     @Before
     public void setUp() {
         field = new DfpField(40);
-        generator = new MersenneTwister(6176597458463500194l);
+        generator = RandomSource.create(RandomSource.MT, 6176597458463500194l);
     }
 
     @Test
@@ -1914,7 +1913,8 @@ public class FastMathTest {
 
     @Test
     public void testFloorDivModInt() {
-        RandomGenerator generator = new Well1024a(0x7ccab45edeaab90al);
+        UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A,
+                                                              0x7ccab45edeaab90al);
         for (int i = 0; i < 10000; ++i) {
             int a = generator.nextInt();
             int b = generator.nextInt();
@@ -1986,7 +1986,8 @@ public class FastMathTest {
 
     @Test
     public void testFloorDivModLong() {
-        RandomGenerator generator = new Well1024a(0xb87b9bc14c96ccd5l);
+        UniformRandomProvider generator = RandomSource.create(RandomSource.WELL_1024_A,
+                                                              0xb87b9bc14c96ccd5l);
         for (int i = 0; i < 10000; ++i) {
             long a = generator.nextLong();
             long b = generator.nextLong();

http://git-wip-us.apache.org/repos/asf/commons-math/blob/11a7e62a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
index d0b635c..05de1b0 100644
--- a/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
+++ b/src/test/java/org/apache/commons/math4/util/MathArraysTest.java
@@ -25,8 +25,8 @@ import org.apache.commons.math4.exception.NotANumberException;
 import org.apache.commons.math4.exception.NotPositiveException;
 import org.apache.commons.math4.exception.NotStrictlyPositiveException;
 import org.apache.commons.math4.exception.NullArgumentException;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
-import org.apache.commons.math4.random.Well1024a;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.Precision;
@@ -762,7 +762,8 @@ public class MathArraysTest {
     public void testLinearCombination2() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(553267312521321234l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.XOR_SHIFT_1024_S,
+                                                           553267312521321234l);
 
         for (int i = 0; i < 10000; ++i) {
             final double ux = 1e17 * random.nextDouble();


[09/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.

Unrelated code comments removed in unit test.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/63a9488f
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/63a9488f
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/63a9488f

Branch: refs/heads/develop
Commit: 63a9488f2910434851e98a8fc0ec8c053b24083b
Parents: 11409e6
Author: Gilles <er...@apache.org>
Authored: Wed May 11 14:25:36 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../MultiStartUnivariateOptimizer.java          |  6 ++---
 .../MultiStartUnivariateOptimizerTest.java      | 23 +++++++-------------
 2 files changed, 11 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/63a9488f/src/main/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizer.java b/src/main/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizer.java
index 5383a52..65bfa67 100644
--- a/src/main/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizer.java
+++ b/src/main/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizer.java
@@ -26,7 +26,7 @@ import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.optim.MaxEval;
 import org.apache.commons.math4.optim.OptimizationData;
 import org.apache.commons.math4.optim.nonlinear.scalar.GoalType;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * Special implementation of the {@link UnivariateOptimizer} interface
@@ -47,7 +47,7 @@ public class MultiStartUnivariateOptimizer
     /** Number of starts to go. */
     private final int starts;
     /** Random generator for multi-start. */
-    private final RandomGenerator generator;
+    private final UniformRandomProvider generator;
     /** Found optima. */
     private UnivariatePointValuePair[] optima;
     /** Optimization data. */
@@ -75,7 +75,7 @@ public class MultiStartUnivariateOptimizer
      */
     public MultiStartUnivariateOptimizer(final UnivariateOptimizer optimizer,
                                          final int starts,
-                                         final RandomGenerator generator) {
+                                         final UniformRandomProvider generator) {
         super(optimizer.getConvergenceChecker());
 
         if (starts < 1) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/63a9488f/src/test/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizerTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizerTest.java b/src/test/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizerTest.java
index ec8ec06..a452ac8 100644
--- a/src/test/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizerTest.java
+++ b/src/test/java/org/apache/commons/math4/optim/univariate/MultiStartUnivariateOptimizerTest.java
@@ -28,7 +28,8 @@ import org.apache.commons.math4.optim.univariate.SearchInterval;
 import org.apache.commons.math4.optim.univariate.UnivariateObjectiveFunction;
 import org.apache.commons.math4.optim.univariate.UnivariateOptimizer;
 import org.apache.commons.math4.optim.univariate.UnivariatePointValuePair;
-import org.apache.commons.math4.random.JDKRandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -37,8 +38,7 @@ public class MultiStartUnivariateOptimizerTest {
     @Test(expected=MathIllegalStateException.class)
     public void testMissingMaxEval() {
         UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(44428400075l);
+        UniformRandomProvider g = RandomSource.create(RandomSource.TWO_CMRES, 44428400075l);
         MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
         optimizer.optimize(new UnivariateObjectiveFunction(new Sin()),
                            GoalType.MINIMIZE,
@@ -47,8 +47,7 @@ public class MultiStartUnivariateOptimizerTest {
     @Test(expected=MathIllegalStateException.class)
     public void testMissingSearchInterval() {
         UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(44428400075l);
+        UniformRandomProvider g = RandomSource.create(RandomSource.TWO_CMRES, 44428400075l);
         MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
         optimizer.optimize(new MaxEval(300),
                            new UnivariateObjectiveFunction(new Sin()),
@@ -59,8 +58,7 @@ public class MultiStartUnivariateOptimizerTest {
     public void testSinMin() {
         UnivariateFunction f = new Sin();
         UnivariateOptimizer underlying = new BrentOptimizer(1e-10, 1e-14);
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(44428400075l);
+        UniformRandomProvider g = RandomSource.create(RandomSource.TWO_CMRES, 44428400075l);
         MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 10, g);
         optimizer.optimize(new MaxEval(300),
                            new UnivariateObjectiveFunction(f),
@@ -79,12 +77,9 @@ public class MultiStartUnivariateOptimizerTest {
 
     @Test
     public void testQuinticMin() {
-        // The quintic function has zeros at 0, +-0.5 and +-1.
-        // The function has extrema (first derivative is zero) at 0.27195613 and 0.82221643,
         UnivariateFunction f = new QuinticFunction();
         UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(4312000053L);
+        UniformRandomProvider g = RandomSource.create(RandomSource.TWO_CMRES, 4312000053L);
         MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 5, g);
 
         UnivariatePointValuePair optimum
@@ -92,7 +87,7 @@ public class MultiStartUnivariateOptimizerTest {
                                  new UnivariateObjectiveFunction(f),
                                  GoalType.MINIMIZE,
                                  new SearchInterval(-0.3, -0.2));
-        Assert.assertEquals(-0.27195613, optimum.getPoint(), 1e-9);
+        Assert.assertEquals(-0.271956128, optimum.getPoint(), 1e-9);
         Assert.assertEquals(-0.0443342695, optimum.getValue(), 1e-9);
 
         UnivariatePointValuePair[] optima = optimizer.getOptima();
@@ -114,8 +109,7 @@ public class MultiStartUnivariateOptimizerTest {
                 }
             };
         UnivariateOptimizer underlying = new BrentOptimizer(1e-9, 1e-14);
-        JDKRandomGenerator g = new JDKRandomGenerator();
-        g.setSeed(4312000053L);
+        UniformRandomProvider g = RandomSource.create(RandomSource.TWO_CMRES, 4312000053L);
         MultiStartUnivariateOptimizer optimizer = new MultiStartUnivariateOptimizer(underlying, 5, g);
 
         try {
@@ -135,5 +129,4 @@ public class MultiStartUnivariateOptimizerTest {
     private static class LocalException extends RuntimeException {
         private static final long serialVersionUID = 1194682757034350629L;
     }
-
 }


[22/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/1b5aef88
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/1b5aef88
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/1b5aef88

Branch: refs/heads/develop
Commit: 1b5aef881bb3acdcde5d9fcbb6e43ceed6db145d
Parents: 022a020
Author: Gilles <er...@apache.org>
Authored: Thu May 12 16:32:18 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/stat/descriptive/rank/PSquarePercentileTest.java      | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/1b5aef88/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
index 52cea33..042e2fd 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PSquarePercentileTest.java
@@ -31,8 +31,7 @@ import org.apache.commons.math4.distribution.AbstractRealDistribution;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well19937c;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.descriptive.StorelessUnivariateStatistic;
 import org.apache.commons.math4.stat.descriptive.StorelessUnivariateStatisticAbstractTest;
@@ -55,7 +54,7 @@ public class PSquarePercentileTest extends
     protected double percentile95 = 16.72195;// 20.82d; this is approximation
     protected double tolerance = 10E-12;
 
-    private final RandomGenerator randomGenerator = new Well19937c(1000);
+    private final UniformRandomProvider randomGenerator = RandomSource.create(RandomSource.WELL_19937_C, 1000);
 
     @Override
     public double getTolerance() {


[19/25] [math] Unused "import".

Posted by er...@apache.org.
Unused "import".


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ae7ade39
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ae7ade39
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ae7ade39

Branch: refs/heads/develop
Commit: ae7ade39901e3323fa1a0f3d3d62fc9542802dd6
Parents: f3108e2
Author: Gilles <er...@apache.org>
Authored: Thu May 12 14:03:51 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../apache/commons/math4/geometry/spherical/twod/CircleTest.java    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ae7ade39/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
index 29b1d57..c3b14ad 100644
--- a/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/spherical/twod/CircleTest.java
@@ -28,7 +28,6 @@ import org.apache.commons.math4.geometry.spherical.oned.SubLimitAngle;
 import org.apache.commons.math4.geometry.spherical.twod.Circle;
 import org.apache.commons.math4.geometry.spherical.twod.S2Point;
 import org.apache.commons.math4.geometry.spherical.twod.Sphere2D;
-import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
 import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;


[12/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/d7073642
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/d7073642
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/d7073642

Branch: refs/heads/develop
Commit: d70736425701b66bd64ad3aab3941bb930a18b66
Parents: ed78ce2
Author: Gilles <er...@apache.org>
Authored: Wed May 11 16:15:29 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/analysis/function/LogitTest.java     | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/d7073642/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java b/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
index 9639fa8..ea5c10d 100644
--- a/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/function/LogitTest.java
@@ -26,8 +26,8 @@ import org.apache.commons.math4.analysis.function.Sigmoid;
 import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -160,7 +160,8 @@ public class LogitTest {
         final double hi = 3;
         final Logit f = new Logit(lo, hi);
         final Sigmoid g = new Sigmoid(lo, hi);
-        RandomGenerator random = new Well1024a(0x49914cdd9f0b8db5l);
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                                 0x49914cdd9f0b8db5l);
         final UnivariateDifferentiableFunction id = FunctionUtils.compose((UnivariateDifferentiableFunction) g,
                                                                 (UnivariateDifferentiableFunction) f);
 
@@ -180,7 +181,8 @@ public class LogitTest {
         final double hi = 3;
         final Logit f = new Logit(lo, hi);
         final Sigmoid g = new Sigmoid(lo, hi);
-        RandomGenerator random = new Well1024a(0x96885e9c1f81cea5l);
+        final UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                                 0x96885e9c1f81cea6l);
         final UnivariateDifferentiableFunction id =
                 FunctionUtils.compose((UnivariateDifferentiableFunction) g, (UnivariateDifferentiableFunction) f);
         for (int maxOrder = 0; maxOrder < 6; ++maxOrder) {
@@ -190,7 +192,8 @@ public class LogitTest {
                 final DerivativeStructure dsX = new DerivativeStructure(1, maxOrder, 0, x);
                 max = FastMath.max(max, FastMath.abs(dsX.getPartialDerivative(maxOrder) -
                                                      id.value(dsX).getPartialDerivative(maxOrder)));
-                Assert.assertEquals(dsX.getPartialDerivative(maxOrder),
+                Assert.assertEquals("maxOrder = " + maxOrder,
+                                    dsX.getPartialDerivative(maxOrder),
                                     id.value(dsX).getPartialDerivative(maxOrder),
                                     epsilon[maxOrder]);
             }


[05/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f81e0465
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f81e0465
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f81e0465

Branch: refs/heads/develop
Commit: f81e0465460ff9abd450eda836bbb4f9b13837c7
Parents: 57e01f4
Author: Gilles <er...@apache.org>
Authored: Wed May 11 13:25:42 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/ml/clustering/FuzzyKMeansClusterer.java     | 12 ++++++------
 .../math4/ml/clustering/KMeansPlusPlusClusterer.java  | 14 +++++++-------
 .../math4/ml/clustering/FuzzyKMeansClustererTest.java |  6 +++---
 .../ml/clustering/KMeansPlusPlusClustererTest.java    | 11 ++++-------
 4 files changed, 20 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f81e0465/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
index e57697f..f650d24 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClusterer.java
@@ -28,8 +28,8 @@ import org.apache.commons.math4.linear.MatrixUtils;
 import org.apache.commons.math4.linear.RealMatrix;
 import org.apache.commons.math4.ml.distance.DistanceMeasure;
 import org.apache.commons.math4.ml.distance.EuclideanDistance;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 import org.apache.commons.math4.util.MathUtils;
@@ -83,7 +83,7 @@ public class FuzzyKMeansClusterer<T extends Clusterable> extends Clusterer<T> {
     private final double epsilon;
 
     /** Random generator for choosing initial centers. */
-    private final RandomGenerator random;
+    private final UniformRandomProvider random;
 
     /** The membership matrix. */
     private double[][] membershipMatrix;
@@ -120,7 +120,7 @@ public class FuzzyKMeansClusterer<T extends Clusterable> extends Clusterer<T> {
     public FuzzyKMeansClusterer(final int k, final double fuzziness,
                                 final int maxIterations, final DistanceMeasure measure)
             throws NumberIsTooSmallException {
-        this(k, fuzziness, maxIterations, measure, DEFAULT_EPSILON, new JDKRandomGenerator());
+        this(k, fuzziness, maxIterations, measure, DEFAULT_EPSILON, RandomSource.create(RandomSource.MT_64));
     }
 
     /**
@@ -137,7 +137,7 @@ public class FuzzyKMeansClusterer<T extends Clusterable> extends Clusterer<T> {
      */
     public FuzzyKMeansClusterer(final int k, final double fuzziness,
                                 final int maxIterations, final DistanceMeasure measure,
-                                final double epsilon, final RandomGenerator random)
+                                final double epsilon, final UniformRandomProvider random)
             throws NumberIsTooSmallException {
 
         super(measure);
@@ -192,7 +192,7 @@ public class FuzzyKMeansClusterer<T extends Clusterable> extends Clusterer<T> {
      * Returns the random generator this instance will use.
      * @return the random generator
      */
-    public RandomGenerator getRandomGenerator() {
+    public UniformRandomProvider getRandomGenerator() {
         return random;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f81e0465/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java b/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
index 1901013..0b8ad96 100644
--- a/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
+++ b/src/main/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClusterer.java
@@ -28,8 +28,8 @@ import org.apache.commons.math4.exception.NumberIsTooSmallException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
 import org.apache.commons.math4.ml.distance.DistanceMeasure;
 import org.apache.commons.math4.ml.distance.EuclideanDistance;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.stat.descriptive.moment.Variance;
 import org.apache.commons.math4.util.MathUtils;
 
@@ -65,7 +65,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
     private final int maxIterations;
 
     /** Random generator for choosing initial centers. */
-    private final RandomGenerator random;
+    private final UniformRandomProvider random;
 
     /** Selected strategy for empty clusters. */
     private final EmptyClusterStrategy emptyStrategy;
@@ -109,7 +109,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
      * @param measure the distance measure to use
      */
     public KMeansPlusPlusClusterer(final int k, final int maxIterations, final DistanceMeasure measure) {
-        this(k, maxIterations, measure, new JDKRandomGenerator());
+        this(k, maxIterations, measure, RandomSource.create(RandomSource.MT_64));
     }
 
     /** Build a clusterer.
@@ -125,7 +125,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
      */
     public KMeansPlusPlusClusterer(final int k, final int maxIterations,
                                    final DistanceMeasure measure,
-                                   final RandomGenerator random) {
+                                   final UniformRandomProvider random) {
         this(k, maxIterations, measure, random, EmptyClusterStrategy.LARGEST_VARIANCE);
     }
 
@@ -141,7 +141,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
      */
     public KMeansPlusPlusClusterer(final int k, final int maxIterations,
                                    final DistanceMeasure measure,
-                                   final RandomGenerator random,
+                                   final UniformRandomProvider random,
                                    final EmptyClusterStrategy emptyStrategy) {
         super(measure);
         this.k             = k;
@@ -170,7 +170,7 @@ public class KMeansPlusPlusClusterer<T extends Clusterable> extends Clusterer<T>
      * Returns the random generator this instance will use.
      * @return the random generator
      */
-    public RandomGenerator getRandomGenerator() {
+    public UniformRandomProvider getRandomGenerator() {
         return random;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f81e0465/src/test/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClustererTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClustererTest.java b/src/test/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClustererTest.java
index a46c01e..4950c80 100644
--- a/src/test/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClustererTest.java
+++ b/src/test/java/org/apache/commons/math4/ml/clustering/FuzzyKMeansClustererTest.java
@@ -28,8 +28,8 @@ import org.apache.commons.math4.ml.clustering.DoublePoint;
 import org.apache.commons.math4.ml.clustering.FuzzyKMeansClusterer;
 import org.apache.commons.math4.ml.distance.CanberraDistance;
 import org.apache.commons.math4.ml.distance.DistanceMeasure;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.hamcrest.CoreMatchers;
 import org.junit.Assert;
 import org.junit.Test;
@@ -97,7 +97,7 @@ public class FuzzyKMeansClustererTest {
     @Test
     public void testGetters() {
         final DistanceMeasure measure = new CanberraDistance();
-        final RandomGenerator random = new JDKRandomGenerator();
+        final UniformRandomProvider random = RandomSource.create(RandomSource.MT_64);
         final FuzzyKMeansClusterer<DoublePoint> clusterer =
                 new FuzzyKMeansClusterer<DoublePoint>(3, 2.0, 100, measure, 1e-6, random);
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/f81e0465/src/test/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClustererTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClustererTest.java b/src/test/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClustererTest.java
index 39ef2c5..0e07a1f 100644
--- a/src/test/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClustererTest.java
+++ b/src/test/java/org/apache/commons/math4/ml/clustering/KMeansPlusPlusClustererTest.java
@@ -28,20 +28,19 @@ import org.apache.commons.math4.ml.clustering.Cluster;
 import org.apache.commons.math4.ml.clustering.DoublePoint;
 import org.apache.commons.math4.ml.clustering.KMeansPlusPlusClusterer;
 import org.apache.commons.math4.ml.distance.EuclideanDistance;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
 public class KMeansPlusPlusClustererTest {
 
-    private RandomGenerator random;
+    private UniformRandomProvider random;
 
     @Before
     public void setUp() {
-        random = new JDKRandomGenerator();
-        random.setSeed(1746432956321l);
+        random = RandomSource.create(RandomSource.MT_64, 1746432956321l);
     }
 
     /**
@@ -152,10 +151,8 @@ public class KMeansPlusPlusClustererTest {
 
         // Ask a KMeansPlusPlusClusterer to run zero iterations (i.e., to simply choose initial
         // cluster centers).
-        final long RANDOM_SEED = 0;
         final int NUM_CLUSTERS = 2;
         final int NUM_ITERATIONS = 0;
-        random.setSeed(RANDOM_SEED);
 
         KMeansPlusPlusClusterer<DoublePoint> clusterer =
             new KMeansPlusPlusClusterer<DoublePoint>(NUM_CLUSTERS, NUM_ITERATIONS,


[02/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0caba084
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0caba084
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0caba084

Branch: refs/heads/develop
Commit: 0caba0845d4363025e619eb3db6f3138b2c3d394
Parents: 1b5aef8
Author: Gilles <er...@apache.org>
Authored: Thu May 12 16:43:09 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/random/UniformRandomGenerator.java    | 36 +++++++++++---------
 .../random/UniformRandomGeneratorTest.java      |  8 ++---
 2 files changed, 22 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0caba084/src/main/java/org/apache/commons/math4/random/UniformRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/UniformRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/UniformRandomGenerator.java
index aac8295..1a07ba4 100644
--- a/src/main/java/org/apache/commons/math4/random/UniformRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/UniformRandomGenerator.java
@@ -18,39 +18,41 @@
 package org.apache.commons.math4.random;
 
 import org.apache.commons.math4.util.FastMath;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * This class implements a normalized uniform random generator.
- * <p>Since it is a normalized random generator, it generates values
- * from a uniform distribution with mean equal to 0 and standard
- * deviation equal to 1. Generated values fall in the range
- * [-&#x0221A;3, +&#x0221A;3].</p>
+ *
+ * <p>
+ * It generates values from a uniform distribution with mean
+ * equal to 0 and standard deviation equal to 1.
+ * Generated values fall in the range \( [-\sqrt{3}, +\sqrt{3}] \).
+ * </p>
  *
  * @since 1.2
  */
 public class UniformRandomGenerator implements NormalizedRandomGenerator {
-
     /** Square root of three. */
-    private static final double SQRT3 = FastMath.sqrt(3.0);
-
+    private static final double SQRT3 = FastMath.sqrt(3);
     /** Underlying generator. */
-    private final RandomGenerator generator;
+    private final UniformRandomProvider generator;
 
-    /** Create a new generator.
-     * @param generator underlying random generator to use
+    /**
+     * Creates a new generator.
+     *
+     * @param generator Underlying random generator.
      */
-    public UniformRandomGenerator(RandomGenerator generator) {
+    public UniformRandomGenerator(UniformRandomProvider generator) {
         this.generator = generator;
     }
 
-    /** Generate a random scalar with null mean and unit standard deviation.
-     * <p>The number generated is uniformly distributed between -&sqrt;(3)
-     * and +&sqrt;(3).</p>
-     * @return a random scalar with null mean and unit standard deviation
+    /**
+     * Generates a random scalar with zero mean and unit standard deviation.
+     *
+     * @return a random scalar in the range \( [-\sqrt{3}, +\sqrt{3}] \).
      */
     @Override
     public double nextNormalizedDouble() {
-        return SQRT3 * (2 * generator.nextDouble() - 1.0);
+        return SQRT3 * (2 * generator.nextDouble() - 1);
     }
-
 }

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0caba084/src/test/java/org/apache/commons/math4/random/UniformRandomGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/UniformRandomGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/UniformRandomGeneratorTest.java
index fbe9271..68b133e 100644
--- a/src/test/java/org/apache/commons/math4/random/UniformRandomGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/UniformRandomGeneratorTest.java
@@ -18,8 +18,8 @@
 package org.apache.commons.math4.random;
 
 import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.UniformRandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.StatUtils;
 import org.junit.Assert;
 import org.junit.Test;
@@ -29,8 +29,7 @@ public class UniformRandomGeneratorTest {
 
     @Test
     public void testMeanAndStandardDeviation() {
-        RandomGenerator rg = new JDKRandomGenerator();
-        rg.setSeed(17399225432l);
+        final UniformRandomProvider rg = RandomSource.create(RandomSource.ISAAC, 17399225432L);
         UniformRandomGenerator generator = new UniformRandomGenerator(rg);
         double[] sample = new double[10000];
         for (int i = 0; i < sample.length; ++i) {
@@ -39,5 +38,4 @@ public class UniformRandomGeneratorTest {
         Assert.assertEquals(0.0, StatUtils.mean(sample), 0.07);
         Assert.assertEquals(1.0, StatUtils.variance(sample), 0.02);
     }
-
 }


[03/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/521b9b33
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/521b9b33
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/521b9b33

Branch: refs/heads/develop
Commit: 521b9b3385d73239b96ab209cb34ceb5c1c1400a
Parents: a9fdcd6
Author: Gilles <er...@apache.org>
Authored: Thu May 12 15:18:13 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/stat/regression/SimpleRegressionTest.java     | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/521b9b33/src/test/java/org/apache/commons/math4/stat/regression/SimpleRegressionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/regression/SimpleRegressionTest.java b/src/test/java/org/apache/commons/math4/stat/regression/SimpleRegressionTest.java
index e37dda0..bc90429 100644
--- a/src/test/java/org/apache/commons/math4/stat/regression/SimpleRegressionTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/regression/SimpleRegressionTest.java
@@ -20,7 +20,8 @@ import java.util.Random;
 
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.random.ISAACRandom;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.regression.ModelSpecificationException;
 import org.apache.commons.math4.stat.regression.RegressionResults;
 import org.apache.commons.math4.stat.regression.SimpleRegression;
@@ -135,7 +136,7 @@ public final class SimpleRegressionTest {
      */
     private void check(boolean includeIntercept) {
         final int sets = 2;
-        final ISAACRandom rand = new ISAACRandom(10L);// Seed can be changed
+        final UniformRandomProvider rand = RandomSource.create(RandomSource.ISAAC, 10L);// Seed can be changed
         final SimpleRegression whole = new SimpleRegression(includeIntercept);// regression of the whole set
         final SimpleRegression parts = new SimpleRegression(includeIntercept);// regression with parts.
 


[18/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/f3108e27
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/f3108e27
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/f3108e27

Branch: refs/heads/develop
Commit: f3108e2771083bfcf02c9c67ebd70a3ac0ddfca8
Parents: 583d57d
Author: Gilles <er...@apache.org>
Authored: Thu May 12 13:32:54 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/ExtendedFieldElementAbstractTest.java | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/f3108e27/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java b/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
index 03b5a1a..5f27243 100644
--- a/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
+++ b/src/test/java/org/apache/commons/math4/ExtendedFieldElementAbstractTest.java
@@ -17,8 +17,8 @@
 package org.apache.commons.math4;
 
 import org.apache.commons.math4.RealFieldElement;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.apache.commons.math4.util.MathArrays;
 import org.junit.Assert;
@@ -393,7 +393,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationFaFa() {
-        RandomGenerator r = new Well1024a(0xfafal);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xfafal);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 10);
             double[] bD = generateDouble(r, 10);
@@ -406,7 +406,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationDaFa() {
-        RandomGenerator r = new Well1024a(0xdafal);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdafal);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 10);
             double[] bD = generateDouble(r, 10);
@@ -418,7 +418,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationFF2() {
-        RandomGenerator r = new Well1024a(0xff2l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff2l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 2);
             double[] bD = generateDouble(r, 2);
@@ -431,7 +431,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationDF2() {
-        RandomGenerator r = new Well1024a(0xdf2l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf2l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 2);
             double[] bD = generateDouble(r, 2);
@@ -443,7 +443,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationFF3() {
-        RandomGenerator r = new Well1024a(0xff3l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff3l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 3);
             double[] bD = generateDouble(r, 3);
@@ -456,7 +456,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationDF3() {
-        RandomGenerator r = new Well1024a(0xdf3l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf3l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 3);
             double[] bD = generateDouble(r, 3);
@@ -468,7 +468,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationFF4() {
-        RandomGenerator r = new Well1024a(0xff4l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xff4l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 4);
             double[] bD = generateDouble(r, 4);
@@ -481,7 +481,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
 
     @Test
     public void testLinearCombinationDF4() {
-        RandomGenerator r = new Well1024a(0xdf4l);
+        UniformRandomProvider r = RandomSource.create(RandomSource.WELL_1024_A, 0xdf4l);
         for (int i = 0; i < 50; ++i) {
             double[] aD = generateDouble(r, 4);
             double[] bD = generateDouble(r, 4);
@@ -521,7 +521,7 @@ public abstract class ExtendedFieldElementAbstractTest<T extends RealFieldElemen
         Assert.assertTrue(t1a.hashCode() != t2.hashCode());
     }
 
-    private double[] generateDouble (final RandomGenerator r, int n) {
+    private double[] generateDouble (final UniformRandomProvider r, int n) {
         double[] a = new double[n];
         for (int i = 0; i < n; ++i) {
             a[i] = r.nextDouble();


[16/25] [math] Unused "import".

Posted by er...@apache.org.
Unused "import".


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/583d57db
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/583d57db
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/583d57db

Branch: refs/heads/develop
Commit: 583d57dbe02ebff1ef46cd1e8239ad6fa00fc36e
Parents: a3fae47
Author: Gilles <er...@apache.org>
Authored: Thu May 12 13:01:47 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java    | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/583d57db/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
index 94b1ffb..1500fc5 100644
--- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/DiskGeneratorTest.java
@@ -24,7 +24,6 @@ import org.apache.commons.math4.geometry.enclosing.EnclosingBall;
 import org.apache.commons.math4.geometry.euclidean.twod.DiskGenerator;
 import org.apache.commons.math4.geometry.euclidean.twod.Euclidean2D;
 import org.apache.commons.math4.geometry.euclidean.twod.Vector2D;
-import org.apache.commons.math4.random.RandomGenerator;
 import org.apache.commons.math4.random.UnitSphereRandomVectorGenerator;
 import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.rng.RandomSource;


[11/25] [math] Unused "import".

Posted by er...@apache.org.
Unused "import".


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/ed78ce27
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/ed78ce27
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/ed78ce27

Branch: refs/heads/develop
Commit: ed78ce27aab2214bd433fd7b43c84fc72d146455
Parents: 829a4e9
Author: Gilles <er...@apache.org>
Authored: Wed May 11 15:56:31 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../apache/commons/math4/distribution/BetaDistributionTest.java   | 3 ---
 1 file changed, 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/ed78ce27/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
index 5127503..03054b8 100644
--- a/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
+++ b/src/test/java/org/apache/commons/math4/distribution/BetaDistributionTest.java
@@ -19,9 +19,6 @@ package org.apache.commons.math4.distribution;
 import java.util.Arrays;
 
 import org.apache.commons.math4.distribution.BetaDistribution;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
-import org.apache.commons.math4.random.Well19937a;
 import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.stat.StatUtils;


[06/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/6fc152e4
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/6fc152e4
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/6fc152e4

Branch: refs/heads/develop
Commit: 6fc152e4177e0482450b13eb7fe496de677ce5b6
Parents: f81e046
Author: Gilles <er...@apache.org>
Authored: Wed May 11 13:38:37 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/math4/util/RandomPivotingStrategy.java  | 6 +++---
 .../commons/math4/stat/descriptive/rank/PercentileTest.java    | 5 ++---
 2 files changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/6fc152e4/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java b/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
index e386664..a13b566 100644
--- a/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
+++ b/src/main/java/org/apache/commons/math4/util/RandomPivotingStrategy.java
@@ -19,7 +19,7 @@ package org.apache.commons.math4.util;
 import java.io.Serializable;
 
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 
 /**
@@ -32,12 +32,12 @@ public class RandomPivotingStrategy implements PivotingStrategyInterface, Serial
     private static final long serialVersionUID = 20140713L;
 
     /** Random generator to use for selecting pivot. */
-    private final RandomGenerator random;
+    private final UniformRandomProvider random;
 
     /** Simple constructor.
      * @param random random generator to use for selecting pivot
      */
-    public RandomPivotingStrategy(final RandomGenerator random) {
+    public RandomPivotingStrategy(final UniformRandomProvider random) {
         this.random = random;
     }
 

http://git-wip-us.apache.org/repos/asf/commons-math/blob/6fc152e4/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
index 98b6f91..ffac6cc 100644
--- a/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/descriptive/rank/PercentileTest.java
@@ -25,7 +25,6 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.NotANumberException;
 import org.apache.commons.math4.exception.NullArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
-import org.apache.commons.math4.random.Well1024a;
 import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.stat.descriptive.UnivariateStatistic;
@@ -317,7 +316,7 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
 
     @Test
     public void testAllTechniquesPercentileUsingRandomPivoting() {
-        kthSelector = new KthSelector(new RandomPivotingStrategy(new Well1024a(0x268a7fb4194240f6l)));
+        kthSelector = new KthSelector(new RandomPivotingStrategy(RandomSource.create(RandomSource.WELL_1024_A, 0x268a7fb4194240f6l)));
         Assert.assertEquals(RandomPivotingStrategy.class,
                             getUnivariateStatistic().getPivotingStrategy().getClass());
         checkAllTechniquesPercentile();
@@ -696,7 +695,7 @@ public class PercentileTest extends UnivariateStatisticAbstractTest{
         for (final PivotingStrategyInterface strategy : new PivotingStrategyInterface[] {
             new MedianOf3PivotingStrategy(),
             new CentralPivotingStrategy(),
-            new RandomPivotingStrategy(new Well1024a(0xf097c734e4740053l))
+            new RandomPivotingStrategy(RandomSource.create(RandomSource.WELL_1024_A, 0xf097c734e4740053l))
         }) {
             kthSelector = new KthSelector(strategy);
             testAllEstimationTechniquesOnly();


[24/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/022a020b
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/022a020b
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/022a020b

Branch: refs/heads/develop
Commit: 022a020bde5afba4f2e9b6753c199386e79d7825
Parents: d7a1666
Author: Gilles <er...@apache.org>
Authored: Thu May 12 15:53:02 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/stat/correlation/StorelessCovarianceTest.java | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/022a020b/src/test/java/org/apache/commons/math4/stat/correlation/StorelessCovarianceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/correlation/StorelessCovarianceTest.java b/src/test/java/org/apache/commons/math4/stat/correlation/StorelessCovarianceTest.java
index dc2197b..9378f29 100644
--- a/src/test/java/org/apache/commons/math4/stat/correlation/StorelessCovarianceTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/correlation/StorelessCovarianceTest.java
@@ -19,7 +19,8 @@ package org.apache.commons.math4.stat.correlation;
 import org.apache.commons.math4.TestUtils;
 import org.apache.commons.math4.linear.Array2DRowRealMatrix;
 import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.math4.random.ISAACRandom;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.correlation.StorelessBivariateCovariance;
 import org.apache.commons.math4.stat.correlation.StorelessCovariance;
 import org.junit.Assert;
@@ -235,7 +236,7 @@ public class StorelessCovarianceTest {
         StorelessBivariateCovariance cov = new StorelessBivariateCovariance();// covariance of the superset
         StorelessBivariateCovariance chk = new StorelessBivariateCovariance();// check covariance made by appending covariance of subsets
 
-        ISAACRandom rand = new ISAACRandom(10L);// Seed can be changed
+        final UniformRandomProvider rand = RandomSource.create(RandomSource.ISAAC, 10L);// Seed can be changed
         for (int s = 0; s < num_sets; s++) {// loop through sets of samlpes
             StorelessBivariateCovariance covs = new StorelessBivariateCovariance();
             for (int i = 0; i < 5; i++) { // loop through individual samlpes.


[07/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0c9af5f4
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0c9af5f4
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0c9af5f4

Branch: refs/heads/develop
Commit: 0c9af5f450ce73da9b791051f861cb9a6420e0f1
Parents: 6fc152e
Author: Gilles <er...@apache.org>
Authored: Wed May 11 13:54:06 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../commons/math4/genetics/GeneticAlgorithm.java  | 18 +++++++++---------
 .../commons/math4/genetics/NPointCrossover.java   |  4 ++--
 .../commons/math4/genetics/OrderedCrossover.java  |  4 ++--
 .../commons/math4/genetics/UniformCrossover.java  |  4 ++--
 4 files changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/0c9af5f4/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java b/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
index bf77606..d76fe93 100644
--- a/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
+++ b/src/main/java/org/apache/commons/math4/genetics/GeneticAlgorithm.java
@@ -18,8 +18,8 @@ package org.apache.commons.math4.genetics;
 
 import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.JDKRandomGenerator;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.RandomSource;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * Implementation of a genetic algorithm. All factors that govern the operation
@@ -30,12 +30,12 @@ import org.apache.commons.math4.random.RandomGenerator;
 public class GeneticAlgorithm {
 
     /**
-     * Static random number generator shared by GA implementation classes. Set the randomGenerator seed to get
-     * reproducible results. Use {@link #setRandomGenerator(RandomGenerator)} to supply an alternative to the default
-     * JDK-provided PRNG.
+     * Static random number generator shared by GA implementation classes.
+     * Use {@link #setRandomGenerator(UniformRandomProvider)} to supply an
+     * alternative to the default PRNG, and/or select a specific seed.
      */
     //@GuardedBy("this")
-    private static RandomGenerator randomGenerator = new JDKRandomGenerator();
+    private static UniformRandomProvider randomGenerator = RandomSource.create(RandomSource.WELL_19937_C);
 
     /** the crossover policy used by the algorithm. */
     private final CrossoverPolicy crossoverPolicy;
@@ -90,7 +90,7 @@ public class GeneticAlgorithm {
      *
      * @param random random generator
      */
-    public static synchronized void setRandomGenerator(final RandomGenerator random) {
+    public static synchronized void setRandomGenerator(final UniformRandomProvider random) {
         randomGenerator = random;
     }
 
@@ -99,7 +99,7 @@ public class GeneticAlgorithm {
      *
      * @return the static random generator shared by GA implementation classes
      */
-    public static synchronized RandomGenerator getRandomGenerator() {
+    public static synchronized UniformRandomProvider getRandomGenerator() {
         return randomGenerator;
     }
 
@@ -148,7 +148,7 @@ public class GeneticAlgorithm {
     public Population nextGeneration(final Population current) {
         Population nextGeneration = current.nextGeneration();
 
-        RandomGenerator randGen = getRandomGenerator();
+        UniformRandomProvider randGen = getRandomGenerator();
 
         while (nextGeneration.getPopulationSize() < nextGeneration.getPopulationLimit()) {
             // select parent chromosomes

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0c9af5f4/src/main/java/org/apache/commons/math4/genetics/NPointCrossover.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/genetics/NPointCrossover.java b/src/main/java/org/apache/commons/math4/genetics/NPointCrossover.java
index 5c79ef1..847e9bc 100644
--- a/src/main/java/org/apache/commons/math4/genetics/NPointCrossover.java
+++ b/src/main/java/org/apache/commons/math4/genetics/NPointCrossover.java
@@ -24,7 +24,7 @@ import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.NotStrictlyPositiveException;
 import org.apache.commons.math4.exception.NumberIsTooLargeException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * N-point crossover policy. For each iteration a random crossover point is
@@ -142,7 +142,7 @@ public class NPointCrossover<T> implements CrossoverPolicy {
         final List<T> child1Rep = new ArrayList<T>(length);
         final List<T> child2Rep = new ArrayList<T>(length);
 
-        final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();
+        final UniformRandomProvider random = GeneticAlgorithm.getRandomGenerator();
 
         List<T> c1 = child1Rep;
         List<T> c2 = child2Rep;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0c9af5f4/src/main/java/org/apache/commons/math4/genetics/OrderedCrossover.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/genetics/OrderedCrossover.java b/src/main/java/org/apache/commons/math4/genetics/OrderedCrossover.java
index b5aecc8..6b6502c 100644
--- a/src/main/java/org/apache/commons/math4/genetics/OrderedCrossover.java
+++ b/src/main/java/org/apache/commons/math4/genetics/OrderedCrossover.java
@@ -25,7 +25,7 @@ import java.util.Set;
 import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 import org.apache.commons.math4.util.FastMath;
 
 /**
@@ -103,7 +103,7 @@ public class OrderedCrossover<T> implements CrossoverPolicy {
         final Set<T> child1Set = new HashSet<T>(length);
         final Set<T> child2Set = new HashSet<T>(length);
 
-        final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();
+        final UniformRandomProvider random = GeneticAlgorithm.getRandomGenerator();
         // choose random points, making sure that lb < ub.
         int a = random.nextInt(length);
         int b;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/0c9af5f4/src/main/java/org/apache/commons/math4/genetics/UniformCrossover.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/genetics/UniformCrossover.java b/src/main/java/org/apache/commons/math4/genetics/UniformCrossover.java
index 3da1c87..df5b929 100644
--- a/src/main/java/org/apache/commons/math4/genetics/UniformCrossover.java
+++ b/src/main/java/org/apache/commons/math4/genetics/UniformCrossover.java
@@ -23,7 +23,7 @@ import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.MathIllegalArgumentException;
 import org.apache.commons.math4.exception.OutOfRangeException;
 import org.apache.commons.math4.exception.util.LocalizedFormats;
-import org.apache.commons.math4.random.RandomGenerator;
+import org.apache.commons.math4.rng.UniformRandomProvider;
 
 /**
  * Perform Uniform Crossover [UX] on the specified chromosomes. A fixed mixing
@@ -115,7 +115,7 @@ public class UniformCrossover<T> implements CrossoverPolicy {
         final List<T> child1Rep = new ArrayList<T>(length);
         final List<T> child2Rep = new ArrayList<T>(length);
 
-        final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();
+        final UniformRandomProvider random = GeneticAlgorithm.getRandomGenerator();
 
         for (int index = 0; index < length; index++) {
 


[17/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/a3fae474
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/a3fae474
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/a3fae474

Branch: refs/heads/develop
Commit: a3fae474e5cf5084c89835fce1950991aa678a41
Parents: f9f632e
Author: Gilles <er...@apache.org>
Authored: Thu May 12 12:43:20 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../org/apache/commons/math4/ode/events/EventFilterTest.java   | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/a3fae474/src/test/java/org/apache/commons/math4/ode/events/EventFilterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/ode/events/EventFilterTest.java b/src/test/java/org/apache/commons/math4/ode/events/EventFilterTest.java
index c8ea085..41585bd 100644
--- a/src/test/java/org/apache/commons/math4/ode/events/EventFilterTest.java
+++ b/src/test/java/org/apache/commons/math4/ode/events/EventFilterTest.java
@@ -27,8 +27,8 @@ import org.apache.commons.math4.ode.events.EventFilter;
 import org.apache.commons.math4.ode.events.EventHandler;
 import org.apache.commons.math4.ode.events.FilterType;
 import org.apache.commons.math4.ode.nonstiff.DormandPrince853Integrator;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well19937a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -118,7 +118,7 @@ public class EventFilterTest {
         }
 
         // verify old events are preserved, even if randomly accessed
-        RandomGenerator rng = new Well19937a(0xb0e7401265af8cd3l);
+        UniformRandomProvider rng = RandomSource.create(RandomSource.TWO_CMRES, 0xb0e7401265af8cd3l);
         for (int i = 0; i < 5000; i++) {
             double t = t0 + (t1 - t0) * rng.nextDouble();
             double g = eventFilter.g(t, new double[] { FastMath.sin(t), FastMath.cos(t) });


[13/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/73317734
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/73317734
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/73317734

Branch: refs/heads/develop
Commit: 7331773448c1f2e0b24deae4144db0deec85fc07
Parents: d707364
Author: Gilles <er...@apache.org>
Authored: Wed May 11 16:43:13 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../analysis/differentiation/DerivativeStructureTest.java   | 7 ++++---
 .../math4/analysis/differentiation/SparseGradientTest.java  | 9 ++++++---
 2 files changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/73317734/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
index 99fcdd1..8d4bf50 100644
--- a/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/differentiation/DerivativeStructureTest.java
@@ -26,7 +26,8 @@ import org.apache.commons.math4.analysis.differentiation.DerivativeStructure;
 import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
 import org.apache.commons.math4.exception.DimensionMismatchException;
 import org.apache.commons.math4.exception.NumberIsTooLargeException;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.ArithmeticUtils;
 import org.apache.commons.math4.util.CombinatoricsUtils;
 import org.apache.commons.math4.util.FastMath;
@@ -1447,7 +1448,7 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest<De
     public void testLinearCombination2DSDS() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(0xc6af886975069f11l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 0xc6af886975069f11l);
 
         for (int i = 0; i < 10000; ++i) {
             final DerivativeStructure[] u = new DerivativeStructure[4];
@@ -1491,7 +1492,7 @@ public class DerivativeStructureTest extends ExtendedFieldElementAbstractTest<De
     public void testLinearCombination2DoubleDS() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(0xc6af886975069f11l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A, 0xc6af886975069f11l);
 
         for (int i = 0; i < 10000; ++i) {
             final double[] u = new double[4];

http://git-wip-us.apache.org/repos/asf/commons-math/blob/73317734/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java b/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
index fdfe87b..569d540 100644
--- a/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
+++ b/src/test/java/org/apache/commons/math4/analysis/differentiation/SparseGradientTest.java
@@ -22,7 +22,8 @@ import java.util.List;
 import org.apache.commons.math4.ExtendedFieldElementAbstractTest;
 import org.apache.commons.math4.TestUtils;
 import org.apache.commons.math4.analysis.polynomials.PolynomialFunction;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -1022,7 +1023,8 @@ public class SparseGradientTest extends ExtendedFieldElementAbstractTest<SparseG
     public void testLinearCombination2DSDS() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(0xc6af886975069f11l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0xc6af886975069f11l);
 
         for (int i = 0; i < 10000; ++i) {
             final SparseGradient[] u = new SparseGradient[4];
@@ -1066,7 +1068,8 @@ public class SparseGradientTest extends ExtendedFieldElementAbstractTest<SparseG
     public void testLinearCombination2DoubleDS() {
         // we compare accurate versus naive dot product implementations
         // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(0xc6af886975069f11l);
+        UniformRandomProvider random = RandomSource.create(RandomSource.WELL_1024_A,
+                                                           0xc6af886975069f11l);
 
         for (int i = 0; i < 10000; ++i) {
             final double[] u = new double[4];


[15/25] [math] MATH-1335

Posted by er...@apache.org.
MATH-1335

Use new RNG API.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/d7a1666f
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/d7a1666f
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/d7a1666f

Branch: refs/heads/develop
Commit: d7a1666f9a89d9a517f5fbaf283e711046fd054e
Parents: 521b9b3
Author: Gilles <er...@apache.org>
Authored: Thu May 12 15:50:26 2016 +0200
Committer: Gilles <er...@apache.org>
Committed: Tue May 17 15:30:23 2016 +0200

----------------------------------------------------------------------
 .../math4/stat/correlation/KendallsCorrelationTest.java        | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/d7a1666f/src/test/java/org/apache/commons/math4/stat/correlation/KendallsCorrelationTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/stat/correlation/KendallsCorrelationTest.java b/src/test/java/org/apache/commons/math4/stat/correlation/KendallsCorrelationTest.java
index a3f312c..8b40f70 100644
--- a/src/test/java/org/apache/commons/math4/stat/correlation/KendallsCorrelationTest.java
+++ b/src/test/java/org/apache/commons/math4/stat/correlation/KendallsCorrelationTest.java
@@ -21,8 +21,8 @@ import java.util.Arrays;
 import org.apache.commons.math4.TestUtils;
 import org.apache.commons.math4.linear.BlockRealMatrix;
 import org.apache.commons.math4.linear.RealMatrix;
-import org.apache.commons.math4.random.RandomGenerator;
-import org.apache.commons.math4.random.Well1024a;
+import org.apache.commons.math4.rng.UniformRandomProvider;
+import org.apache.commons.math4.rng.RandomSource;
 import org.apache.commons.math4.stat.correlation.KendallsCorrelation;
 import org.junit.Assert;
 import org.junit.Before;
@@ -266,7 +266,7 @@ public class KendallsCorrelationTest extends PearsonsCorrelationTest {
     public void testMath1277() {
         // example that led to a correlation coefficient outside of [-1, 1]
         // due to a bug reported in MATH-1277
-        RandomGenerator rng = new Well1024a(0);
+        UniformRandomProvider rng = RandomSource.create(RandomSource.WELL_1024_A, 0);
         double[] xArray = new double[120000];
         double[] yArray = new double[120000];
         for (int i = 0; i < xArray.length; ++i) {