commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1043078 [1/2] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/optimization/ main/java/org/apache/commons/math/optimization/direct/ main/java/org/apache/commons/math/optimization/fitting/ main/java/org/apache/commons/...
Date Tue, 07 Dec 2010 15:01:38 GMT
Author: erans
Date: Tue Dec  7 15:01:37 2010
New Revision: 1043078

URL: http://svn.apache.org/viewvc?rev=1043078&view=rev
Log:
MATH-454
Pass the number of allowed function evaluations as a parameter to the
"optimize" methods.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateVectorialOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/SimplexOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BaseUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/MultiStartUnivariateRealOptimizer.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/GaussNewtonOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/MinpackTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/general/NonLinearConjugateGradientOptimizerTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/univariate/BrentOptimizerTest.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/BaseMultiStartMultivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateRealOptimizer.java Tue Dec  7 15:01:37 2010
@@ -73,13 +73,13 @@ public class BaseMultiStartMultivariateR
 
     /**
      * Get all the optima found during the last call to {@link
-     * #optimize(MultivariateRealFunction,GoalType,double[]) optimize}.
+     * #optimize(int,MultivariateRealFunction,GoalType,double[]) optimize}.
      * The optimizer stores all the optima found during a set of
-     * restarts. The {@link #optimize(MultivariateRealFunction,GoalType,double[])
+     * restarts. The {@link #optimize(int,MultivariateRealFunction,GoalType,double[])
      * optimize} method returns the best point only. This method
      * returns all the points found at the end of each starts,
      * including the best one already returned by the {@link
-     * #optimize(MultivariateRealFunction,GoalType,double[]) optimize} method.
+     * #optimize(int,MultivariateRealFunction,GoalType,double[]) optimize} method.
      * <br/>
      * The returned array as one element for each start as specified
      * in the constructor. It is ordered with the results from the
@@ -87,14 +87,14 @@ public class BaseMultiStartMultivariateR
      * objective value (i.e in ascending order if minimizing and in
      * descending order if maximizing), followed by and null elements
      * corresponding to the runs that did not converge. This means all
-     * elements will be null if the {@link #optimize(MultivariateRealFunction,GoalType,double[])
+     * elements will be null if the {@link #optimize(int,MultivariateRealFunction,GoalType,double[])
      * optimize} method did throw a {@link MathUserException}).
      * This also means that if the first element is not {@code null}, it
      * is the best point found across all starts.
      *
      * @return an array containing the optima.
      * @throws MathIllegalStateException if {@link
-     * #optimize(MultivariateRealFunction,GoalType,double[]) optimize}
+     * #optimize(int,MultivariateRealFunction,GoalType,double[]) optimize}
      * has not been called.
      */
     public RealPointValuePair[] getOptima() {
@@ -115,12 +115,6 @@ public class BaseMultiStartMultivariateR
     }
 
     /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        this.maxEvaluations = maxEvaluations;
-        optimizer.setMaxEvaluations(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
     public void setConvergenceChecker(ConvergenceChecker<RealPointValuePair> checker) {
         optimizer.setConvergenceChecker(checker);
     }
@@ -133,9 +127,10 @@ public class BaseMultiStartMultivariateR
     /**
      * {@inheritDoc}
      */
-    public RealPointValuePair optimize(final FUNC f,
+    public RealPointValuePair optimize(int maxEval, final FUNC f,
                                        final GoalType goal,
-                                       double[] startPoint) throws MathUserException {
+                                       double[] startPoint) {
+        maxEvaluations = maxEval;
         MathUserException lastException = null;
         optima = new RealPointValuePair[starts];
         totalEvaluations = 0;
@@ -143,16 +138,14 @@ public class BaseMultiStartMultivariateR
         // Multi-start loop.
         for (int i = 0; i < starts; ++i) {
             try {
-                optima[i] = optimizer.optimize(f, goal,
+                optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, goal,
                                                i == 0 ? startPoint : generator.nextVector());
             } catch (MathUserException mue) {
                 lastException = mue;
                 optima[i] = null;
             }
 
-            final int usedEvaluations = optimizer.getEvaluations();
-            optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
-            totalEvaluations += usedEvaluations;
+            totalEvaluations += optimizer.getEvaluations();
         }
 
         sortPairs(goal);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultiStartMultivariateVectorialOptimizer.java Tue Dec  7 15:01:37 2010
@@ -73,13 +73,13 @@ public class BaseMultiStartMultivariateV
 
     /**
      * Get all the optima found during the last call to {@link
-     * #optimize(MultivariateVectorialFunction,double[],double[],double[]) optimize}.
+     * #optimize(int,MultivariateVectorialFunction,double[],double[],double[]) optimize}.
      * The optimizer stores all the optima found during a set of
-     * restarts. The {@link #optimize(MultivariateVectorialFunction,double[],double[],double[])
+     * restarts. The {@link #optimize(int,MultivariateVectorialFunction,double[],double[],double[])
      * optimize} method returns the best point only. This method
      * returns all the points found at the end of each starts, including
      * the best one already returned by the {@link
-     * #optimize(MultivariateVectorialFunction,double[],double[],double[]) optimize} method.
+     * #optimize(int,MultivariateVectorialFunction,double[],double[],double[]) optimize} method.
      * <br/>
      * The returned array as one element for each start as specified
      * in the constructor. It is ordered with the results from the
@@ -88,14 +88,14 @@ public class BaseMultiStartMultivariateV
      * descending order if maximizing), followed by and null elements
      * corresponding to the runs that did not converge. This means all
      * elements will be null if the {@link
-     * #optimize(MultivariateVectorialFunction,double[],double[],double[]) optimize} method did
+     * #optimize(int,MultivariateVectorialFunction,double[],double[],double[]) optimize} method did
      * throw a {@link ConvergenceException}). This also means that if
      * the first element is not {@code null}, it is the best point found
      * across all starts.
      *
      * @return array containing the optima
      * @throws MathIllegalStateException if {@link
-     * #optimize(MultivariateVectorialFunction,double[],double[],double[]) optimize} has not been
+     * #optimize(int,MultivariateVectorialFunction,double[],double[],double[]) optimize} has not been
      * called.
      */
     public VectorialPointValuePair[] getOptima() {
@@ -116,12 +116,6 @@ public class BaseMultiStartMultivariateV
     }
 
     /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        this.maxEvaluations = maxEvaluations;
-        optimizer.setMaxEvaluations(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
     public void setConvergenceChecker(ConvergenceChecker<VectorialPointValuePair> checker) {
         optimizer.setConvergenceChecker(checker);
     }
@@ -134,19 +128,19 @@ public class BaseMultiStartMultivariateV
     /**
      * {@inheritDoc}
      */
-    public VectorialPointValuePair optimize(final FUNC f,
+    public VectorialPointValuePair optimize(int maxEval, final FUNC f,
                                             double[] target, double[] weights,
-                                            double[] startPoint)
-        throws MathUserException {
-
+                                            double[] startPoint) {
+        maxEvaluations = maxEval;
         MathUserException lastException = null;
         optima = new VectorialPointValuePair[starts];
+        totalEvaluations = 0;
 
         // Multi-start loop.
         for (int i = 0; i < starts; ++i) {
 
             try {
-                optima[i] = optimizer.optimize(f, target, weights,
+                optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, target, weights,
                                                i == 0 ? startPoint : generator.nextVector());
             } catch (MathUserException mue) {
                 lastException = mue;
@@ -155,9 +149,7 @@ public class BaseMultiStartMultivariateV
                 optima[i] = null;
             }
 
-            final int usedEvaluations = optimizer.getEvaluations();
-            optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
-            totalEvaluations += usedEvaluations;
+            totalEvaluations += optimizer.getEvaluations();
         }
 
         sortPairs(target, weights);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateRealOptimizer.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization;
 
 import org.apache.commons.math.analysis.MultivariateRealFunction;
-import org.apache.commons.math.exception.MathUserException;
 
 /**
  * This interface is mainly intended to enforce the internal coherence of
@@ -43,6 +42,7 @@ public interface BaseMultivariateRealOpt
      * @param goalType Type of optimization goal: either
      * {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}.
      * @param startPoint Start point for optimization.
+     * @param maxEval Maximum number of function evaluations.
      * @return the point/value pair giving the optimal value for objective
      * function.
      * @throws org.apache.commons.math.exception.DimensionMismatchException
@@ -51,7 +51,9 @@ public interface BaseMultivariateRealOpt
      * if the maximal number of evaluations is exceeded.
      * @throws org.apache.commons.math.exception.NullArgumentException if
      * any argument is {@code null}.
-     * @throws MathUserException if objective function throws one during search
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * objective function throws one during search.
      */
-    RealPointValuePair optimize(FUNC f, GoalType goalType, double[] startPoint) throws MathUserException;
+    RealPointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
+                                double[] startPoint);
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateVectorialOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateVectorialOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateVectorialOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseMultivariateVectorialOptimizer.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization;
 
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;
-import org.apache.commons.math.exception.MathUserException;
 
 /**
  * This interface is mainly intended to enforce the internal coherence of
@@ -47,14 +46,16 @@ public interface BaseMultivariateVectori
      * @param startPoint Start point for optimization.
      * @return the point/value pair giving the optimal value for objective
      * function.
+     * @param maxEval Maximum number of function evaluations.
      * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if the start point dimension is wrong.
      * @throws org.apache.commons.math.exception.TooManyEvaluationsException
      * if the maximal number of evaluations is exceeded.
      * @throws org.apache.commons.math.exception.NullArgumentException if
      * any argument is {@code null}.
-     * @throws MathUserException if function throws one during search.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * function throws one during search.
      */
-    VectorialPointValuePair optimize(FUNC f, double[] target, double[] weight,
-                                     double[] startPoint) throws MathUserException;
+    VectorialPointValuePair optimize(int maxEval, FUNC f, double[] target,
+                                     double[] weight, double[] startPoint);
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/BaseOptimizer.java Tue Dec  7 15:01:37 2010
@@ -35,13 +35,6 @@ package org.apache.commons.math.optimiza
  */
 public interface BaseOptimizer<PAIR> {
     /**
-     * Set the maximal number of function evaluations.
-     *
-     * @param maxEvaluations Maximal number of function evaluations.
-     */
-    void setMaxEvaluations(int maxEvaluations);
-
-    /**
      * Get the maximal number of function evaluations.
      *
      * @return the maximal number of function evaluations.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractScalarOptimizer.java Tue Dec  7 15:01:37 2010
@@ -58,21 +58,13 @@ public abstract class BaseAbstractScalar
      * the allowed number of evaluations is set to {@link Integer#MAX_VALUE}.
      */
     protected BaseAbstractScalarOptimizer() {
-        this(new SimpleScalarValueChecker(), Integer.MAX_VALUE);
+        this(new SimpleScalarValueChecker());
     }
     /**
      * @param checker Convergence checker.
-     * @param maxEvaluations Maximum number of function evaluations.
      */
-    protected BaseAbstractScalarOptimizer(ConvergenceChecker<RealPointValuePair> checker,
-                                          int maxEvaluations) {
+    protected BaseAbstractScalarOptimizer(ConvergenceChecker<RealPointValuePair> checker) {
         this.checker = checker;
-        evaluations.setMaximalCount(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        evaluations.setMaximalCount(maxEvaluations);
     }
 
     /** {@inheritDoc} */
@@ -102,9 +94,10 @@ public abstract class BaseAbstractScalar
      * @return the objective function value at the specified point.
      * @throws TooManyEvaluationsException if the maximal number of
      * evaluations is exceeded.
-     * @throws MathUserException if objective function throws one
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * objective function throws one.
      */
-    protected double computeObjectiveValue(double[] point) throws MathUserException {
+    protected double computeObjectiveValue(double[] point) {
         try {
             evaluations.incrementCount();
         } catch (MaxCountExceededException e) {
@@ -114,9 +107,8 @@ public abstract class BaseAbstractScalar
     }
 
     /** {@inheritDoc} */
-    public RealPointValuePair optimize(FUNC f,
-                                       GoalType goalType,
-                                       double[] startPoint) throws MathUserException {
+    public RealPointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
+                                       double[] startPoint) {
         // Checks.
         if (f == null) {
             throw new NullArgumentException();
@@ -129,6 +121,7 @@ public abstract class BaseAbstractScalar
         }
 
         // Reset.
+        evaluations.setMaximalCount(maxEval);
         evaluations.resetCount();
 
         // Store optimization problem characteristics.
@@ -157,8 +150,10 @@ public abstract class BaseAbstractScalar
     /**
      * Perform the bulk of the optimization algorithm.
      *
-     * @return the point/value pair giving the optimal value for objective function.
-     * @throws MathUserException if objective function throws one
+     * @return the point/value pair giving the optimal value for the
+     * objective function.
+     * @throws org.apache.commons.math.exception.MathUserException if
+     * the objective function throws one.
      */
-    protected abstract RealPointValuePair doOptimize() throws MathUserException;
+    protected abstract RealPointValuePair doOptimize();
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/BaseAbstractVectorialOptimizer.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization.direct;
 
 import org.apache.commons.math.util.Incrementor;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.exception.DimensionMismatchException;
@@ -60,21 +59,13 @@ public abstract class BaseAbstractVector
      * the allowed number of evaluations is set to {@link Integer#MAX_VALUE}.
      */
     protected BaseAbstractVectorialOptimizer() {
-        this(new SimpleVectorialValueChecker(),  Integer.MAX_VALUE);
+        this(new SimpleVectorialValueChecker());
     }
     /**
      * @param checker Convergence checker.
-     * @param maxEvaluations Maximum number of function evaluations.
      */
-    protected BaseAbstractVectorialOptimizer(ConvergenceChecker<VectorialPointValuePair> checker,
-                                             int maxEvaluations) {
+    protected BaseAbstractVectorialOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
         this.checker = checker;
-        evaluations.setMaximalCount(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        evaluations.setMaximalCount(maxEvaluations);
     }
 
     /** {@inheritDoc} */
@@ -104,9 +95,10 @@ public abstract class BaseAbstractVector
      * @return the objective function value at the specified point.
      * @throws TooManyEvaluationsException if the maximal number of evaluations is
      * exceeded.
-     * @throws MathUserException if objective function throws one
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * objective function throws one.
      */
-    protected double[] computeObjectiveValue(double[] point) throws MathUserException {
+    protected double[] computeObjectiveValue(double[] point) {
         try {
             evaluations.incrementCount();
         } catch (MaxCountExceededException e) {
@@ -116,8 +108,8 @@ public abstract class BaseAbstractVector
     }
 
     /** {@inheritDoc} */
-    public VectorialPointValuePair optimize(FUNC f, double[] t, double[] w, double[] startPoint)
-        throws MathUserException {
+    public VectorialPointValuePair optimize(int maxEval, FUNC f, double[] t, double[] w,
+                                            double[] startPoint) {
         // Checks.
         if (f == null) {
             throw new NullArgumentException();
@@ -136,6 +128,7 @@ public abstract class BaseAbstractVector
         }
 
         // Reset.
+        evaluations.setMaximalCount(maxEval);
         evaluations.resetCount();
 
         // Store optimization problem characteristics.
@@ -158,10 +151,12 @@ public abstract class BaseAbstractVector
     /**
      * Perform the bulk of the optimization algorithm.
      *
-     * @return the point/value pair giving the optimal value for objective function
-     * @throws MathUserException if function throws one during search.
+     * @return the point/value pair giving the optimal value for the
+     * objective function.
+     * @throws org.apache.commons.math.exception.MathUserException if
+     * the function throws one during search.
      */
-    protected abstract VectorialPointValuePair doOptimize() throws MathUserException;
+    protected abstract VectorialPointValuePair doOptimize();
 
     /**
      * @return a reference to the {@link #target array}.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java Tue Dec  7 15:01:37 2010
@@ -20,7 +20,6 @@ package org.apache.commons.math.optimiza
 import org.apache.commons.math.util.FastMath;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.NumberIsTooSmallException;
 import org.apache.commons.math.exception.NotStrictlyPositiveException;
 import org.apache.commons.math.optimization.GoalType;
@@ -96,19 +95,7 @@ public class PowellOptimizer
 
     /** {@inheritDoc} */
     @Override
-    public void setMaxEvaluations(int maxEvaluations) {
-        super.setMaxEvaluations(maxEvaluations);
-
-        // We must allow at least as many iterations to the underlying line
-        // search optimizer. Because the line search inner class will call
-        // "computeObjectiveValue" in this class, we ensure that this class
-        // will be the first to eventually throw "TooManyEvaluationsException".
-        line.setMaxEvaluations(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
-    @Override
-    protected RealPointValuePair doOptimize() throws MathUserException {
+    protected RealPointValuePair doOptimize() {
         final GoalType goal = getGoalType();
         final double[] guess = getStartPoint();
         final int n = guess.length;
@@ -255,13 +242,13 @@ public class PowellOptimizer
          * @return the optimum.
          * @throws org.apache.commons.math.exception.TooManyEvaluationsException
          * if the number of evaluations is exceeded.
-         * @throws MathUserException if objective function throws one.
+         * @throws org.apache.commons.math.exception.MathUserException if the
+         * objective function throws one.
          */
-        public UnivariateRealPointValuePair search(final double[] p, final double[] d)
-            throws MathUserException {
+        public UnivariateRealPointValuePair search(final double[] p, final double[] d) {
             final int n = p.length;
             final UnivariateRealFunction f = new UnivariateRealFunction() {
-                    public double value(double alpha) throws MathUserException {
+                    public double value(double alpha) {
                         final double[] x = new double[n];
                         for (int i = 0; i < n; i++) {
                             x[i] = p[i] + alpha * d[i];
@@ -273,8 +260,11 @@ public class PowellOptimizer
 
             final GoalType goal = PowellOptimizer.this.getGoalType();
             bracket.search(f, goal, 0, 1);
-            return optimize(f, goal, bracket.getLo(), bracket.getHi(),
-                            bracket.getMid());
+            // Passing "MAX_VALUE" as a dummy value because it is the enclosing
+            // class that counts the number of evaluations (and will eventually
+            // generate the exception).
+            return optimize(Integer.MAX_VALUE, f, goal,
+                            bracket.getLo(), bracket.getHi(), bracket.getMid());
         }
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/SimplexOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/SimplexOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/SimplexOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/SimplexOptimizer.java Tue Dec  7 15:01:37 2010
@@ -55,7 +55,7 @@ import org.apache.commons.math.optimizat
  *  be called prior to calling the {@code optimize} method.
  * </p>
  * <p>
- *  Each call to {@link #optimize(MultivariateRealFunction,GoalType,double[])
+ *  Each call to {@link #optimize(int,MultivariateRealFunction,GoalType,double[])
  *  optimize} will re-use the start configuration of the current simplex and
  *  move it such that its first vertex is at the provided start point of the
  *  optimization. If the {@code optimize} method is called to solve a different

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/fitting/CurveFitter.java Tue Dec  7 15:01:37 2010
@@ -40,10 +40,8 @@ import org.apache.commons.math.optimizat
  * @since 2.0
  */
 public class CurveFitter {
-
     /** Optimizer to use for the fitting. */
     private final DifferentiableMultivariateVectorialOptimizer optimizer;
-
     /** Observed points. */
     private final List<WeightedObservedPoint> observations;
 
@@ -109,22 +107,45 @@ public class CurveFitter {
         observations.clear();
     }
 
-    /** Fit a curve.
-     * <p>This method compute the coefficients of the curve that best
+    /**
+     * Fit a curve.
+     * This method compute the coefficients of the curve that best
+     * fit the sample of observed points previously given through calls
+     * to the {@link #addObservedPoint(WeightedObservedPoint)
+     * addObservedPoint} method.
+     *
+     * @param f parametric function to fit.
+     * @param initialGuess first guess of the function parameters.
+     * @return the fitted parameters.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
+     * if the start point dimension is wrong.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * parametric function throws one.
+     */
+    public double[] fit(final ParametricRealFunction f, final double[] initialGuess) {
+        return fit(Integer.MAX_VALUE, f, initialGuess);
+    }
+
+    /**
+     * Fit a curve.
+     * This method compute the coefficients of the curve that best
      * fit the sample of observed points previously given through calls
      * to the {@link #addObservedPoint(WeightedObservedPoint)
-     * addObservedPoint} method.</p>
-     * @param f parametric function to fit
-     * @param initialGuess first guess of the function parameters
-     * @return fitted parameters
-     * @exception org.apache.commons.math.exception.ConvergenceException
-     * if the algorithm failed to converge.
-     * @exception org.apache.commons.math.exception.DimensionMismatchException
+     * addObservedPoint} method.
+     *
+     * @param f parametric function to fit.
+     * @param initialGuess first guess of the function parameters.
+     * @param maxEval Maximum number of function evaluations.
+     * @return the fitted parameters.
+     * @throws org.apache.commons.math.exception.TooManyEvaluationsException
+     * if the number of allowed evaluations is exceeded.
+     * @throws org.apache.commons.math.exception.DimensionMismatchException
      * if the start point dimension is wrong.
-     * @throws MathUserException if the parametric function throws one
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * parametric function throws one.
      */
-    public double[] fit(final ParametricRealFunction f,
-                        final double[] initialGuess) throws MathUserException {
+    public double[] fit(int maxEval, final ParametricRealFunction f,
+                        final double[] initialGuess) {
         // prepare least squares problem
         double[] target  = new double[observations.size()];
         double[] weights = new double[observations.size()];
@@ -137,7 +158,8 @@ public class CurveFitter {
 
         // perform the fit
         VectorialPointValuePair optimum =
-            optimizer.optimize(new TheoreticalValuesFunction(f), target, weights, initialGuess);
+            optimizer.optimize(maxEval, new TheoreticalValuesFunction(f),
+                               target, weights, initialGuess);
 
         // extract the coefficients
         return optimum.getPointRef();

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java Tue Dec  7 15:01:37 2010
@@ -78,11 +78,9 @@ public abstract class AbstractLeastSquar
     protected AbstractLeastSquaresOptimizer() {}
     /**
      * @param checker Convergence checker.
-     * @param maxEvaluations Maximal number of function evaluations.
      */
-    protected AbstractLeastSquaresOptimizer(ConvergenceChecker<VectorialPointValuePair> checker,
-                                            int maxEvaluations) {
-        super(checker, maxEvaluations);
+    protected AbstractLeastSquaresOptimizer(ConvergenceChecker<VectorialPointValuePair> checker) {
+        super(checker);
     }
 
     /**
@@ -231,7 +229,8 @@ public abstract class AbstractLeastSquar
 
     /** {@inheritDoc} */
     @Override
-    public VectorialPointValuePair optimize(final DifferentiableMultivariateVectorialFunction f,
+    public VectorialPointValuePair optimize(int maxEval,
+                                            final DifferentiableMultivariateVectorialFunction f,
                                             final double[] target, final double[] weights,
                                             final double[] startPoint) {
         // Reset counter.
@@ -251,6 +250,6 @@ public abstract class AbstractLeastSquar
 
         cost = Double.POSITIVE_INFINITY;
 
-        return super.optimize(f, target, weights, startPoint);
+        return super.optimize(maxEval, f, target, weights, startPoint);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/general/AbstractScalarDifferentiableOptimizer.java Tue Dec  7 15:01:37 2010
@@ -51,11 +51,9 @@ public abstract class AbstractScalarDiff
     protected AbstractScalarDifferentiableOptimizer() {}
     /**
      * @param checker Convergence checker.
-     * @param maxEvaluations Maximum number of function evaluations.
      */
-    protected AbstractScalarDifferentiableOptimizer(ConvergenceChecker<RealPointValuePair> checker,
-                                                    int maxEvaluations) {
-        super(checker, maxEvaluations);
+    protected AbstractScalarDifferentiableOptimizer(ConvergenceChecker<RealPointValuePair> checker) {
+        super(checker);
     }
 
     /**
@@ -74,12 +72,13 @@ public abstract class AbstractScalarDiff
 
     /** {@inheritDoc} */
     @Override
-    public RealPointValuePair optimize(final DifferentiableMultivariateRealFunction f,
+    public RealPointValuePair optimize(int maxEval,
+                                       final DifferentiableMultivariateRealFunction f,
                                        final GoalType goalType,
                                        final double[] startPoint) throws MathUserException {
         // Store optimization problem characteristics.
         gradient = f.gradient();
 
-        return super.optimize(f, goalType, startPoint);
+        return super.optimize(maxEval, f, goalType, startPoint);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/AbstractUnivariateRealOptimizer.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization.univariate;
 
 import org.apache.commons.math.util.Incrementor;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.MaxCountExceededException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.exception.NullArgumentException;
@@ -51,11 +50,6 @@ public abstract class AbstractUnivariate
     private UnivariateRealFunction function;
 
     /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        evaluations.setMaximalCount(maxEvaluations);
-    }
-
-    /** {@inheritDoc} */
     public int getMaxEvaluations() {
         return evaluations.getMaximalCount();
     }
@@ -97,9 +91,10 @@ public abstract class AbstractUnivariate
      * @return the objective function value at specified point.
      * @throws TooManyEvaluationsException if the maximal number of evaluations
      * is exceeded.
-     * @throws MathUserException if objective function throws one
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * objective function throws one.
      */
-    protected double computeObjectiveValue(double point) throws MathUserException {
+    protected double computeObjectiveValue(double point) {
         try {
             evaluations.incrementCount();
         } catch (MaxCountExceededException e) {
@@ -109,10 +104,10 @@ public abstract class AbstractUnivariate
     }
 
     /** {@inheritDoc} */
-    public UnivariateRealPointValuePair optimize(UnivariateRealFunction f,
+    public UnivariateRealPointValuePair optimize(int maxEval, UnivariateRealFunction f,
                                                  GoalType goalType,
                                                  double min, double max,
-                                                 double startValue) throws MathUserException {
+                                                 double startValue) {
         // Checks.
         if (f == null) {
             throw new NullArgumentException();
@@ -127,6 +122,7 @@ public abstract class AbstractUnivariate
         searchStart = startValue;
         goal = goalType;
         function = f;
+        evaluations.setMaximalCount(maxEval);
         evaluations.resetCount();
 
         // Perform computation.
@@ -134,10 +130,11 @@ public abstract class AbstractUnivariate
     }
 
     /** {@inheritDoc} */
-    public UnivariateRealPointValuePair optimize(UnivariateRealFunction f,
+    public UnivariateRealPointValuePair optimize(int maxEval,
+                                                 UnivariateRealFunction f,
                                                  GoalType goalType,
-                                                 double min, double max) throws MathUserException {
-        return optimize(f, goalType, min, max, min + 0.5 * (max - min));
+                                                 double min, double max){
+        return optimize(maxEval, f, goalType, min, max, min + 0.5 * (max - min));
     }
 
     /**
@@ -161,7 +158,8 @@ public abstract class AbstractUnivariate
      * @return the optimum and its corresponding function value.
      * @throws TooManyEvaluationsException if the maximal number of evaluations
      * is exceeded.
-     * @throws MathUserException if the function to optimize throws one during search.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * function to optimize throws one during search.
      */
-    protected abstract UnivariateRealPointValuePair doOptimize() throws MathUserException;
+    protected abstract UnivariateRealPointValuePair doOptimize();
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BaseUnivariateRealOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BaseUnivariateRealOptimizer.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BaseUnivariateRealOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/univariate/BaseUnivariateRealOptimizer.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization.univariate;
 
 import org.apache.commons.math.analysis.UnivariateRealFunction;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.optimization.BaseOptimizer;
 import org.apache.commons.math.optimization.GoalType;
 
@@ -47,6 +46,7 @@ public interface BaseUnivariateRealOptim
      * {@link GoalType#MAXIMIZE} or {@link GoalType#MINIMIZE}.
      * @param min Lower bound for the interval.
      * @param max Upper bound for the interval.
+     * @param maxEval Maximum number of function evaluations.
      * @return a (point, value) pair where the function is optimum.
      * @throws org.apache.commons.math.exception.TooManyEvaluationsException
      * if the maximum evaluation count is exceeded.
@@ -54,10 +54,11 @@ public interface BaseUnivariateRealOptim
      * if the optimizer detects a convergence problem.
      * @throws IllegalArgumentException if {@code min > max} or the endpoints
      * do not satisfy the requirements specified by the optimizer.
-     * @throws MathUserException if the function to optimize throws one during search.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * function to optimize throws one during search.
      */
-    UnivariateRealPointValuePair optimize(FUNC f, GoalType goalType,
-                                          double min, double max) throws MathUserException;
+    UnivariateRealPointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
+                                          double min, double max);
 
     /**
      * Find an optimum in the given interval, start at startValue.
@@ -69,6 +70,7 @@ public interface BaseUnivariateRealOptim
      * @param min Lower bound for the interval.
      * @param max Upper bound for the interval.
      * @param startValue Start value to use.
+     * @param maxEval Maximum number of function evaluations.
      * @return a (point, value) pair where the function is optimum.
      * @throws org.apache.commons.math.exception.TooManyEvaluationsException
      * if the maximum evaluation count is exceeded.
@@ -78,9 +80,10 @@ public interface BaseUnivariateRealOptim
      * do not satisfy the requirements specified by the optimizer.
      * @throws org.apache.commons.math.exception.NullArgumentException if any
      * argument is {@code null}.
-     * @throws MathUserException if the function to optimize throws one during search.
+     * @throws org.apache.commons.math.exception.MathUserException if the
+     * function to optimize throws one during search.
      */
-    UnivariateRealPointValuePair optimize(FUNC f, GoalType goalType,
+    UnivariateRealPointValuePair optimize(int maxEval, FUNC f, GoalType goalType,
                                           double min, double max,
-                                          double startValue) throws MathUserException;
+                                          double startValue);
 }

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=1043078&r1=1043077&r2=1043078&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 Tue Dec  7 15:01:37 2010
@@ -97,20 +97,14 @@ public class MultiStartUnivariateRealOpt
         return totalEvaluations;
     }
 
-    /** {@inheritDoc} */
-    public void setMaxEvaluations(int maxEvaluations) {
-        this.maxEvaluations = maxEvaluations;
-        optimizer.setMaxEvaluations(maxEvaluations);
-    }
-
     /**
      * Get all the optima found during the last call to {@link
-     * #optimize(UnivariateRealFunction,GoalType,double,double) optimize}.
+     * #optimize(int,UnivariateRealFunction,GoalType,double,double) optimize}.
      * The optimizer stores all the optima found during a set of
-     * restarts. The {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}
+     * restarts. The {@link #optimize(int,UnivariateRealFunction,GoalType,double,double) optimize}
      * method returns the best point only. This method returns all the points
      * found at the end of each starts, including the best one already
-     * returned by the {@link #optimize(UnivariateRealFunction,GoalType,double,double) optimize}
+     * returned by the {@link #optimize(int,UnivariateRealFunction,GoalType,double,double) optimize}
      * method.
      * <br/>
      * The returned array as one element for each start as specified
@@ -120,14 +114,14 @@ public class MultiStartUnivariateRealOpt
      * descending order if maximizing), followed by {@code null} elements
      * corresponding to the runs that did not converge. This means all
      * elements will be {@code null} if the {@link
-     * #optimize(UnivariateRealFunction,GoalType,double,double) optimize}
-     * method did throw a {@link MathUserException}). This also means that
-     * if the first element is not {@code null}, it is the best point found
-     * across all starts.
+     * #optimize(int,UnivariateRealFunction,GoalType,double,double) optimize}
+     * method did throw a {@link MathUserException}).
+     * This also means that if the first element is not {@code null}, it is
+     * the best point found across all starts.
      *
      * @return an array containing the optima.
      * @throws MathIllegalStateException if {@link
-     * #optimize(UnivariateRealFunction,GoalType,double,double) optimize}
+     * #optimize(int,UnivariateRealFunction,GoalType,double,double) optimize}
      * has not been called.
      */
     public UnivariateRealPointValuePair[] getOptima() {
@@ -138,18 +132,17 @@ public class MultiStartUnivariateRealOpt
     }
 
     /** {@inheritDoc} */
-    public UnivariateRealPointValuePair optimize(final FUNC f,
+    public UnivariateRealPointValuePair optimize(int maxEval, final FUNC f,
                                                  final GoalType goal,
-                                                 final double min, final double max)
-        throws MathUserException {
-        return optimize(f, goal, min, max, min + 0.5 * (max - min));
+                                                 final double min, final double max) {
+        return optimize(maxEval, f, goal, min, max, min + 0.5 * (max - min));
     }
 
     /** {@inheritDoc} */
-    public UnivariateRealPointValuePair optimize(final FUNC f, final GoalType goal,
+    public UnivariateRealPointValuePair optimize(int maxEval, final FUNC f,
+                                                 final GoalType goal,
                                                  final double min, final double max,
-                                                 final double startValue)
-        throws MathUserException {
+                                                 final double startValue) {
         MathUserException lastException = null;
         optima = new UnivariateRealPointValuePair[starts];
         totalEvaluations = 0;
@@ -158,15 +151,13 @@ public class MultiStartUnivariateRealOpt
         for (int i = 0; i < starts; ++i) {
             try {
                 final double s = (i == 0) ? startValue : min + generator.nextDouble() * (max - min);
-                optima[i] = optimizer.optimize(f, goal, min, max, s);
+                optima[i] = optimizer.optimize(maxEval - totalEvaluations, f, goal, min, max, s);
             } catch (MathUserException mue) {
                 lastException = mue;
                 optima[i] = null;
             }
 
-            final int usedEvaluations = optimizer.getEvaluations();
-            optimizer.setMaxEvaluations(optimizer.getMaxEvaluations() - usedEvaluations);
-            totalEvaluations += usedEvaluations;
+            totalEvaluations += optimizer.getEvaluations();
         }
 
         sortPairs(goal);

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Tue Dec  7 15:01:37 2010
@@ -52,8 +52,12 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-454">
+        For optimizers (package "optimization"), the number of allowed function
+        evaluations is passed as a parameter to the "optimize" method.
+      </action>
       <action dev="erans" type="fix" issue="MATH-451">
-        For "solvers" (package "analysis.solvers"), the number of allowed function
+        For solvers (package "analysis.solvers"), the number of allowed function
         evaluations is passed as a parameter to the "solve" method.
       </action>
       <action dev="erans" type="fix" issue="MATH-447">

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateRealOptimizerTest.java Tue Dec  7 15:01:37 2010
@@ -27,7 +27,6 @@ import org.apache.commons.math.analysis.
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;
 import org.apache.commons.math.analysis.solvers.BrentSolver;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.optimization.general.ConjugateGradientFormula;
 import org.apache.commons.math.optimization.general.NonLinearConjugateGradientOptimizer;
 import org.apache.commons.math.random.GaussianRandomGenerator;
@@ -39,7 +38,7 @@ import org.junit.Test;
 public class MultiStartDifferentiableMultivariateRealOptimizerTest {
 
     @Test
-    public void testCircleFitting() throws MathUserException {
+    public void testCircleFitting() {
         Circle circle = new Circle();
         circle.addPoint( 30.0,  68.0);
         circle.addPoint( 50.0,  -6.0);
@@ -55,12 +54,11 @@ public class MultiStartDifferentiableMul
                                                   new GaussianRandomGenerator(g));
         MultiStartDifferentiableMultivariateRealOptimizer optimizer =
             new MultiStartDifferentiableMultivariateRealOptimizer(underlying, 10, generator);
-        optimizer.setMaxEvaluations(200);
-        assertEquals(200, optimizer.getMaxEvaluations());
         optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1.0e-10, 1.0e-10));
         BrentSolver solver = new BrentSolver();
         RealPointValuePair optimum =
-            optimizer.optimize(circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
+            optimizer.optimize(200, circle, GoalType.MINIMIZE, new double[] { 98.680, 47.345 });
+        assertEquals(200, optimizer.getMaxEvaluations());
         RealPointValuePair[] optima = optimizer.getOptima();
         for (RealPointValuePair o : optima) {
             Point2D.Double center = new Point2D.Double(o.getPointRef()[0], o.getPointRef()[1]);
@@ -113,8 +111,7 @@ public class MultiStartDifferentiableMul
             return new double[] { dJdX, dJdY };
         }
 
-        public double value(double[] variables)
-        throws IllegalArgumentException, MathUserException {
+        public double value(double[] variables) {
 
             Point2D.Double center = new Point2D.Double(variables[0], variables[1]);
             double radius = getRadius(center);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartDifferentiableMultivariateVectorialOptimizerTest.java Tue Dec  7 15:01:37 2010
@@ -100,7 +100,7 @@ import org.junit.Test;
 public class MultiStartDifferentiableMultivariateVectorialOptimizerTest {
 
     @Test
-    public void testTrivial() throws MathUserException {
+    public void testTrivial() {
         LinearProblem problem =
             new LinearProblem(new double[][] { { 2 } }, new double[] { 3 });
         DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
@@ -112,7 +112,6 @@ public class MultiStartDifferentiableMul
         MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
             new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
                                                                        10, generator);
-        optimizer.setMaxEvaluations(100);
         optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
 
         // no optima before first optimization attempt
@@ -123,7 +122,7 @@ public class MultiStartDifferentiableMul
             // expected
         }
         VectorialPointValuePair optimum =
-            optimizer.optimize(problem, problem.target, new double[] { 1 }, new double[] { 0 });
+            optimizer.optimize(100, problem, problem.target, new double[] { 1 }, new double[] { 0 });
         assertEquals(1.5, optimum.getPoint()[0], 1.0e-10);
         assertEquals(3.0, optimum.getValue()[0], 1.0e-10);
         VectorialPointValuePair[] optima = optimizer.getOptima();
@@ -138,7 +137,7 @@ public class MultiStartDifferentiableMul
     }
 
     @Test(expected = MathUserException.class)
-    public void testNoOptimum() throws MathUserException {
+    public void testNoOptimum() {
         DifferentiableMultivariateVectorialOptimizer underlyingOptimizer =
             new GaussNewtonOptimizer(true);
         JDKRandomGenerator g = new JDKRandomGenerator();
@@ -148,13 +147,12 @@ public class MultiStartDifferentiableMul
         MultiStartDifferentiableMultivariateVectorialOptimizer optimizer =
             new MultiStartDifferentiableMultivariateVectorialOptimizer(underlyingOptimizer,
                                                                        10, generator);
-        optimizer.setMaxEvaluations(100);
         optimizer.setConvergenceChecker(new SimpleVectorialValueChecker(1.0e-6, 1.0e-6));
-        optimizer.optimize(new DifferentiableMultivariateVectorialFunction() {
+        optimizer.optimize(100, new DifferentiableMultivariateVectorialFunction() {
                 public MultivariateMatrixFunction jacobian() {
                     return null;
                 }
-                public double[] value(double[] point) throws MathUserException {
+                public double[] value(double[] point) {
                     throw new MathUserException();
                 }
             }, new double[] { 2 }, new double[] { 1 }, new double[] { 0 });

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/MultiStartMultivariateRealOptimizerTest.java Tue Dec  7 15:01:37 2010
@@ -46,9 +46,8 @@ public class MultiStartMultivariateRealO
         MultiStartMultivariateRealOptimizer optimizer =
             new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
         optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
-        optimizer.setMaxEvaluations(1100);
         RealPointValuePair optimum =
-            optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
+            optimizer.optimize(1100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
 
         assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
         assertTrue(optimizer.getEvaluations() > 900);

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/PowellOptimizerTest.java Tue Dec  7 15:01:37 2010
@@ -132,9 +132,8 @@ public class PowellOptimizerTest {
                         double fTol,
                         double pointTol) {
         final MultivariateRealOptimizer optim = new PowellOptimizer(fTol, Math.ulp(1d));
-        optim.setMaxEvaluations(1000);
 
-        final RealPointValuePair result = optim.optimize(func, goal, init);
+        final RealPointValuePair result = optim.optimize(1000, func, goal, init);
         final double[] found = result.getPoint();
 
         for (int i = 0, dim = optimum.length; i < dim; i++) {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerMultiDirectionalTest.java Tue Dec  7 15:01:37 2010
@@ -18,7 +18,6 @@
 package org.apache.commons.math.optimization.direct;
 
 import org.apache.commons.math.analysis.MultivariateRealFunction;
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.optimization.GoalType;
 import org.apache.commons.math.optimization.RealPointValuePair;
 import org.apache.commons.math.optimization.SimpleScalarValueChecker;
@@ -28,7 +27,7 @@ import org.junit.Test;
 
 public class SimplexOptimizerMultiDirectionalTest {
     @Test
-    public void testMinimizeMaximize() throws MathUserException {
+    public void testMinimizeMaximize() {
         // the following function has 4 local extrema:
         final double xM        = -3.841947088256863675365;
         final double yM        = -1.391745200270734924416;
@@ -40,7 +39,7 @@ public class SimplexOptimizerMultiDirect
         final double valueXpYp = -valueXpYm;                // global maximum
         MultivariateRealFunction fourExtrema = new MultivariateRealFunction() {
                 private static final long serialVersionUID = -7039124064449091152L;
-                public double value(double[] variables) throws MathUserException {
+                public double value(double[] variables) {
                     final double x = variables[0];
                     final double y = variables[1];
                     return ((x == 0) || (y == 0)) ? 0 :
@@ -49,19 +48,18 @@ public class SimplexOptimizerMultiDirect
             };
 
         SimplexOptimizer optimizer = new SimplexOptimizer(1e-11, 1e-30);
-        optimizer.setMaxEvaluations(200);
         optimizer.setSimplex(new MultiDirectionalSimplex(new double[] { 0.2, 0.2 }));
         RealPointValuePair optimum;
 
         // minimization
-        optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { -3, 0 });
+        optimum = optimizer.optimize(200, fourExtrema, GoalType.MINIMIZE, new double[] { -3, 0 });
         Assert.assertEquals(xM,        optimum.getPoint()[0], 4e-6);
         Assert.assertEquals(yP,        optimum.getPoint()[1], 3e-6);
         Assert.assertEquals(valueXmYp, optimum.getValue(),    8e-13);
         Assert.assertTrue(optimizer.getEvaluations() > 120);
         Assert.assertTrue(optimizer.getEvaluations() < 150);
 
-        optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { 1, 0 });
+        optimum = optimizer.optimize(200, fourExtrema, GoalType.MINIMIZE, new double[] { 1, 0 });
         Assert.assertEquals(xP,        optimum.getPoint()[0], 2e-8);
         Assert.assertEquals(yM,        optimum.getPoint()[1], 3e-6);
         Assert.assertEquals(valueXpYm, optimum.getValue(),    2e-12);
@@ -69,7 +67,7 @@ public class SimplexOptimizerMultiDirect
         Assert.assertTrue(optimizer.getEvaluations() < 150);
 
         // maximization
-        optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { -3.0, 0.0 });
+        optimum = optimizer.optimize(200, fourExtrema, GoalType.MAXIMIZE, new double[] { -3.0, 0.0 });
         Assert.assertEquals(xM,        optimum.getPoint()[0], 7e-7);
         Assert.assertEquals(yM,        optimum.getPoint()[1], 3e-7);
         Assert.assertEquals(valueXmYm, optimum.getValue(),    2e-14);
@@ -77,7 +75,7 @@ public class SimplexOptimizerMultiDirect
         Assert.assertTrue(optimizer.getEvaluations() < 150);
 
         optimizer.setConvergenceChecker(new SimpleScalarValueChecker(1e-15, 1e-30));
-        optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
+        optimum = optimizer.optimize(200, fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
         Assert.assertEquals(xP,        optimum.getPoint()[0], 2e-8);
         Assert.assertEquals(yP,        optimum.getPoint()[1], 3e-6);
         Assert.assertEquals(valueXpYp, optimum.getValue(),    2e-12);
@@ -86,11 +84,11 @@ public class SimplexOptimizerMultiDirect
     }
 
     @Test
-    public void testRosenbrock() throws MathUserException {
+    public void testRosenbrock() {
         MultivariateRealFunction rosenbrock =
             new MultivariateRealFunction() {
                 private static final long serialVersionUID = -9044950469615237490L;
-                public double value(double[] x) throws MathUserException {
+                public double value(double[] x) {
                     ++count;
                     double a = x[1] - x[0] * x[0];
                     double b = 1.0 - x[0];
@@ -100,12 +98,11 @@ public class SimplexOptimizerMultiDirect
 
         count = 0;
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
-        optimizer.setMaxEvaluations(100);
         optimizer.setSimplex(new MultiDirectionalSimplex(new double[][] {
                     { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
                 }));
         RealPointValuePair optimum =
-            optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
+            optimizer.optimize(100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
 
         Assert.assertEquals(count, optimizer.getEvaluations());
         Assert.assertTrue(optimizer.getEvaluations() > 50);
@@ -114,11 +111,11 @@ public class SimplexOptimizerMultiDirect
     }
 
     @Test
-    public void testPowell() throws MathUserException {
+    public void testPowell() {
         MultivariateRealFunction powell =
             new MultivariateRealFunction() {
                 private static final long serialVersionUID = -832162886102041840L;
-                public double value(double[] x) throws MathUserException {
+                public double value(double[] x) {
                     ++count;
                     double a = x[0] + 10 * x[1];
                     double b = x[2] - x[3];
@@ -130,10 +127,9 @@ public class SimplexOptimizerMultiDirect
 
         count = 0;
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
-        optimizer.setMaxEvaluations(1000);
         optimizer.setSimplex(new MultiDirectionalSimplex(4));
         RealPointValuePair optimum =
-            optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
+            optimizer.optimize(1000, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
         Assert.assertEquals(count, optimizer.getEvaluations());
         Assert.assertTrue(optimizer.getEvaluations() > 800);
         Assert.assertTrue(optimizer.getEvaluations() < 900);
@@ -141,14 +137,13 @@ public class SimplexOptimizerMultiDirect
     }
 
     @Test
-    public void testMath283() throws MathUserException {
+    public void testMath283() {
         // fails because MultiDirectional.iterateSimplex is looping forever
         // the while(true) should be replaced with a convergence check
         SimplexOptimizer optimizer = new SimplexOptimizer();
-        optimizer.setMaxEvaluations(1000);
         optimizer.setSimplex(new MultiDirectionalSimplex(2));
         final Gaussian2D function = new Gaussian2D(0, 0, 1);
-        RealPointValuePair estimate = optimizer.optimize(function,
+        RealPointValuePair estimate = optimizer.optimize(1000, function,
                                                          GoalType.MAXIMIZE, function.getMaximumPosition());
         final double EPSILON = 1e-5;
         final double expectedMaximum = function.getMaximum();

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java?rev=1043078&r1=1043077&r2=1043078&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/optimization/direct/SimplexOptimizerNelderMeadTest.java Tue Dec  7 15:01:37 2010
@@ -20,7 +20,6 @@ package org.apache.commons.math.optimiza
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-import org.apache.commons.math.exception.MathUserException;
 import org.apache.commons.math.exception.TooManyEvaluationsException;
 import org.apache.commons.math.analysis.MultivariateRealFunction;
 import org.apache.commons.math.analysis.MultivariateVectorialFunction;
@@ -33,8 +32,7 @@ import org.junit.Test;
 
 public class SimplexOptimizerNelderMeadTest {
     @Test
-    public void testMinimizeMaximize()
-        throws MathUserException {
+    public void testMinimizeMaximize() {
 
         // the following function has 4 local extrema:
         final double xM        = -3.841947088256863675365;
@@ -56,19 +54,18 @@ public class SimplexOptimizerNelderMeadT
             };
 
         SimplexOptimizer optimizer = new SimplexOptimizer(1e-10, 1e-30);
-        optimizer.setMaxEvaluations(100);
         optimizer.setSimplex(new NelderMeadSimplex(new double[] { 0.2, 0.2 }));
         RealPointValuePair optimum;
 
         // minimization
-        optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { -3, 0 });
+        optimum = optimizer.optimize(100, fourExtrema, GoalType.MINIMIZE, new double[] { -3, 0 });
         assertEquals(xM,        optimum.getPoint()[0], 2e-7);
         assertEquals(yP,        optimum.getPoint()[1], 2e-5);
         assertEquals(valueXmYp, optimum.getValue(),    6e-12);
         assertTrue(optimizer.getEvaluations() > 60);
         assertTrue(optimizer.getEvaluations() < 90);
 
-        optimum = optimizer.optimize(fourExtrema, GoalType.MINIMIZE, new double[] { 1, 0 });
+        optimum = optimizer.optimize(100, fourExtrema, GoalType.MINIMIZE, new double[] { 1, 0 });
         assertEquals(xP,        optimum.getPoint()[0], 5e-6);
         assertEquals(yM,        optimum.getPoint()[1], 6e-6);
         assertEquals(valueXpYm, optimum.getValue(),    1e-11);
@@ -76,14 +73,14 @@ public class SimplexOptimizerNelderMeadT
         assertTrue(optimizer.getEvaluations() < 90);
 
         // maximization
-        optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { -3, 0 });
+        optimum = optimizer.optimize(100, fourExtrema, GoalType.MAXIMIZE, new double[] { -3, 0 });
         assertEquals(xM,        optimum.getPoint()[0], 1e-5);
         assertEquals(yM,        optimum.getPoint()[1], 3e-6);
         assertEquals(valueXmYm, optimum.getValue(),    3e-12);
         assertTrue(optimizer.getEvaluations() > 60);
         assertTrue(optimizer.getEvaluations() < 90);
 
-        optimum = optimizer.optimize(fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
+        optimum = optimizer.optimize(100, fourExtrema, GoalType.MAXIMIZE, new double[] { 1, 0 });
         assertEquals(xP,        optimum.getPoint()[0], 4e-6);
         assertEquals(yP,        optimum.getPoint()[1], 5e-6);
         assertEquals(valueXpYp, optimum.getValue(),    7e-12);
@@ -92,17 +89,15 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test
-    public void testRosenbrock()
-        throws MathUserException {
+    public void testRosenbrock() {
 
         Rosenbrock rosenbrock = new Rosenbrock();
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
-        optimizer.setMaxEvaluations(100);
         optimizer.setSimplex(new NelderMeadSimplex(new double[][] {
                     { -1.2,  1 }, { 0.9, 1.2 } , {  3.5, -2.3 }
                 }));
         RealPointValuePair optimum =
-            optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
+            optimizer.optimize(100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
 
         assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
         assertTrue(optimizer.getEvaluations() > 40);
@@ -111,15 +106,13 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test
-    public void testPowell()
-        throws MathUserException {
+    public void testPowell() {
 
         Powell powell = new Powell();
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
-        optimizer.setMaxEvaluations(200);
         optimizer.setSimplex(new NelderMeadSimplex(4));
         RealPointValuePair optimum =
-            optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
+            optimizer.optimize(200, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
         assertEquals(powell.getCount(), optimizer.getEvaluations());
         assertTrue(optimizer.getEvaluations() > 110);
         assertTrue(optimizer.getEvaluations() < 130);
@@ -127,8 +120,7 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test
-    public void testLeastSquares1()
-        throws MathUserException {
+    public void testLeastSquares1() {
 
         final RealMatrix factors =
             new Array2DRowRealMatrix(new double[][] {
@@ -141,10 +133,9 @@ public class SimplexOptimizerNelderMeadT
                 }
             }, new double[] { 2.0, -3.0 });
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
-        optimizer.setMaxEvaluations(200);
         optimizer.setSimplex(new NelderMeadSimplex(2));
         RealPointValuePair optimum =
-            optimizer.optimize(ls, GoalType.MINIMIZE, new double[] { 10, 10 });
+            optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
         assertEquals( 2, optimum.getPointRef()[0], 3e-5);
         assertEquals(-3, optimum.getPointRef()[1], 4e-4);
         assertTrue(optimizer.getEvaluations() > 60);
@@ -153,8 +144,7 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test
-    public void testLeastSquares2()
-        throws MathUserException {
+    public void testLeastSquares2() {
 
         final RealMatrix factors =
             new Array2DRowRealMatrix(new double[][] {
@@ -167,10 +157,9 @@ public class SimplexOptimizerNelderMeadT
                 }
             }, new double[] { 2, -3 }, new double[] { 10, 0.1 });
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
-        optimizer.setMaxEvaluations(200);
         optimizer.setSimplex(new NelderMeadSimplex(2));
         RealPointValuePair optimum =
-            optimizer.optimize(ls, GoalType.MINIMIZE, new double[] { 10, 10 });
+            optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
         assertEquals( 2, optimum.getPointRef()[0], 5e-5);
         assertEquals(-3, optimum.getPointRef()[1], 8e-4);
         assertTrue(optimizer.getEvaluations() > 60);
@@ -179,8 +168,7 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test
-    public void testLeastSquares3()
-        throws MathUserException {
+    public void testLeastSquares3() {
 
         final RealMatrix factors =
             new Array2DRowRealMatrix(new double[][] {
@@ -195,10 +183,9 @@ public class SimplexOptimizerNelderMeadT
                     { 1, 1.2 }, { 1.2, 2 }
                 }));
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
-        optimizer.setMaxEvaluations(200);
         optimizer.setSimplex(new NelderMeadSimplex(2));
         RealPointValuePair optimum =
-            optimizer.optimize(ls, GoalType.MINIMIZE, new double[] { 10, 10 });
+            optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
         assertEquals( 2, optimum.getPointRef()[0], 2e-3);
         assertEquals(-3, optimum.getPointRef()[1], 8e-4);
         assertTrue(optimizer.getEvaluations() > 60);
@@ -207,12 +194,11 @@ public class SimplexOptimizerNelderMeadT
     }
 
     @Test(expected = TooManyEvaluationsException.class)
-    public void testMaxIterations() throws MathUserException {
+    public void testMaxIterations() {
         Powell powell = new Powell();
         SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
-        optimizer.setMaxEvaluations(20);
         optimizer.setSimplex(new NelderMeadSimplex(4));
-        optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
+        optimizer.optimize(20, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
     }
 
     private static class Rosenbrock implements MultivariateRealFunction {
@@ -222,7 +208,7 @@ public class SimplexOptimizerNelderMeadT
             count = 0;
         }
 
-        public double value(double[] x) throws MathUserException {
+        public double value(double[] x) {
             ++count;
             double a = x[1] - x[0] * x[0];
             double b = 1.0 - x[0];



Mime
View raw message