You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2009/07/19 22:04:57 UTC

svn commit: r795607 - /commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java

Author: luc
Date: Sun Jul 19 20:04:56 2009
New Revision: 795607

URL: http://svn.apache.org/viewvc?rev=795607&view=rev
Log:
changing multistart behaviour to rely on search domain boundary rather than on start point
the only implementation of the raw minimizer ignores the start point so the multistart optimizer always found the same point before the change

Modified:
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java?rev=795607&r1=795606&r2=795607&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiStartUnivariateRealOptimizer.java Sun Jul 19 20:04:56 2009
@@ -198,13 +198,6 @@
                            final double min, final double max)
         throws ConvergenceException,
             FunctionEvaluationException {
-        return optimize(f, goalType, min, max, min + generator.nextDouble() * (max - min));
-    }
-
-    /** {@inheritDoc} */
-    public double optimize(final UnivariateRealFunction f, final GoalType goalType,
-                           final double min, final double max, final double startValue)
-            throws ConvergenceException, FunctionEvaluationException {
 
         optima           = new double[starts];
         totalIterations  = 0;
@@ -216,8 +209,11 @@
             try {
                 optimizer.setMaximalIterationCount(maxIterations - totalIterations);
                 optimizer.setMaxEvaluations(maxEvaluations - totalEvaluations);
-                optima[i] = optimizer.optimize(f, goalType, min, max,
-                                               (i == 0) ? startValue : generator.nextDouble() * (max - min));
+                final double bound1 = min + generator.nextDouble() * (max - min);
+                final double bound2 = min + generator.nextDouble() * (max - min);
+                optima[i] = optimizer.optimize(f, goalType,
+                                               Math.min(bound1, bound2),
+                                               Math.max(bound1, bound2));
             } catch (FunctionEvaluationException fee) {
                 optima[i] = Double.NaN;
             } catch (ConvergenceException ce) {
@@ -257,4 +253,11 @@
 
     }
 
+    /** {@inheritDoc} */
+    public double optimize(final UnivariateRealFunction f, final GoalType goalType,
+                           final double min, final double max, final double startValue)
+            throws ConvergenceException, FunctionEvaluationException {
+        return optimize(f, goalType, min, max);
+    }
+
 }