commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [09/25] [math] MATH-1335
Date Tue, 17 May 2016 15:49:42 GMT
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 <erans@apache.org>
Authored: Wed May 11 14:25:36 2016 +0200
Committer: Gilles <erans@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;
     }
-
 }


Mime
View raw message