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/02/26 20:17:41 UTC

svn commit: r748274 [1/3] - in /commons/proper/math/trunk: ./ src/java/org/apache/commons/math/analysis/ src/java/org/apache/commons/math/analysis/minimization/ src/java/org/apache/commons/math/estimation/ src/java/org/apache/commons/math/optimization/...

Author: luc
Date: Thu Feb 26 19:17:39 2009
New Revision: 748274

URL: http://svn.apache.org/viewvc?rev=748274&view=rev
Log:
started refactoring of optimization framework:
 - created subpackages optimization.direct, optimization.general,
   optimization.linear (currently empty) and optimization.univariate
 - removed packages analysis.minimization and estimation
 - renamed all Cost-related interfaces/classes into Objective
   (this allows both minimization and maximization)
 - added a few new general interfaces

This work is not complete yet. The direct and general packages classes
are very close to the former design, they have almost not been changed
structurally.

Added:
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java   (with props)
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java   (with props)
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java   (with props)
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostException.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostFunction.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java   (with props)
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/MultiDirectional.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/NelderMead.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/package.html   (with props)
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/AbstractEstimator.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/AbstractEstimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/EstimatedParameter.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/EstimationProblem.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/Estimator.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/GaussNewtonEstimator.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/LevenbergMarquardtEstimator.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/SimpleEstimationProblem.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/SimpleEstimationProblem.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/WeightedMeasurement.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/general/package.html   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/linear/
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/BrentMinimizer.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/minimization/BrentMinimizer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizer.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/UnivariateRealMinimizerImpl.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/minimization/UnivariateRealMinimizerImpl.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/univariate/package.html   (props changed)
      - copied unchanged from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/minimization/package.html
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/direct/
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/direct/MultiDirectionalTest.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/direct/NelderMeadTest.java   (contents, props changed)
      - copied, changed from r746578, commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/EstimatedParameterTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/GaussNewtonEstimatorTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/LevenbergMarquardtEstimatorTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/MinpackTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/general/WeightedMeasurementTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/linear/
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/univariate/BrentMinimizerTest.java   (contents, props changed)
      - copied, changed from r746504, commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/minimization/BrentMinimizerTest.java
Removed:
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/minimization/
    commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostException.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostFunction.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/NelderMead.java
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/minimization/
    commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/MultiDirectionalTest.java
    commons/proper/math/trunk/src/test/org/apache/commons/math/optimization/NelderMeadTest.java
Modified:
    commons/proper/math/trunk/findbugs-exclude-filter.xml
    commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/package.html
    commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/package.html
    commons/proper/math/trunk/src/site/resources/userguide/TrajectoryDeterminationProblem.java
    commons/proper/math/trunk/src/site/xdoc/userguide/analysis.xml
    commons/proper/math/trunk/src/site/xdoc/userguide/index.xml
    commons/proper/math/trunk/src/site/xdoc/userguide/optimization.xml
    commons/proper/math/trunk/src/site/xdoc/userguide/overview.xml

Modified: commons/proper/math/trunk/findbugs-exclude-filter.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/findbugs-exclude-filter.xml?rev=748274&r1=748273&r2=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/findbugs-exclude-filter.xml (original)
+++ commons/proper/math/trunk/findbugs-exclude-filter.xml Thu Feb 26 19:17:39 2009
@@ -26,7 +26,7 @@
   <!--  the following equality tests are part of the reference algorithms -->
   <!--  which already know about limited precision of the double numbers -->
   <Match>
-    <Class name="org.apache.commons.math.analysis.minimization.BrentMinimizer" />
+    <Class name="org.apache.commons.math.optimization.univariate.BrentMinimizer" />
     <Method name="localMin" params="double,double,double,double,org.apache.commons.math.analysis.UnivariateRealFunction" returns="double" />
     <Bug pattern="FE_FLOATING_POINT_EQUALITY" />
   </Match>

Modified: commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/package.html
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/package.html?rev=748274&r1=748273&r2=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/package.html (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/package.html Thu Feb 26 19:17:39 2009
@@ -17,7 +17,7 @@
   -->
     <!-- $Revision$ $Date$ -->
     <body>
-     Parent package for common numerical analysis procedures, including root finding, minimization,
+     Parent package for common numerical analysis procedures, including root finding,
      function interpolation and integration.
     </body>
 </html>
\ No newline at end of file

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java (from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java&r1=746504&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java Thu Feb 26 19:17:39 2009
@@ -17,6 +17,9 @@
 
 package org.apache.commons.math.optimization;
 
+import org.apache.commons.math.optimization.direct.DirectSearchOptimizer;
+
+
 /** This interface specifies how to check if a {@link
  * DirectSearchOptimizer direct search method} has converged.
  *
@@ -32,10 +35,16 @@
 public interface ConvergenceChecker {
 
   /** Check if the optimization algorithm has converged on the simplex.
-   * @param simplex ordered simplex (all points in the simplex have
-   * been eavluated and are sorted from lowest to largest cost)
+   * <p>
+   * When this method is called, all points in the simplex have been evaluated
+   * and are sorted from lowest to largest value. The values are either the
+   * original objective function values if the optimizer was configured for
+   * minimization, or the opposites of the original objective function values
+   * if the optimizer was configured for maximization.
+   * </p>
+   * @param simplex ordered simplex
    * @return true if the algorithm is considered to have converged
    */
-  public boolean converged (PointCostPair[] simplex);
+  boolean converged(PointValuePair[] simplex);
 
 }

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ConvergenceChecker.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java?rev=748274&view=auto
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java (added)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java Thu Feb 26 19:17:39 2009
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.optimization;
+
+import java.io.Serializable;
+
+/** 
+ * Goal type for an optimization problem.
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public enum GoalType implements Serializable {
+
+    /** Maximization goal. */
+    MAXIMIZE,
+
+    /** Minimization goal. */
+    MINIMIZE
+
+}

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/GoalType.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java?rev=748274&view=auto
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java (added)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java Thu Feb 26 19:17:39 2009
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.optimization;
+
+import org.apache.commons.math.linear.RealMatrix;
+
+/** This class converts {@link MultiObjectiveFunction vectorial
+ * objective functions} to {@link ObjectiveFunction scalar objective functions}
+ * when the goal is to minimize them.
+ * <p>
+ * This class is mostly used when the vectorial objective function represents
+ * residuals, i.e. differences between a theoretical result computed from a
+ * variables set applied to a model and a reference. Residuals are intended to be
+ * minimized in order to get the variables set that best fit the model to the
+ * reference. The reference may be obtained for example from physical measurements
+ * whether the model is built from theoretical considerations.
+ * </p>
+ * <p>
+ * This class computes a possibly weighted squared sum of the residuals, which is
+ * a scalar value. It implements the {@link ObjectiveFunction} interface and can
+ * therefore be minimized by any optimizer supporting scalar objectives functions.
+ * This correspond to a least square estimation.
+ * </p>
+ * <p>
+ * This class support combination of residuals with or without weights and correlations.
+ * </p>
+  *
+ * @see ObjectiveFunction
+ * @see MultiObjectiveFunction
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+
+public class LeastSquaresConverter implements ObjectiveFunction {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -5174886571116126798L;
+
+    /** Underlying vectorial function. */
+    private final MultiObjectiveFunction function;
+
+    /** Optional weights for the residuals. */
+    private final double[] weights;
+
+    /** Optional scaling matrix (weight and correlations) for the residuals. */
+    private final RealMatrix scale;
+
+    /** Build a simple converter for uncorrelated residuals with the same weight.
+     * @param function vectorial residuals function to wrap
+     */
+    public LeastSquaresConverter (final MultiObjectiveFunction function) {
+        this.function = function;
+        this.weights  = null;
+        this.scale    = null;
+    }
+
+    /** Build a simple converter for uncorrelated residuals with the specific weights.
+     * <p>
+     * The scalar objective function value is computed as:
+     * <pre>
+     * objective = &sum;(weight<sub>i</sub>residual<sub>i</sub>)<sup>2</sup>
+     * </pre>
+     * </p>
+     * <p>
+     * Weights can be used for example to combine residuals with different standard
+     * deviations. As an example, consider a 2000 elements residuals array in which
+     * even elements are angular measurements in degrees with a 0.01&deg; standard
+     * deviation and off elements are distance measurements in meters with a 15m
+     * standard deviation. In this case, the weights array should be initialized with
+     * value 1.0/0.01 in the even elements and 1.0/15.0 in the odd elements. 
+     * </p>
+     * <p>
+     * The residuals array computed by the function and the weights array must
+     * have consistent sizes or a {@link ObjectiveException} will be triggered while
+     * computing the scalar objective.
+     * </p>
+     * @param function vectorial residuals function to wrap
+     * @param weights weights to apply to the residuals
+     */
+    public LeastSquaresConverter (final MultiObjectiveFunction function,
+                                  final double[] weights) {
+        this.function = function;
+        this.weights  = weights.clone();
+        this.scale    = null;
+    }
+
+    /** Build a simple convertor for correlated residuals with the specific weights.
+     * <p>
+     * The scalar objective function value is computed as:
+     * <pre>
+     * objective = &sum;(y<sub>i</sub>)<sup>2</sup> with y = scale&times;residual
+     * </pre>
+     * </p>
+     * <p>
+     * The residuals array computed by the function and the scaling matrix must
+     * have consistent sizes or a {@link ObjectiveException} will be triggered while
+     * computing the scalar objective.
+     * </p>
+     * @param function vectorial residuals function to wrap
+     * @param scale scaling matrix (
+     */
+    public LeastSquaresConverter (final MultiObjectiveFunction function,
+                                  final RealMatrix scale) {
+        this.function = function;
+        this.weights  = null;
+        this.scale    = scale.copy();
+    }
+
+    /** {@inheritDoc} */
+    public double objective(final double[] variables) throws ObjectiveException {
+
+        final double[] residuals = function.objective(variables);
+        double sumSquares = 0;
+
+        if (weights != null) {
+            if (weights.length != residuals.length) {
+                throw new ObjectiveException("dimension mismatch {0} != {1}",
+                                        weights.length, residuals.length);
+            }
+            for (int i = 0; i < weights.length; ++i) {
+                final double ai = residuals[i] * weights[i];
+                sumSquares += ai * ai;
+            }
+        } else if (scale != null) {
+            if (scale.getColumnDimension() != residuals.length) {
+                throw new ObjectiveException("dimension mismatch {0} != {1}",
+                                        scale.getColumnDimension(), residuals.length);
+            }
+            for (final double yi : scale.operate(residuals)) {
+                sumSquares += yi * yi;
+            }
+        } else {
+            for (final double ri : residuals) {
+                sumSquares += ri * ri;
+            }
+        }
+
+        return sumSquares;
+
+    }
+
+}

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/LeastSquaresConverter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java?rev=748274&view=auto
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java (added)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java Thu Feb 26 19:17:39 2009
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.optimization;
+
+import java.io.Serializable;
+
+/** 
+ * This interface represents a vectorial objective function to be either minimized or maximized.
+ * @see LeastSquaresConverter
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public interface MultiObjectiveFunction extends Serializable {
+
+    /** 
+     * Compute the function value for the given variables set.
+     * @param variables variables set
+     * @return function value for the given variables set
+     * @exception ObjectiveException if no cost can be computed for the parameters
+     */
+    double[] objective(double[] variables) throws ObjectiveException;
+
+}

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiObjectiveFunction.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java (from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostException.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostException.java&r1=746578&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostException.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java Thu Feb 26 19:17:39 2009
@@ -20,37 +20,37 @@
 import org.apache.commons.math.MathException;
 
 /** 
- * This class represents exceptions thrown by cost functions.
+ * This class represents exceptions thrown by obective functions.
  *
  * @version $Revision$ $Date$
  * @since 1.2
  */
 
-public class CostException
+public class ObjectiveException
   extends MathException {
 
     /** Serializable version identifier. */
-    private static final long serialVersionUID = 467695563268795689L;
+    private static final long serialVersionUID = 8738657724051397417L;
 
     /**
-     * Constructs a new <code>MathException</code> with specified
+     * Constructs a new <code>ObjectiveException</code> with specified
      * formatted detail message.
      * Message formatting is delegated to {@link java.text.MessageFormat}.
      * @param pattern format specifier
      * @param arguments format arguments
      */
-    public CostException(String pattern, Object ... arguments) {
+    public ObjectiveException(String pattern, Object ... arguments) {
       super(pattern, arguments);
     }
 
     /**
-     * Constructs a new <code>MathException</code> with specified
+     * Constructs a new <code>ObjectiveException</code> with specified
      * nested <code>Throwable</code> root cause.
      *
      * @param rootCause  the exception or error that caused this exception
      *                   to be thrown.
      */
-    public CostException(Throwable rootCause) {
+    public ObjectiveException(Throwable rootCause) {
         super(rootCause);
     }
     

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveException.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java (from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostFunction.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostFunction.java&r1=746504&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/CostFunction.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java Thu Feb 26 19:17:39 2009
@@ -17,21 +17,21 @@
 
 package org.apache.commons.math.optimization;
 
+import java.io.Serializable;
+
 /** 
- * This interface represents a cost function to be minimized.
+ * This interface represents a scalar objective function to be either minimized or maximized.
  * @version $Revision$ $Date$
  * @since 1.2
  */
-public interface CostFunction {
-
+public interface ObjectiveFunction extends Serializable {
 
-  /** 
-   * Compute the cost associated to the given parameters array.
-   * @param x parameters array
-   * @return cost associated to the parameters array
-   * @exception CostException if no cost can be computed for the parameters
-   * @see PointCostPair
-   */
-  public double cost(double[] x) throws CostException;
+    /** 
+     * Compute the function value for the given variables set.
+     * @param variables variables set
+     * @return function value for the given variables set
+     * @exception ObjectiveException if no value can be computed for the parameters
+     */
+    double objective(double[] variables) throws ObjectiveException;
 
 }

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/ObjectiveFunction.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java (from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java&r1=746578&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java Thu Feb 26 19:17:39 2009
@@ -15,9 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.commons.math.estimation;
+package org.apache.commons.math.optimization;
 
-import org.apache.commons.math.MathException;
+import org.apache.commons.math.ConvergenceException;
 
 /** 
  * This class represents exceptions thrown by the estimation solvers.
@@ -27,11 +27,10 @@
  *
  */
 
-public class EstimationException
-extends MathException {
+public class OptimizationException extends ConvergenceException {
 
     /** Serializable version identifier. */
-    private static final long serialVersionUID = -573038581493881337L;
+    private static final long serialVersionUID = -781139167958631145L;
 
     /** 
      * Simple constructor.
@@ -39,7 +38,7 @@
      * @param specifier format specifier (to be translated)
      * @param parts to insert in the format (no translation)
      */
-    public EstimationException(String specifier, Object ... parts) {
+    public OptimizationException(String specifier, Object ... parts) {
         super(specifier, parts);
     }
 

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/OptimizationException.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Added: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java?rev=748274&view=auto
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java (added)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java Thu Feb 26 19:17:39 2009
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math.optimization;
+
+import java.io.Serializable;
+
+/** 
+ * This interface represents an optimization algorithm.
+ * @version $Revision$ $Date$
+ * @since 2.0
+ */
+public interface Optimizer extends Serializable {
+
+    /** Set the maximal number of objective function calls.
+     * @param maxEvaluations maximal number of function calls for each
+     * start (note that the number may be checked <em>after</em>
+     * a few related calls have been made, this means that in some
+     * cases this number will be exceeded by a few units, depending on
+     * the dimension of the problem and kind of optimizer).
+     */
+    void setMaxEvaluations(int maxEvaluations);
+
+    /** Set the convergence checker.
+     * @param checker object to use to check for convergence
+     */
+    void setConvergenceChecker(ConvergenceChecker checker);
+
+    /** Optimizes an objective function.
+     * @param f objective function
+     * @param goalType type of optimization goal: either {@link GoalType#MAXIMIZE}
+     * or {@link GoalType#MINIMIZE}
+     * @return the point/value pair giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
+     * the search
+     * @exception OptimizationException if the algorithm failed to converge
+     */
+    PointValuePair optimize(final ObjectiveFunction f, final GoalType goalType)
+        throws ObjectiveException, OptimizationException;
+
+}

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/Optimizer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java (from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java&r1=746504&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointCostPair.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java Thu Feb 26 19:17:39 2009
@@ -17,43 +17,49 @@
 
 package org.apache.commons.math.optimization;
 
+import java.io.Serializable;
+
+
 /** 
- * This class holds a point and its associated cost.
+ * This class holds a point and the value of an objective function at this point.
  * <p>This is a simple immutable container.</p>
  * @version $Revision$ $Date$
- * @see CostFunction
- * @since 1.2
+ * @see ObjectiveFunction
+ * @since 2.0
  */
-public class PointCostPair {
+public class PointValuePair implements Serializable {
 
-  /** Build a point/cost pair.
-   * @param point point coordinates (the built instance will store
-   * a copy of the array, not the array passed as argument)
-   * @param cost point cost
-   */
-  public PointCostPair(double[] point, double cost) {
-    this.point = (double[]) point.clone();
-    this.cost = cost;
-  }
-
-  /** Get the point.
-   * @return a copy of the stored point
-   */
-  public double[] getPoint() {
-      return (double[]) point.clone();
-  }
-
-  /** Get the cost.
-   * @return the stored cost
-   */
-  public double getCost() {
-      return cost;
-  }
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = 2254035971797977063L;
 
-  /** Point coordinates. */
-  private final double[] point;
+    /** Point coordinates. */
+    private final double[] point;
 
-  /** Cost associated to the point. */
-  private final double cost;
+    /** Value of the objective function at the point. */
+    private final double value;
+
+    /** Build a point/objective function value pair.
+     * @param point point coordinates (the built instance will store
+     * a copy of the array, not the array passed as argument)
+     * @param value value of an objective function at the point
+     */
+    public PointValuePair(final double[] point, final double value) {
+        this.point = point.clone();
+        this.value  = value;
+    }
+
+    /** Get the point.
+     * @return a copy of the stored point
+     */
+    public double[] getPoint() {
+        return point.clone();
+    }
+
+    /** Get the value of the objective function.
+     * @return the stored value of the objective function
+     */
+    public double getValue() {
+        return value;
+    }
 
 }

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/PointValuePair.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java (from r746578, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java&r1=746578&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/DirectSearchOptimizer.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java Thu Feb 26 19:17:39 2009
@@ -15,8 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.commons.math.optimization;
+package org.apache.commons.math.optimization.direct;
 
+import java.io.Serializable;
 import java.util.Arrays;
 import java.util.Comparator;
 
@@ -25,6 +26,10 @@
 import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.linear.RealMatrix;
 import org.apache.commons.math.linear.decomposition.NotPositiveDefiniteMatrixException;
+import org.apache.commons.math.optimization.ConvergenceChecker;
+import org.apache.commons.math.optimization.ObjectiveException;
+import org.apache.commons.math.optimization.ObjectiveFunction;
+import org.apache.commons.math.optimization.PointValuePair;
 import org.apache.commons.math.random.CorrelatedRandomVectorGenerator;
 import org.apache.commons.math.random.JDKRandomGenerator;
 import org.apache.commons.math.random.RandomGenerator;
@@ -38,7 +43,7 @@
  * This class implements simplex-based direct search optimization
  * algorithms.
  *
- * <p>Direct search methods only use cost function values, they don't
+ * <p>Direct search methods only use objective function values, they don't
  * need derivatives and don't either try to compute approximation of
  * the derivatives. According to a 1996 paper by Margaret H. Wright
  * (<a href="http://cm.bell-labs.com/cm/cs/doc/96/4-02.ps.gz">Direct
@@ -51,40 +56,80 @@
  * direct search methods can be useful.</p>
  *
  * <p>Simplex-based direct search methods are based on comparison of
- * the cost function values at the vertices of a simplex (which is a
+ * the objective function values at the vertices of a simplex (which is a
  * set of n+1 points in dimension n) that is updated by the algorithms
  * steps.</p>
  *
- * <p>Minimization can be attempted either in single-start or in
+ * <p>Optimization can be attempted either in single-start or in
  * multi-start mode. Multi-start is a traditional way to try to avoid
- * being trapped in a local minimum and miss the global minimum of a
+ * being trapped in a local optimum and miss the global optimum of a
  * function. It can also be used to verify the convergence of an
- * algorithm. The various multi-start-enabled <code>minimize</code>
- * methods return the best minimum found after all starts, and the
- * {@link #getMinima getMinima} method can be used to retrieve all
- * minima from all starts (including the one already provided by the
- * {@link #minimize(CostFunction, int, ConvergenceChecker, double[],
- * double[]) minimize} method).</p>
+ * algorithm. The various multi-start-enabled <code>optimize</code>
+ * methods return the best optimum found after all starts, and the
+ * {@link #getOptimum getOptimum} method can be used to retrieve all
+ * optima from all starts (including the one already provided by the
+ * {@link #optimize(ObjectiveFunction, int, ConvergenceChecker, double[],
+ * double[]) optimize} method).</p>
  *
  * <p>This class is the base class performing the boilerplate simplex
  * initialization and handling. The simplex update by itself is
  * performed by the derived classes according to the implemented
  * algorithms.</p>
  *
- * @see CostFunction
+ * @see ObjectiveFunction
  * @see NelderMead
  * @see MultiDirectional
  * @version $Revision$ $Date$
  * @since 1.2
  */
-public abstract class DirectSearchOptimizer {
+public abstract class DirectSearchOptimizer implements Serializable {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -3913013760494455466L;
+
+    /** Comparator for {@link PointValuePair} objects. */
+    private static final Comparator<PointValuePair> PAIR_COMPARATOR =
+        new Comparator<PointValuePair>() {
+            public int compare(PointValuePair o1, PointValuePair o2) {
+                if (o1 == null) {
+                    return (o2 == null) ? 0 : +1;
+                } else if (o2 == null) {
+                    return -1;
+                }
+                return (o1.getValue() < o2.getValue()) ? -1 : ((o1 == o2) ? 0 : +1);
+            }
+        };
+
+    /** Simplex. */
+    protected PointValuePair[] simplex;
+
+    /** Objective function. */
+    private ObjectiveFunction f;
+
+    /** Indicator for minimization. */
+    private boolean minimizing;
+
+    /** Number of evaluations already performed for the current start. */
+    private int evaluations;
+
+    /** Number of evaluations already performed for all starts. */
+    private int totalEvaluations;
+
+    /** Number of starts to go. */
+    private int starts;
+
+    /** Random generator for multi-start. */
+    private RandomVectorGenerator generator;
+
+    /** Found optima. */
+    private PointValuePair[] optima;
 
     /** Simple constructor.
      */
     protected DirectSearchOptimizer() {
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The initial simplex is built from two vertices that are
      * considered to represent two opposite vertices of a box parallel
      * to the canonical axes of the space. The simplex is the subset of
@@ -93,36 +138,37 @@
      * regular simplex using the projected separation between the given
      * points as the scaling factor along each coordinate axis.</p>
      * <p>The optimization is performed in single-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param vertexA first vertex
      * @param vertexB last vertex
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  double[] vertexA, double[] vertexB)
-    throws CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final double[] vertexA, final double[] vertexB)
+        throws ObjectiveException, ConvergenceException {
 
         // set up optimizer
         buildSimplex(vertexA, vertexB);
         setSingleStart();
 
-        // compute minimum
-        return minimize(f, maxEvaluations, checker);
+        // compute optimum
+        return optimize(f, maxEvaluations, checker, minimizing);
 
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The initial simplex is built from two vertices that are
      * considered to represent two opposite vertices of a box parallel
      * to the canonical axes of the space. The simplex is the subset of
@@ -131,30 +177,31 @@
      * regular simplex using the projected separation between the given
      * points as the scaling factor along each coordinate axis.</p>
      * <p>The optimization is performed in multi-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param vertexA first vertex
      * @param vertexB last vertex
      * @param starts number of starts to perform (including the
      * first one), multi-start is disabled if value is less than or
      * equal to 1
      * @param seed seed for the random vector generator
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the obective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  double[] vertexA, double[] vertexB,
-                                  int starts, long seed)
-    throws CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final double[] vertexA, final double[] vertexB,
+                                   final int starts, final long seed)
+        throws ObjectiveException, ConvergenceException {
 
         // set up the simplex traveling around the box
         buildSimplex(vertexA, vertexB);
@@ -162,111 +209,112 @@
         // we consider the simplex could have been produced by a generator
         // having its mean value at the center of the box, the standard
         // deviation along each axe being the corresponding half size
-        double[] mean              = new double[vertexA.length];
-        double[] standardDeviation = new double[vertexA.length];
+        final double[] mean              = new double[vertexA.length];
+        final double[] standardDeviation = new double[vertexA.length];
         for (int i = 0; i < vertexA.length; ++i) {
             mean[i]              = 0.5 * (vertexA[i] + vertexB[i]);
             standardDeviation[i] = 0.5 * Math.abs(vertexA[i] - vertexB[i]);
         }
 
-        RandomGenerator rg = new JDKRandomGenerator();
+        final RandomGenerator rg = new JDKRandomGenerator();
         rg.setSeed(seed);
-        UniformRandomGenerator urg = new UniformRandomGenerator(rg);
-        RandomVectorGenerator rvg =
+        final UniformRandomGenerator urg = new UniformRandomGenerator(rg);
+        final RandomVectorGenerator rvg =
             new UncorrelatedRandomVectorGenerator(mean, standardDeviation, urg);
         setMultiStart(starts, rvg);
 
-        // compute minimum
-        return minimize(f, maxEvaluations, checker);
+        // compute optimum
+        return optimize(f, maxEvaluations, checker, minimizing);
 
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The simplex is built from all its vertices.</p>
      * <p>The optimization is performed in single-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param vertices array containing all vertices of the simplex
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  double[][] vertices)
-    throws CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final double[][] vertices)
+        throws ObjectiveException, ConvergenceException {
 
         // set up optimizer
         buildSimplex(vertices);
         setSingleStart();
 
-        // compute minimum
-        return minimize(f, maxEvaluations, checker);
+        // compute optimum
+        return optimize(f, maxEvaluations, checker, minimizing);
 
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The simplex is built from all its vertices.</p>
      * <p>The optimization is performed in multi-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param vertices array containing all vertices of the simplex
      * @param starts number of starts to perform (including the
      * first one), multi-start is disabled if value is less than or
      * equal to 1
      * @param seed seed for the random vector generator
-     * @return the point/cost pairs giving the minimal cost
+     * @return the point/value pairs giving the optimal value for objective function
      * @exception NotPositiveDefiniteMatrixException if the vertices
      * array is degenerated
-     * @exception CostException if the cost function throws one during
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  double[][] vertices,
-                                  int starts, long seed)
-    throws NotPositiveDefiniteMatrixException,
-    CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final double[][] vertices,
+                                   final int starts, final long seed)
+        throws NotPositiveDefiniteMatrixException, ObjectiveException, ConvergenceException {
 
         try {
             // store the points into the simplex
             buildSimplex(vertices);
 
             // compute the statistical properties of the simplex points
-            VectorialMean meanStat = new VectorialMean(vertices[0].length);
-            VectorialCovariance covStat = new VectorialCovariance(vertices[0].length, true);
+            final VectorialMean meanStat = new VectorialMean(vertices[0].length);
+            final VectorialCovariance covStat = new VectorialCovariance(vertices[0].length, true);
             for (int i = 0; i < vertices.length; ++i) {
                 meanStat.increment(vertices[i]);
                 covStat.increment(vertices[i]);
             }
-            double[] mean = meanStat.getResult();
-            RealMatrix covariance = covStat.getResult();
+            final double[] mean = meanStat.getResult();
+            final RealMatrix covariance = covStat.getResult();
             
 
-            RandomGenerator rg = new JDKRandomGenerator();
+            final RandomGenerator rg = new JDKRandomGenerator();
             rg.setSeed(seed);
-            RandomVectorGenerator rvg =
+            final RandomVectorGenerator rvg =
                 new CorrelatedRandomVectorGenerator(mean,
                                                     covariance, 1.0e-12 * covariance.getNorm(),
                                                     new UniformRandomGenerator(rg));
             setMultiStart(starts, rvg);
 
-            // compute minimum
-            return minimize(f, maxEvaluations, checker);
+            // compute optimum
+            return optimize(f, maxEvaluations, checker, minimizing);
 
         } catch (DimensionMismatchException dme) {
             // this should not happen
@@ -275,69 +323,71 @@
 
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The simplex is built randomly.</p>
      * <p>The optimization is performed in single-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param generator random vector generator
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  RandomVectorGenerator generator)
-    throws CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final RandomVectorGenerator generator)
+        throws ObjectiveException, ConvergenceException {
 
         // set up optimizer
         buildSimplex(generator);
         setSingleStart();
 
-        // compute minimum
-        return minimize(f, maxEvaluations, checker);
+        // compute optimum
+        return optimize(f, maxEvaluations, checker, minimizing);
 
     }
 
-    /** Minimizes a cost function.
+    /** Optimizes an objective function.
      * <p>The simplex is built randomly.</p>
      * <p>The optimization is performed in multi-start mode.</p>
-     * @param f cost function
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
      * @param generator random vector generator
      * @param starts number of starts to perform (including the
      * first one), multi-start is disabled if value is less than or
      * equal to 1
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    public PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                  ConvergenceChecker checker,
-                                  RandomVectorGenerator generator,
-                                  int starts)
-    throws CostException, ConvergenceException {
+    public PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing,
+                                   final RandomVectorGenerator generator,
+                                   final int starts)
+        throws ObjectiveException, ConvergenceException {
 
         // set up optimizer
         buildSimplex(generator);
         setMultiStart(starts, generator);
 
-        // compute minimum
-        return minimize(f, maxEvaluations, checker);
+        // compute optimum
+        return optimize(f, maxEvaluations, checker, minimizing);
 
     }
 
@@ -352,21 +402,21 @@
      * @param vertexA first vertex
      * @param vertexB last vertex
      */
-    private void buildSimplex(double[] vertexA, double[] vertexB) {
+    private void buildSimplex(final double[] vertexA, final double[] vertexB) {
 
-        int n = vertexA.length;
-        simplex = new PointCostPair[n + 1];
+        final int n = vertexA.length;
+        simplex = new PointValuePair[n + 1];
 
         // set up the simplex traveling around the box
         for (int i = 0; i <= n; ++i) {
-            double[] vertex = new double[n];
+            final double[] vertex = new double[n];
             if (i > 0) {
                 System.arraycopy(vertexB, 0, vertex, 0, i);
             }
             if (i < n) {
                 System.arraycopy(vertexA, i, vertex, i, n - i);
             }
-            simplex[i] = new PointCostPair(vertex, Double.NaN);
+            simplex[i] = new PointValuePair(vertex, Double.NaN);
         }
 
     }
@@ -374,28 +424,28 @@
     /** Build a simplex from all its points.
      * @param vertices array containing all vertices of the simplex
      */
-    private void buildSimplex(double[][] vertices) {
-        int n = vertices.length - 1;
-        simplex = new PointCostPair[n + 1];
+    private void buildSimplex(final double[][] vertices) {
+        final int n = vertices.length - 1;
+        simplex = new PointValuePair[n + 1];
         for (int i = 0; i <= n; ++i) {
-            simplex[i] = new PointCostPair(vertices[i], Double.NaN);
+            simplex[i] = new PointValuePair(vertices[i], Double.NaN);
         }
     }
 
     /** Build a simplex randomly.
      * @param generator random vector generator
      */
-    private void buildSimplex(RandomVectorGenerator generator) {
+    private void buildSimplex(final RandomVectorGenerator generator) {
 
         // use first vector size to compute the number of points
-        double[] vertex = generator.nextVector();
-        int n = vertex.length;
-        simplex = new PointCostPair[n + 1];
-        simplex[0] = new PointCostPair(vertex, Double.NaN);
+        final double[] vertex = generator.nextVector();
+        final int n = vertex.length;
+        simplex = new PointValuePair[n + 1];
+        simplex[0] = new PointValuePair(vertex, Double.NaN);
 
         // fill up the vertex
         for (int i = 1; i <= n; ++i) {
-            simplex[i] = new PointCostPair(generator.nextVector(), Double.NaN);
+            simplex[i] = new PointValuePair(generator.nextVector(), Double.NaN);
         }
 
     }
@@ -405,7 +455,7 @@
     private void setSingleStart() {
         starts    = 1;
         generator = null;
-        minima    = null;
+        optima    = null;
     }
 
     /** Set up multi-start mode.
@@ -414,65 +464,69 @@
      * equal to 1
      * @param generator random vector generator to use for restarts
      */
-    private void setMultiStart(int starts, RandomVectorGenerator generator) {
+    private void setMultiStart(final int starts, final RandomVectorGenerator generator) {
         if (starts < 2) {
             this.starts    = 1;
             this.generator = null;
-            minima         = null;
+            optima         = null;
         } else {
             this.starts    = starts;
             this.generator = generator;
-            minima         = null;
+            optima         = null;
         }
     }
 
-    /** Get all the minima found during the last call to {@link
-     * #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
+    /** Get all the optima found during the last call to {@link
+     * #optimize(ObjectiveFunction, int, ConvergenceChecker, double[], double[])
      * minimize}.
-     * <p>The optimizer stores all the minima found during a set of
+     * <p>The optimizer stores all the optima found during a set of
      * restarts when multi-start mode is enabled. The {@link
-     * #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
-     * minimize} method returns the best point only. This method
+     * #optimize(ObjectiveFunction, int, ConvergenceChecker, 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 #minimize(CostFunction,
-     * int, ConvergenceChecker, double[], double[]) minimize} method.
+     * the best one already returned by the {@link #optimize(ObjectiveFunction,
+     * int, ConvergenceChecker, double[], double[]) optimize} method.
      * The array as one element for each start as specified in the constructor
      * (it has one element only if optimizer has been set up for single-start).</p>
-     * <p>The array containing the minima is ordered with the results
+     * <p>The array containing the optimum is ordered with the results
      * from the runs that did converge first, sorted from lowest to
-     * highest minimum cost, and null elements corresponding to the runs
-     * that did not converge (all elements will be null if the {@link
-     * #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
-     * minimize} method did throw a {@link ConvergenceException
-     * ConvergenceException}).</p>
-     * @return array containing the minima, or null if {@link
-     * #minimize(CostFunction, int, ConvergenceChecker, double[], double[])
-     * minimize} has not been called
+     * highest objective value if minimizing (from highest to lowest if maximizing),
+     * and null elements corresponding to the runs that did not converge. This means
+     * all elements will be null if the {@link #optimize(ObjectiveFunction, int,
+     * ConvergenceChecker, double[], double[]) optimize} method did throw a {@link
+     * ConvergenceException ConvergenceException}). This also means that if the first
+     * element is non null, it is the best point found accross all starts.</p>
+     * @return array containing the optima, or null if {@link
+     * #optimize(ObjectiveFunction, int, ConvergenceChecker, double[], double[])
+     * optimize} has not been called
      */
-    public PointCostPair[] getMinima() {
-        return (PointCostPair[]) minima.clone();
+    public PointValuePair[] getOptima() {
+        return (PointValuePair[]) optima.clone();
     }
 
-    /** Minimizes a cost function.
-     * @param f cost function
+    /** Optimizes an objective function.
+     * @param f objective function
      * @param maxEvaluations maximal number of function calls for each
      * start (note that the number will be checked <em>after</em>
      * complete simplices have been evaluated, this means that in some
      * cases this number will be exceeded by a few units, depending on
      * the dimension of the problem)
      * @param checker object to use to check for convergence
-     * @return the point/cost pairs giving the minimal cost
-     * @exception CostException if the cost function throws one during
+     * @param minimizing if true, function must be minimize otherwise it must be maximized
+     * @return the point/value pairs giving the optimal value for objective function
+     * @exception ObjectiveException if the objective function throws one during
      * the search
      * @exception ConvergenceException if none of the starts did
      * converge (it is not thrown if at least one start did converge)
      */
-    private PointCostPair minimize(CostFunction f, int maxEvaluations,
-                                    ConvergenceChecker checker)
-    throws CostException, ConvergenceException {
-
-        this.f = f;
-        minima = new PointCostPair[starts];
+    private PointValuePair optimize(final ObjectiveFunction f, final int maxEvaluations,
+                                   final ConvergenceChecker checker, final boolean minimizing)
+        throws ObjectiveException, ConvergenceException {
+
+        this.f          = f;
+        this.minimizing = minimizing;
+        optima = new PointValuePair[starts];
+        totalEvaluations = 0;
 
         // multi-start loop
         for (int i = 0; i < starts; ++i) {
@@ -482,18 +536,20 @@
 
             for (boolean loop = true; loop;) {
                 if (checker.converged(simplex)) {
-                    // we have found a minimum
-                    minima[i] = simplex[0];
+                    // we have found an optimum
+                    optima[i] = simplex[0];
                     loop = false;
                 } else if (evaluations >= maxEvaluations) {
                     // this start did not converge, try a new one
-                    minima[i] = null;
+                    optima[i] = null;
                     loop = false;
                 } else {
                     iterateSimplex();
                 }
             }
 
+            totalEvaluations += evaluations;
+
             if (i < (starts - 1)) {
                 // restart
                 buildSimplex(generator);
@@ -501,103 +557,90 @@
 
         }
 
-        // sort the minima from lowest cost to highest cost, followed by
+        // sort the optima from best to poorest, followed by
         // null elements
-        Arrays.sort(minima, pointCostPairComparator);
+        Arrays.sort(optima, PAIR_COMPARATOR);
+
+        if (!minimizing) {
+            // revert objective function sign to match user original definition
+            for (int i = 0; i < optima.length; ++i) {
+                final PointValuePair current = optima[i];
+                if (current != null) {
+                    optima[i] = new PointValuePair(current.getPoint(), -current.getValue());
+                }
+            }
+        }
 
-        // return the found point given the lowest cost
-        if (minima[0] == null) {
+        // return the found point given the best objective function value
+        if (optima[0] == null) {
             throw new ConvergenceException(
                     "none of the {0} start points lead to convergence",
                     starts);
         }
-        return minima[0];
+        return optima[0];
 
     }
 
+    /** Get the total number of evaluations of the objective function.
+     * <p>
+     * The total number of evaluations includes all evaluations for all
+     * starts if in optimization was done in multi-start mode.
+     * </p>
+     * @return total number of evaluations of the objective function
+     */
+    public int getTotalEvaluations() {
+        return totalEvaluations;
+    }
+
     /** Compute the next simplex of the algorithm.
-     * @exception CostException if the function cannot be evaluated at
+     * @exception ObjectiveException if the function cannot be evaluated at
      * some point
      */
-    protected abstract void iterateSimplex()
-    throws CostException;
+    protected abstract void iterateSimplex() throws ObjectiveException;
 
-    /** Evaluate the cost on one point.
+    /** Evaluate the objective function on one point.
      * <p>A side effect of this method is to count the number of
      * function evaluations</p>
-     * @param x point on which the cost function should be evaluated
-     * @return cost at the given point
-     * @exception CostException if no cost can be computed for the parameters
+     * @param x point on which the objective function should be evaluated
+     * @return objective function value at the given point
+     * @exception ObjectiveException if no value can be computed for the parameters
      */
-    protected double evaluateCost(double[] x)
-    throws CostException {
+    protected double evaluate(final double[] x) throws ObjectiveException {
         evaluations++;
-        return f.cost(x);
+        return minimizing ? f.objective(x) : -f.objective(x);
     }
 
     /** Evaluate all the non-evaluated points of the simplex.
-     * @exception CostException if no cost can be computed for the parameters
+     * @exception ObjectiveException if no value can be computed for the parameters
      */
-    protected void evaluateSimplex()
-    throws CostException {
+    protected void evaluateSimplex() throws ObjectiveException {
 
-        // evaluate the cost at all non-evaluated simplex points
+        // evaluate the objective function at all non-evaluated simplex points
         for (int i = 0; i < simplex.length; ++i) {
-            PointCostPair pair = simplex[i];
-            if (Double.isNaN(pair.getCost())) {
-                simplex[i] = new PointCostPair(pair.getPoint(), evaluateCost(pair.getPoint()));
+            PointValuePair pair = simplex[i];
+            if (Double.isNaN(pair.getValue())) {
+                simplex[i] = new PointValuePair(pair.getPoint(), evaluate(pair.getPoint()));
             }
         }
 
-        // sort the simplex from lowest cost to highest cost
-        Arrays.sort(simplex, pointCostPairComparator);
+        // sort the simplex from best to poorest
+        Arrays.sort(simplex, PAIR_COMPARATOR);
 
     }
 
     /** Replace the worst point of the simplex by a new point.
-     * @param pointCostPair point to insert
+     * @param pointValuePair point to insert
      */
-    protected void replaceWorstPoint(PointCostPair pointCostPair) {
+    protected void replaceWorstPoint(PointValuePair pointValuePair) {
         int n = simplex.length - 1;
         for (int i = 0; i < n; ++i) {
-            if (simplex[i].getCost() > pointCostPair.getCost()) {
-                PointCostPair tmp = simplex[i];
-                simplex[i]        = pointCostPair;
-                pointCostPair     = tmp;
+            if (simplex[i].getValue() > pointValuePair.getValue()) {
+                PointValuePair tmp = simplex[i];
+                simplex[i]        = pointValuePair;
+                pointValuePair     = tmp;
             }
         }
-        simplex[n] = pointCostPair;
+        simplex[n] = pointValuePair;
     }
 
-    /** Comparator for {@link PointCostPair PointCostPair} objects. */
-    private static Comparator<PointCostPair> pointCostPairComparator =
-        new Comparator<PointCostPair>() {
-        public int compare(PointCostPair o1, PointCostPair o2) {
-            if (o1 == null) {
-                return (o2 == null) ? 0 : +1;
-            } else if (o2 == null) {
-                return -1;
-            }
-            return (o1.getCost() < o2.getCost()) ? -1 : ((o1 == o2) ? 0 : +1);
-        }
-    };
-
-    /** Simplex. */
-    protected PointCostPair[] simplex;
-
-    /** Cost function. */
-    private CostFunction f;
-
-    /** Number of evaluations already performed. */
-    private int evaluations;
-
-    /** Number of starts to go. */
-    private int starts;
-
-    /** Random generator for multi-start. */
-    private RandomVectorGenerator generator;
-
-    /** Found minima. */
-    private PointCostPair[] minima;
-
 }

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/DirectSearchOptimizer.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/MultiDirectional.java (from r746504, commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java)
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/MultiDirectional.java?p2=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/MultiDirectional.java&p1=commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java&r1=746504&r2=748274&rev=748274&view=diff
==============================================================================
--- commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/MultiDirectional.java (original)
+++ commons/proper/math/trunk/src/java/org/apache/commons/math/optimization/direct/MultiDirectional.java Thu Feb 26 19:17:39 2009
@@ -15,7 +15,10 @@
  * limitations under the License.
  */
 
-package org.apache.commons.math.optimization;
+package org.apache.commons.math.optimization.direct;
+
+import org.apache.commons.math.optimization.ObjectiveException;
+import org.apache.commons.math.optimization.PointValuePair;
 
 /** 
  * This class implements the multi-directional direct search method.
@@ -24,103 +27,103 @@
  * @see NelderMead
  * @since 1.2
  */
-public class MultiDirectional
-  extends DirectSearchOptimizer {
-
-  /** Build a multi-directional optimizer with default coefficients.
-   * <p>The default values are 2.0 for khi and 0.5 for gamma.</p>
-   */
-  public MultiDirectional() {
-    super();
-    this.khi   = 2.0;
-    this.gamma = 0.5;
-  }
-
-  /** Build a multi-directional optimizer with specified coefficients.
-   * @param khi expansion coefficient
-   * @param gamma contraction coefficient
-   */
-  public MultiDirectional(double khi, double gamma) {
-    super();
-    this.khi   = khi;
-    this.gamma = gamma;
-  }
-
-  /** Compute the next simplex of the algorithm.
-   * @exception CostException if the function cannot be evaluated at
-   * some point
-   */
-  protected void iterateSimplex()
-    throws CostException {
-
-    while (true) {
-
-      // save the original vertex
-      PointCostPair[] original = simplex;
-      double originalCost = original[0].getCost();
-
-      // perform a reflection step
-      double reflectedCost = evaluateNewSimplex(original, 1.0);
-      if (reflectedCost < originalCost) {
-
-        // compute the expanded simplex
-        PointCostPair[] reflected = simplex;
-        double expandedCost = evaluateNewSimplex(original, khi);
-        if (reflectedCost <= expandedCost) {
-          // accept the reflected simplex
-          simplex = reflected;
-        }
+public class MultiDirectional extends DirectSearchOptimizer {
 
-        return;
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -5347711305645019145L;
 
-      }
+    /** Expansion coefficient. */
+    private final double khi;
 
-      // compute the contracted simplex
-      double contractedCost = evaluateNewSimplex(original, gamma);
-      if (contractedCost < originalCost) {
-        // accept the contracted simplex
-        return;
-      }
+    /** Contraction coefficient. */
+    private final double gamma;
+
+    /** Build a multi-directional optimizer with default coefficients.
+     * <p>The default values are 2.0 for khi and 0.5 for gamma.</p>
+     */
+    public MultiDirectional() {
+        this.khi   = 2.0;
+        this.gamma = 0.5;
+    }
 
+    /** Build a multi-directional optimizer with specified coefficients.
+     * @param khi expansion coefficient
+     * @param gamma contraction coefficient
+     */
+    public MultiDirectional(final double khi, final double gamma) {
+        this.khi   = khi;
+        this.gamma = gamma;
     }
 
-  }
+    /** Compute the next simplex of the algorithm.
+     * @exception ObjectiveException if the function cannot be evaluated at
+     * some point
+     */
+    protected void iterateSimplex() throws ObjectiveException {
+
+        while (true) {
+
+            // save the original vertex
+            final PointValuePair[] original = simplex;
+            final double originalValue = original[0].getValue();
+
+            // perform a reflection step
+            final double reflectedValue = evaluateNewSimplex(original, 1.0);
+            if (reflectedValue < originalValue) {
+
+                // compute the expanded simplex
+                final PointValuePair[] reflected = simplex;
+                final double expandedValue = evaluateNewSimplex(original, khi);
+                if (reflectedValue <= expandedValue) {
+                    // accept the reflected simplex
+                    simplex = reflected;
+                }
+
+                return;
+
+            }
+
+            // compute the contracted simplex
+            final double contractedValue = evaluateNewSimplex(original, gamma);
+            if (contractedValue < originalValue) {
+                // accept the contracted simplex
+                return;
+            }
 
-  /** Compute and evaluate a new simplex.
-   * @param original original simplex (to be preserved)
-   * @param coeff linear coefficient
-   * @return smallest cost in the transformed simplex
-   * @exception CostException if the function cannot be evaluated at
-   * some point
-   */
-  private double evaluateNewSimplex(PointCostPair[] original, double coeff)
-    throws CostException {
-
-    double[] xSmallest = original[0].getPoint();
-    int n = xSmallest.length;
-
-    // create the linearly transformed simplex
-    simplex = new PointCostPair[n + 1];
-    simplex[0] = original[0];
-    for (int i = 1; i <= n; ++i) {
-      double[] xOriginal    = original[i].getPoint();
-      double[] xTransformed = new double[n];
-      for (int j = 0; j < n; ++j) {
-        xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
-      }
-      simplex[i] = new PointCostPair(xTransformed, Double.NaN);
-    }
+        }
 
-    // evaluate it
-    evaluateSimplex();
-    return simplex[0].getCost();
+    }
 
-  }
+    /** Compute and evaluate a new simplex.
+     * @param original original simplex (to be preserved)
+     * @param coeff linear coefficient
+     * @return smallest value in the transformed simplex
+     * @exception ObjectiveException if the function cannot be evaluated at
+     * some point
+     */
+    private double evaluateNewSimplex(final PointValuePair[] original,
+                                      final double coeff)
+        throws ObjectiveException {
+
+        final double[] xSmallest = original[0].getPoint();
+        final int n = xSmallest.length;
+
+        // create the linearly transformed simplex
+        simplex = new PointValuePair[n + 1];
+        simplex[0] = original[0];
+        for (int i = 1; i <= n; ++i) {
+            final double[] xOriginal    = original[i].getPoint();
+            final double[] xTransformed = new double[n];
+            for (int j = 0; j < n; ++j) {
+                xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
+            }
+            simplex[i] = new PointValuePair(xTransformed, Double.NaN);
+        }
 
-  /** Expansion coefficient. */
-  private double khi;
+        // evaluate it
+        evaluateSimplex();
+        return simplex[0].getValue();
 
-  /** Contraction coefficient. */
-  private double gamma;
+    }
 
 }