commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1000422 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
Date Thu, 23 Sep 2010 12:11:56 GMT
Author: erans
Date: Thu Sep 23 12:11:56 2010
New Revision: 1000422

URL: http://svn.apache.org/viewvc?rev=1000422&view=rev
Log:
MATH-413 (point 13)
Selecting a random start value (instead of interval bounds).

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java?rev=1000422&r1=1000421&r2=1000422&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
Thu Sep 23 12:11:56 2010
@@ -143,18 +143,22 @@ public class MultiStartUnivariateRealOpt
                                                  final GoalType goal,
                                                  final double min, final double max)
         throws FunctionEvaluationException {
+        return optimize(f, goal, min, max, min + 0.5 * (max - min));
+    }
 
+    /** {@inheritDoc} */
+    public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
+                                                 final double min, final double max,
+                                                 final double startValue)
+        throws FunctionEvaluationException {
         optima = new UnivariateRealPointValuePair[starts];
         totalEvaluations = 0;
 
         // Multi-start loop.
         for (int i = 0; i < starts; ++i) {
             try {
-                final double bound1 = (i == 0) ? min : min + generator.nextDouble() * (max
- min);
-                final double bound2 = (i == 0) ? max : min + generator.nextDouble() * (max
- min);
-                optima[i] = optimizer.optimize(f, goal,
-                                               FastMath.min(bound1, bound2),
-                                               FastMath.max(bound1, bound2));
+                final double s = (i == 0) ? startValue : min + generator.nextDouble() * (max
- min);
+                optima[i] = optimizer.optimize(f, goal, min, max, s);
             } catch (FunctionEvaluationException fee) {
                 optima[i] = null;
             } catch (ConvergenceException ce) {
@@ -177,16 +181,6 @@ public class MultiStartUnivariateRealOpt
         return optima[0];
     }
 
-    /** {@inheritDoc} */
-    public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goalType,
-                                                 final double min, final double max,
-                                                 final double startValue)
-            throws FunctionEvaluationException {
-        // XXX Main code should be here, using "startValue" for the first start.
-        // XXX This method should set "startValue" to min + 0.5 * (max - min)
-        return optimize(f, goalType, min, max);
-    }
-
     /**
      * Sort the optima from best to worst, followed by {@code null} elements.
      *

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java?rev=1000422&r1=1000421&r2=1000422&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizerTest.java
Thu Sep 23 12:11:56 2010
@@ -50,8 +50,8 @@ public class MultiStartUnivariateRealOpt
             assertEquals(-1.0, f.value(optima[i].getPoint()), 1.0e-10);
             assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1.0e-10);
         }
-        assertTrue(optimizer.getEvaluations() > 150);
-        assertTrue(optimizer.getEvaluations() < 250);
+        assertTrue(optimizer.getEvaluations() > 200);
+        assertTrue(optimizer.getEvaluations() < 300);
     }
 
     @Test
@@ -68,14 +68,14 @@ public class MultiStartUnivariateRealOpt
 
         UnivariateRealPointValuePair optimum
             = optimizer.optimize(f, GoalType.MINIMIZE, -0.3, -0.2);
-        assertEquals(-0.2719561271, optimum.getPoint(), 1e-9);
+        assertEquals(-0.2719561293, optimum.getPoint(), 1e-9);
         assertEquals(-0.0443342695, optimum.getValue(), 1e-9);
 
         UnivariateRealPointValuePair[] optima = optimizer.getOptima();
         for (int i = 0; i < optima.length; ++i) {
             assertEquals(f.value(optima[i].getPoint()), optima[i].getValue(), 1e-9);
         }
-        assertTrue(optimizer.getEvaluations() >= 110);
-        assertTrue(optimizer.getEvaluations() <= 150);
+        assertTrue(optimizer.getEvaluations() >= 50);
+        assertTrue(optimizer.getEvaluations() <= 100);
     }
 }



Mime
View raw message