You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by lu...@apache.org on 2007/02/26 23:59:47 UTC

svn commit: r512061 - in /jakarta/commons/proper/math/trunk/src: java/org/apache/commons/math/estimation/ mantissa/src/org/spaceroots/mantissa/estimation/ mantissa/src/org/spaceroots/mantissa/estimation/doc-files/ mantissa/tests-src/org/spaceroots/mant...

Author: luc
Date: Mon Feb 26 14:59:45 2007
New Revision: 512061

URL: http://svn.apache.org/viewvc?view=rev&rev=512061
Log:
added the estimation package from Mantissa

Added:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java   (with props)
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html   (with props)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/
      - copied from r511516, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java
      - copied, changed from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/EstimatedParameterTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java
      - copied, changed from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/LevenbergMarquardtEstimatorTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java
      - copied, changed from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/MinpackTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java
      - copied, changed from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/WeightedMeasurementTest.java
Removed:
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimatedParameter.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationException.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/EstimationProblem.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/Estimator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/GaussNewtonEstimator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/LeastSquaresEstimator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/LevenbergMarquardtEstimator.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/WeightedMeasurement.java
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/doc-files/
    jakarta/commons/proper/math/trunk/src/mantissa/src/org/spaceroots/mantissa/estimation/package.html
    jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/AllTests.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/GaussNewtonEstimatorTest.java

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,123 @@
+// 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.estimation;
+
+import java.io.Serializable;
+
+/** This class represent the estimated parameters of an estimation problem.
+
+ * <p>The parameters of an estimation problem have a name, a value and
+ * a bound flag. The value of bound parameters is considered trusted
+ * and the solvers should not adjust them. On the other hand, the
+ * solvers should adjust the value of unbounds parameters until they
+ * satisfy convergence criterions specific to each solver.</p>
+
+ * @version $Id: EstimatedParameter.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class EstimatedParameter
+  implements Serializable {
+
+  /** Simple constructor.
+   * Build an instance from a first estimate of the parameter,
+   * initially considered unbound.
+   * @param name name of the parameter
+   * @param firstEstimate first estimate of the parameter
+   */
+  public EstimatedParameter(String name, double firstEstimate) {
+    this.name = name;
+    estimate  = firstEstimate;
+    bound     = false;
+  }
+
+  /** Simple constructor.
+   * Build an instance from a first estimate of the parameter and a
+   * bound flag
+   * @param name name of the parameter
+   * @param firstEstimate first estimate of the parameter
+   * @param bound flag, should be true if the parameter is bound
+   */
+  public EstimatedParameter(String name,
+                            double firstEstimate,
+                            boolean bound) {
+    this.name  = name;
+    estimate   = firstEstimate;
+    this.bound = bound;
+  }
+
+  /** Copy constructor.
+   * Build a copy of a parameter
+   * @param parameter instance to copy
+   */
+  public EstimatedParameter(EstimatedParameter parameter) {
+    name     = parameter.name;
+    estimate = parameter.estimate;
+    bound    = parameter.bound;
+  }
+
+  /** Set a new estimated value for the parameter.
+   * @param estimate new estimate for the parameter
+   */
+  public void setEstimate(double estimate) {
+    this.estimate = estimate;
+  }
+
+  /** Get the current estimate of the parameter
+   * @return current estimate
+   */
+  public double getEstimate() {
+    return estimate;
+  }
+
+  /** get the name of the parameter
+   * @return parameter name
+   */
+  public String getName() {
+    return name;
+  }
+
+  /** Set the bound flag of the parameter
+   * @param bound this flag should be set to true if the parameter is
+   * bound (i.e. if it should not be adjusted by the solver).
+   */
+  public void setBound(boolean bound) {
+    this.bound = bound;
+  }
+
+  /** Check if the parameter is bound
+   * @return true if the parameter is bound */
+  public boolean isBound() {
+    return bound;
+  }
+
+  /** Name of the parameter */
+  private   String  name;
+
+  /** Current value of the parameter */
+  protected double  estimate;
+
+  /** Indicator for bound parameters
+   * (ie parameters that should not be estimated)
+   */
+  private   boolean bound;
+
+  private static final long serialVersionUID = -555440800213416949L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimatedParameter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,52 @@
+// 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.estimation;
+
+import org.apache.commons.math.MathException;
+
+/** This class represents exceptions thrown by the estimation solvers.
+
+ * @version $Id: EstimationException.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class EstimationException
+extends MathException {
+
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -7414806622114810487L;
+
+    /** Simple constructor.
+     * Build an exception by translating and formating a message
+     * @param specifier format specifier (to be translated)
+     * @param parts to insert in the format (no translation)
+     */
+    public EstimationException(String specifier, String[] parts) {
+        super(specifier, parts);
+    }
+
+    /** Simple constructor.
+     * Build an exception from a cause
+     * @param cause cause of this exception
+     */
+    public EstimationException(Throwable cause) {
+        super(cause);
+    }
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,61 @@
+// 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.estimation;
+
+/** This interface represents an estimation problem.
+
+ * <p>This interface should be implemented by all real estimation
+ * problems before they can be handled by the estimators through the
+ * {@link Estimator#estimate Estimator.estimate} method.</p>
+
+ * <p>An estimation problem, as seen by a solver is a set of
+ * parameters and a set of measurements. The parameters are adjusted
+ * during the estimation through the {@link #getUnboundParameters
+ * getUnboundParameters} and {@link EstimatedParameter#setEstimate
+ * EstimatedParameter.setEstimate} methods. The measurements both have
+ * a measured value which is generally fixed at construction and a
+ * theoretical value which depends on the model and hence varies as
+ * the parameters are adjusted. The purpose of the solver is to reduce
+ * the residual between these values, it can retrieve the measurements
+ * through the {@link #getMeasurements getMeasurements} method.</p>
+
+ * @see Estimator
+ * @see WeightedMeasurement
+
+ * @version $Id: EstimationProblem.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public interface EstimationProblem {
+  /** Get the measurements of an estimation problem.
+   * @return measurements
+   */
+  public WeightedMeasurement[] getMeasurements();
+
+  /** Get the unbound parameters of the problem.
+   * @return unbound parameters
+   */
+  public EstimatedParameter[] getUnboundParameters();
+
+  /** Get all the parameters of the problem.
+   * @return parameters
+   */
+  public EstimatedParameter[] getAllParameters();
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/EstimationProblem.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,66 @@
+// 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.estimation;
+
+/** This interface represents solvers for estimation problems.
+
+ * <p>The classes which are devoted to solve estimation problems
+ * should implement this interface. The problems which can be handled
+ * should implement the {@link EstimationProblem} interface which
+ * gather all the information needed by the solver.</p>
+
+ * <p>The interface is composed only of the {@link #estimate estimate}
+ * method.</p>
+
+ * @see EstimationProblem
+
+ * @version $Id: Estimator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public interface Estimator {
+
+  /** Solve an estimation problem.
+
+   * <p>The method should set the parameters of the problem to several
+   * trial values until it reaches convergence. If this method returns
+   * normally (i.e. without throwing an exception), then the best
+   * estimate of the parameters can be retrieved from the problem
+   * itself, through the {@link EstimationProblem#getAllParameters
+   * EstimationProblem.getAllParameters} method.</p>
+
+   * @param problem estimation problem to solve
+   * @exception EstimationException if the problem cannot be solved
+
+   */
+  public void estimate(EstimationProblem problem)
+    throws EstimationException;
+
+  /** Get the Root Mean Square value.
+   * Get the Root Mean Square value, i.e. the root of the arithmetic
+   * mean of the square of all weighted residuals. This is related to the
+   * criterion that is minimized by the estimator as follows: if
+   * <em>c</em> if the criterion, and <em>n</em> is the number of
+   * measurements, the the RMS is <em>sqrt (c/n)</em>.
+   * @param problem estimation problem
+   * @return RMS value
+   */
+  public double getRMS(EstimationProblem problem);
+ 
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/Estimator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,235 @@
+// 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.estimation;
+
+import java.io.Serializable;
+
+import org.apache.commons.math.linear.InvalidMatrixException;
+import org.apache.commons.math.linear.RealMatrix;
+import org.apache.commons.math.linear.RealMatrixImpl;
+
+/** This class implements a solver for estimation problems.
+
+ * <p>This class solves estimation problems using a weighted least
+ * squares criterion on the measurement residuals. It uses a
+ * Gauss-Newton algorithm.</p>
+
+ * @version $Id: GaussNewtonEstimator.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public class GaussNewtonEstimator
+  implements Estimator, Serializable {
+
+  /** Simple constructor.
+
+   * <p>This constructor build an estimator and store its convergence
+   * characteristics.</p>
+
+   * <p>An estimator is considered to have converged whenever either
+   * the criterion goes below a physical threshold under which
+   * improvements are considered useless or when the algorithm is
+   * unable to improve it (even if it is still high). The first
+   * condition that is met stops the iterations.</p>
+
+   * <p>The fact an estimator has converged does not mean that the
+   * model accurately fits the measurements. It only means no better
+   * solution can be found, it does not mean this one is good. Such an
+   * analysis is left to the caller.</p>
+
+   * <p>If neither conditions are fulfilled before a given number of
+   * iterations, the algorithm is considered to have failed and an
+   * {@link EstimationException} is thrown.</p>
+
+   * @param maxIterations maximum number of iterations allowed
+   * @param convergence criterion threshold below which we do not need
+   * to improve the criterion anymore
+   * @param steadyStateThreshold steady state detection threshold, the
+   * problem has converged has reached a steady state if
+   * <code>Math.abs (Jn - Jn-1) < Jn * convergence</code>, where
+   * <code>Jn</code> and <code>Jn-1</code> are the current and
+   * preceding criterion value (square sum of the weighted residuals
+   * of considered measurements).
+   */
+  public GaussNewtonEstimator(int maxIterations,
+                               double convergence,
+                               double steadyStateThreshold) {
+    this.maxIterations        = maxIterations;
+    this.steadyStateThreshold = steadyStateThreshold;
+    this.convergence          = convergence;
+  }
+
+  /** Solve an estimation problem using a least squares criterion.
+
+   * <p>This method set the unbound parameters of the given problem
+   * starting from their current values through several iterations. At
+   * each step, the unbound parameters are changed in order to
+   * minimize a weighted least square criterion based on the
+   * measurements of the problem.</p>
+
+   * <p>The iterations are stopped either when the criterion goes
+   * below a physical threshold under which improvement are considered
+   * useless or when the algorithm is unable to improve it (even if it
+   * is still high). The first condition that is met stops the
+   * iterations. If the convergence it nos reached before the maximum
+   * number of iterations, an {@link EstimationException} is
+   * thrown.</p>
+
+   * @param problem estimation problem to solve
+   * @exception EstimationException if the problem cannot be solved
+
+   * @see EstimationProblem
+
+   */
+  public void estimate(EstimationProblem problem)
+    throws EstimationException {
+    int    iterations = 0;
+    double previous   = 0.0;
+    double current    = 0.0;
+
+    // iterate until convergence is reached
+    do {
+
+      if (++iterations > maxIterations) {
+        throw new EstimationException ("unable to converge in {0} iterations",
+                                       new String[] {
+                                         Integer.toString(maxIterations)
+                                       });
+      }
+
+      // perform one iteration
+      linearEstimate(problem);
+
+      previous = current;
+      current  = evaluateCriterion(problem);
+
+    } while ((iterations < 2)
+             || (Math.abs(previous - current) > (current * steadyStateThreshold)
+                 && (Math.abs(current) > convergence)));
+
+  }
+
+  /** Estimate the solution of a linear least square problem.
+
+   * <p>The Gauss-Newton algorithm is iterative. Each iteration
+   * consist in solving a linearized least square problem. Several
+   * iterations are needed for general problems since the
+   * linearization is only an approximation of the problem
+   * behaviour. However, for linear problems one iteration is enough
+   * to get the solution. This method is provided in the public
+   * interface in order to handle more efficiently these linear
+   * problems.</p>
+
+   * @param problem estimation problem to solve
+   * @exception EstimationException if the problem cannot be solved
+
+   */
+  public void linearEstimate(EstimationProblem problem)
+    throws EstimationException {
+
+    EstimatedParameter[]  parameters   = problem.getUnboundParameters();
+    WeightedMeasurement[] measurements = problem.getMeasurements();
+
+    // build the linear problem
+    RealMatrix b              = new RealMatrixImpl(parameters.length, 1);
+    RealMatrix a              = new RealMatrixImpl(parameters.length, parameters.length);
+    double[] grad             = new double[parameters.length];
+    RealMatrixImpl bDecrement = new RealMatrixImpl(parameters.length, 1);
+    double[][] bDecrementData = bDecrement.getDataRef();
+    RealMatrixImpl wGradGradT = new RealMatrixImpl(parameters.length, parameters.length);
+    double[][] wggData        = wGradGradT.getDataRef();
+    for (int i = 0; i < measurements.length; ++i) {
+        if (! measurements [i].isIgnored()) {
+
+            double weight   = measurements[i].getWeight();
+            double residual = measurements[i].getResidual();
+
+            // compute the normal equation
+            for (int j = 0; j < parameters.length; ++j) {
+                grad[j] = measurements[i].getPartial(parameters[j]);
+                bDecrementData[j][0] = weight * residual * grad[j];
+            }
+
+            // build the contribution matrix for measurement i
+            for (int k = 0; k < parameters.length; ++k) {
+                double[] wggRow = wggData[k];
+                double gk = grad[k];
+                for (int l = 0; l < parameters.length; ++l) {
+                    wggRow[l] =  weight * gk * grad[l];
+                }
+            }
+
+            // update the matrices
+            a = a.add(wGradGradT);
+            b = b.add(bDecrement);
+
+        }
+    }
+
+    try {
+
+      // solve the linearized least squares problem
+      RealMatrix dX = a.solve(b);
+
+      // update the estimated parameters
+      for (int i = 0; i < parameters.length; ++i) {
+        parameters[i].setEstimate(parameters[i].getEstimate() + dX.getEntry(i, 0));
+      }
+
+    } catch(InvalidMatrixException e) {
+      throw new EstimationException(e);
+    }
+
+  }
+
+  private double evaluateCriterion(EstimationProblem problem) {
+    double criterion = 0.0;
+    WeightedMeasurement[] measurements = problem.getMeasurements();
+
+    for (int i = 0; i < measurements.length; ++i) {
+      double residual = measurements[i].getResidual();
+      criterion      += measurements[i].getWeight() * residual * residual;
+    }
+
+    return criterion;
+
+  }
+
+  /** Get the Root Mean Square value.
+   * Get the Root Mean Square value, i.e. the root of the arithmetic
+   * mean of the square of all weighted residuals. This is related to the
+   * criterion that is minimized by the estimator as follows: if
+   * <em>c</em> if the criterion, and <em>n</em> is the number of
+   * measurements, then the RMS is <em>sqrt (c/n)</em>.
+   * @param problem estimation problem
+   * @return RMS value
+   */
+  public double getRMS(EstimationProblem problem) {
+    double criterion = evaluateCriterion(problem);
+    int n = problem.getMeasurements().length;
+    return Math.sqrt(criterion / n);
+  }
+
+  private int    maxIterations;
+  private double steadyStateThreshold;
+  private double convergence;
+
+  private static final long serialVersionUID = -7606628156644194170L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/GaussNewtonEstimator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,971 @@
+/*
+ * 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.estimation;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/** This class solves a least squares problem.
+
+ * <p>This implementation <em>should</em> work even for over-determined systems
+ * (i.e. systems having more variables than equations). Over-determined systems
+ * are solved by ignoring the variables which have the smallest impact according
+ * to their jacobian column norm. Only the rank of the matrix and some loop bounds
+ * are changed to implement this. This feature has undergone only basic testing
+ * for now and should still be considered experimental.</p>
+
+ * <p>The resolution engine is a simple translation of the MINPACK <a
+ * href="http://www.netlib.org/minpack/lmder.f">lmder</a> routine with minor
+ * changes. The changes include the over-determined resolution and the Q.R.
+ * decomposition which has been rewritten following the algorithm described in the
+ * P. Lascaux and R. Theodor book <i>Analyse num&eacute;rique matricielle
+ * appliqu&eacute;e &agrave; l'art de l'ing&eacute;nieur</i>, Masson 1986. The
+ * redistribution policy for MINPACK is available <a
+ * href="http://www.netlib.org/minpack/disclaimer">here</a>, for convenience, it
+ * is reproduced below.</p>
+
+ * <table border="0" width="80%" cellpadding="10" align="center" bgcolor="#E0E0E0">
+ * <tr><td>
+ *    Minpack Copyright Notice (1999) University of Chicago.
+ *    All rights reserved
+ * </td></tr>
+ * <tr><td>
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * <ol>
+ *  <li>Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.</li>
+ * <li>Redistributions in binary form must reproduce the above
+ *     copyright notice, this list of conditions and the following
+ *     disclaimer in the documentation and/or other materials provided
+ *     with the distribution.</li>
+ * <li>The end-user documentation included with the redistribution, if any,
+ *     must include the following acknowledgment:
+ *     <code>This product includes software developed by the University of
+ *           Chicago, as Operator of Argonne National Laboratory.</code>
+ *     Alternately, this acknowledgment may appear in the software itself,
+ *     if and wherever such third-party acknowledgments normally appear.</li>
+ * <li><strong>WARRANTY DISCLAIMER. THE SOFTWARE IS SUPPLIED "AS IS"
+ *     WITHOUT WARRANTY OF ANY KIND. THE COPYRIGHT HOLDER, THE
+ *     UNITED STATES, THE UNITED STATES DEPARTMENT OF ENERGY, AND
+ *     THEIR EMPLOYEES: (1) DISCLAIM ANY WARRANTIES, EXPRESS OR
+ *     IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES
+ *     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE
+ *     OR NON-INFRINGEMENT, (2) DO NOT ASSUME ANY LEGAL LIABILITY
+ *     OR RESPONSIBILITY FOR THE ACCURACY, COMPLETENESS, OR
+ *     USEFULNESS OF THE SOFTWARE, (3) DO NOT REPRESENT THAT USE OF
+ *     THE SOFTWARE WOULD NOT INFRINGE PRIVATELY OWNED RIGHTS, (4)
+ *     DO NOT WARRANT THAT THE SOFTWARE WILL FUNCTION
+ *     UNINTERRUPTED, THAT IT IS ERROR-FREE OR THAT ANY ERRORS WILL
+ *     BE CORRECTED.</strong></li>
+ * <li><strong>LIMITATION OF LIABILITY. IN NO EVENT WILL THE COPYRIGHT
+ *     HOLDER, THE UNITED STATES, THE UNITED STATES DEPARTMENT OF
+ *     ENERGY, OR THEIR EMPLOYEES: BE LIABLE FOR ANY INDIRECT,
+ *     INCIDENTAL, CONSEQUENTIAL, SPECIAL OR PUNITIVE DAMAGES OF
+ *     ANY KIND OR NATURE, INCLUDING BUT NOT LIMITED TO LOSS OF
+ *     PROFITS OR LOSS OF DATA, FOR ANY REASON WHATSOEVER, WHETHER
+ *     SUCH LIABILITY IS ASSERTED ON THE BASIS OF CONTRACT, TORT
+ *     (INCLUDING NEGLIGENCE OR STRICT LIABILITY), OR OTHERWISE,
+ *     EVEN IF ANY OF SAID PARTIES HAS BEEN WARNED OF THE
+ *     POSSIBILITY OF SUCH LOSS OR DAMAGES.</strong></li>
+ * <ol></td></tr>
+ * </table>
+
+ * @author Argonne National Laboratory. MINPACK project. March 1980 (original fortran)
+ * @author Burton S. Garbow (original fortran)
+ * @author Kenneth E. Hillstrom (original fortran)
+ * @author Jorge J. More (original fortran)
+ * @author Luc Maisonobe (Java translation)
+ */
+public class LevenbergMarquardtEstimator implements Serializable, Estimator {
+
+  /** Build an estimator for least squares problems.
+   * <p>The default values for the algorithm settings are:
+   *   <ul>
+   *    <li>{@link #setInitialStepBoundFactor initial step bound factor}: 100.0</li>
+   *    <li>{@link #setMaxCostEval maximal cost evaluations}: 1000</li>
+   *    <li>{@link #setCostRelativeTolerance cost relative tolerance}: 1.0e-10</li>
+   *    <li>{@link #setParRelativeTolerance parameters relative tolerance}: 1.0e-10</li>
+   *    <li>{@link #setOrthoTolerance orthogonality tolerance}: 1.0e-10</li>
+   *   </ul>
+   * </p>
+   */
+  public LevenbergMarquardtEstimator() {
+    // default values for the tuning parameters
+    setInitialStepBoundFactor(100.0);
+    setMaxCostEval(1000);
+    setCostRelativeTolerance(1.0e-10);
+    setParRelativeTolerance(1.0e-10);
+    setOrthoTolerance(1.0e-10);
+  }
+
+  /** Set the positive input variable used in determining the initial step bound.
+   * This bound is set to the product of initialStepBoundFactor and the euclidean norm of diag*x if nonzero,
+   * or else to initialStepBoundFactor itself. In most cases factor should lie
+   * in the interval (0.1, 100.0). 100.0 is a generally recommended value
+   * @param initialStepBoundFactor initial step bound factor
+   * @see #estimate
+   */
+  public void setInitialStepBoundFactor(double initialStepBoundFactor) {
+    this.initialStepBoundFactor = initialStepBoundFactor;
+  }
+
+  /** Set the maximal number of cost evaluations.
+  * @param maxCostEval maximal number of cost evaluations
+   * @see #estimate
+  */
+  public void setMaxCostEval(int maxCostEval) {
+    this.maxCostEval = maxCostEval;
+  }
+
+  /** Set the desired relative error in the sum of squares.
+   * @param costRelativeTolerance desired relative error in the sum of squares
+   * @see #estimate
+   */
+  public void setCostRelativeTolerance(double costRelativeTolerance) {
+    this.costRelativeTolerance = costRelativeTolerance;
+  }
+
+  /** Set the desired relative error in the approximate solution parameters.
+   * @param parRelativeTolerance desired relative error
+   * in the approximate solution parameters
+   * @see #estimate
+   */
+  public void setParRelativeTolerance(double parRelativeTolerance) {
+    this.parRelativeTolerance = parRelativeTolerance;
+  }
+
+  /** Set the desired max cosine on the orthogonality.
+   * @param orthoTolerance desired max cosine on the orthogonality
+   * between the function vector and the columns of the jacobian
+   * @see #estimate
+   */
+  public void setOrthoTolerance(double orthoTolerance) {
+    this.orthoTolerance = orthoTolerance;
+  }
+
+  /** Get the number of cost evaluations.
+   * @return number of cost evaluations
+   * */
+  public int getCostEvaluations() {
+    return costEvaluations;
+  }
+
+  /** Get the number of jacobian evaluations.
+   * @return number of jacobian evaluations
+   * */
+  public int getJacobianEvaluations() {
+    return jacobianEvaluations;
+  }
+
+  /** Update the jacobian matrix.
+   */
+  private void updateJacobian() {
+    ++jacobianEvaluations;
+    Arrays.fill(jacobian, 0);
+    for (int i = 0, index = 0; i < rows; i++) {
+      WeightedMeasurement wm = measurements[i];
+      double factor = -Math.sqrt(wm.getWeight());
+      for (int j = 0; j < cols; ++j) {
+        jacobian[index++] = factor * wm.getPartial(parameters[j]);
+      }
+    }
+  }
+
+  /** Update the residuals array and cost function value.
+   */
+  private void updateResidualsAndCost() {
+    ++costEvaluations;
+    cost = 0;
+    for (int i = 0, index = 0; i < rows; i++, index += cols) {
+      WeightedMeasurement wm = measurements[i];
+      double residual = wm.getResidual();
+      residuals[i] = Math.sqrt(wm.getWeight()) * residual;
+      cost += wm.getWeight() * residual * residual;
+    }
+    cost = Math.sqrt(cost);
+  }
+
+  /** Get the Root Mean Square value.
+   * Get the Root Mean Square value, i.e. the root of the arithmetic
+   * mean of the square of all weighted residuals. This is related to the
+   * criterion that is minimized by the estimator as follows: if
+   * <em>c</em> if the criterion, and <em>n</em> is the number of
+   * measurements, then the RMS is <em>sqrt (c/n)</em>.
+   * @param problem estimation problem
+   * @return RMS value
+   */
+  public double getRMS(EstimationProblem problem) {
+    WeightedMeasurement[] wm = problem.getMeasurements();
+    double criterion = 0;
+    for (int i = 0; i < wm.length; ++i) {
+      double residual = wm[i].getResidual();
+      criterion += wm[i].getWeight() * residual * residual;
+    }
+    return Math.sqrt(criterion / wm.length);
+  }
+
+  /** Solve an estimation problem using the Levenberg-Marquardt algorithm.
+   * <p>The algorithm used is a modified Levenberg-Marquardt one, based
+   * on the MINPACK <a href="http://www.netlib.org/minpack/lmder.f">lmder</a>
+   * routine. The algorithm settings must have been set up before this method
+   * is called with the {@link #setInitialStepBoundFactor},
+   * {@link #setMaxCostEval}, {@link #setCostRelativeTolerance},
+   * {@link #setParRelativeTolerance} and {@link #setOrthoTolerance} methods.
+   * If these methods have not been called, the default values set up by the
+   * {@link #LevenbergMarquardtEstimator() constructor} will be used.</p>
+   * <p>The authors of the original fortran function are:</p>
+   * <ul>
+   *   <li>Argonne National Laboratory. MINPACK project. March 1980</li>
+   *   <li>Burton  S. Garbow</li>
+   *   <li>Kenneth E. Hillstrom</li>
+   *   <li>Jorge   J. More</li>
+   *   </ul>
+   * <p>Luc Maisonobe did the Java translation.</p>
+   * @param problem estimation problem to solve
+   * @exception EstimationException if convergence cannot be
+   * reached with the specified algorithm settings or if there are more variables
+   * than equations
+   * @see #setInitialStepBoundFactor
+   * @see #setMaxCostEval
+   * @see #setCostRelativeTolerance
+   * @see #setParRelativeTolerance
+   * @see #setOrthoTolerance
+   */
+  public void estimate(EstimationProblem problem)
+    throws EstimationException {
+
+    // retrieve the equations and the parameters
+    measurements = problem.getMeasurements();
+    parameters   = problem.getUnboundParameters();
+
+    // arrays shared with the other private methods
+    rows        = measurements.length;
+    cols        = parameters.length;
+    solvedCols  = Math.min(rows, cols);
+    jacobian    = new double[rows * cols];
+    diagR       = new double[cols];
+    jacNorm     = new double[cols];
+    beta        = new double[cols];
+    permutation = new int[cols];
+    lmDir       = new double[cols];
+    residuals   = new double[rows];
+
+    // local variables
+    double   delta   = 0, xNorm = 0;
+    double[] diag    = new double[cols];
+    double[] oldX    = new double[cols];
+    double[] oldRes  = new double[rows];
+    double[] work1   = new double[cols];
+    double[] work2   = new double[cols];
+    double[] work3   = new double[cols];
+
+    // evaluate the function at the starting point and calculate its norm
+    updateResidualsAndCost();
+    
+    // outer loop
+    lmPar               = 0;
+    costEvaluations     = 0;
+    jacobianEvaluations = 0;
+    boolean firstIteration = true;
+    while (costEvaluations < maxCostEval) {
+
+      // compute the Q.R. decomposition of the jacobian matrix
+      updateJacobian();
+      qrDecomposition();
+
+      // compute Qt.res
+      qTy(residuals);
+
+      // now we don't need Q anymore,
+      // so let jacobian contain the R matrix with its diagonal elements
+      for (int k = 0; k < solvedCols; ++k) {
+        int pk = permutation[k];
+        jacobian[k * cols + pk] = diagR[pk];
+      }
+
+      if (firstIteration) {
+
+        // scale the variables according to the norms of the columns
+        // of the initial jacobian
+        xNorm = 0;
+        for (int k = 0; k < cols; ++k) {
+          double dk = jacNorm[k];
+          if (dk == 0) {
+            dk = 1.0;
+          }
+          double xk = dk * parameters[k].getEstimate();
+          xNorm  += xk * xk;
+          diag[k] = dk;
+        }
+        xNorm = Math.sqrt(xNorm);
+        
+        // initialize the step bound delta
+        delta = (xNorm == 0)
+              ? initialStepBoundFactor : (initialStepBoundFactor * xNorm);
+ 
+      }
+
+      // check orthogonality between function vector and jacobian columns
+      double maxCosine = 0;
+      if (cost != 0) {
+        for (int j = 0; j < solvedCols; ++j) {
+          int    pj = permutation[j];
+          double s  = jacNorm[pj];
+          if (s != 0) {
+            double sum = 0;
+            for (int i = 0, index = pj; i <= j; ++i, index += cols) {
+              sum += jacobian[index] * residuals[i];
+            }
+            maxCosine = Math.max(maxCosine, Math.abs(sum) / (s * cost));
+          }
+        }
+      }
+      if (maxCosine <= orthoTolerance) {
+        return;
+      }
+
+      // rescale if necessary
+      for (int j = 0; j < cols; ++j) {
+        diag[j] = Math.max(diag[j], jacNorm[j]);
+      }
+
+      // inner loop
+      for (double ratio = 0; ratio < 1.0e-4;) {
+
+        // save the state
+        for (int j = 0; j < solvedCols; ++j) {
+          int pj = permutation[j];
+          oldX[pj] = parameters[pj].getEstimate();
+        }
+        double previousCost = cost;
+        double[] tmpVec = residuals;
+        residuals = oldRes;
+        oldRes    = tmpVec;
+        
+        // determine the Levenberg-Marquardt parameter
+        determineLMParameter(oldRes, delta, diag, work1, work2, work3);
+
+        // compute the new point and the norm of the evolution direction
+        double lmNorm = 0;
+        for (int j = 0; j < solvedCols; ++j) {
+          int pj = permutation[j];
+          lmDir[pj] = -lmDir[pj];
+          parameters[pj].setEstimate(oldX[pj] + lmDir[pj]);
+          double s = diag[pj] * lmDir[pj];
+          lmNorm  += s * s;
+        }
+        lmNorm = Math.sqrt(lmNorm);
+
+        // on the first iteration, adjust the initial step bound.
+        if (firstIteration) {
+          delta = Math.min(delta, lmNorm);
+        }
+
+        // evaluate the function at x + p and calculate its norm
+        updateResidualsAndCost();
+
+        // compute the scaled actual reduction
+        double actRed = -1.0;
+        if (0.1 * cost < previousCost) {
+          double r = cost / previousCost;
+          actRed = 1.0 - r * r;
+        }
+
+        // compute the scaled predicted reduction
+        // and the scaled directional derivative
+        for (int j = 0; j < solvedCols; ++j) {
+          int pj = permutation[j];
+          double dirJ = lmDir[pj];
+          work1[j] = 0;
+          for (int i = 0, index = pj; i <= j; ++i, index += cols) {
+            work1[i] += jacobian[index] * dirJ;
+          }
+        }
+        double coeff1 = 0;
+        for (int j = 0; j < solvedCols; ++j) {
+         coeff1 += work1[j] * work1[j];
+        }
+        double pc2 = previousCost * previousCost;
+        coeff1 = coeff1 / pc2;
+        double coeff2 = lmPar * lmNorm * lmNorm / pc2;
+        double preRed = coeff1 + 2 * coeff2;
+        double dirDer = -(coeff1 + coeff2);
+
+        // ratio of the actual to the predicted reduction
+        ratio = (preRed == 0) ? 0 : (actRed / preRed);
+
+        // update the step bound
+        if (ratio <= 0.25) {
+          double tmp =
+            (actRed < 0) ? (0.5 * dirDer / (dirDer + 0.5 * actRed)) : 0.5;
+          if ((0.1 * cost >= previousCost) || (tmp < 0.1)) {
+            tmp = 0.1;
+          }
+          delta = tmp * Math.min(delta, 10.0 * lmNorm);
+          lmPar /= tmp;
+        } else if ((lmPar == 0) || (ratio >= 0.75)) {
+          delta = 2 * lmNorm;
+          lmPar *= 0.5;
+        }
+
+        // test for successful iteration.
+        if (ratio >= 1.0e-4) {
+          // successful iteration, update the norm
+          firstIteration = false;
+          xNorm = 0;
+          for (int k = 0; k < cols; ++k) {
+            double xK = diag[k] * parameters[k].getEstimate();
+            xNorm    += xK * xK;
+          }
+          xNorm = Math.sqrt(xNorm);
+        } else {
+          // failed iteration, reset the previous values
+          cost = previousCost;
+          for (int j = 0; j < solvedCols; ++j) {
+            int pj = permutation[j];
+            parameters[pj].setEstimate(oldX[pj]);
+          }
+          tmpVec    = residuals;
+          residuals = oldRes;
+          oldRes    = tmpVec;
+        }
+   
+        // tests for convergence.
+        if (((Math.abs(actRed) <= costRelativeTolerance)
+            && (preRed <= costRelativeTolerance)
+            && (ratio <= 2.0))
+            || (delta <= parRelativeTolerance * xNorm)) {
+          return;
+        }
+
+        // tests for termination and stringent tolerances
+        // (2.2204e-16 is the machine epsilon for IEEE754)
+        if (costEvaluations >= maxCostEval) {
+          break;
+        }
+        if ((Math.abs(actRed) <= 2.2204e-16)
+            && (preRed <= 2.2204e-16)
+            && (ratio <= 2.0)) {
+          throw new EstimationException("cost relative tolerance is too small ({0}),"
+                                      + " no further reduction in the"
+                                      + " sum of squares is possible",
+                                        new String[] {
+                                          Double.toString(costRelativeTolerance)
+                                        });
+        } else if (delta <= 2.2204e-16 * xNorm) {
+          throw new EstimationException("parameters relative tolerance is too small"
+                                      + " ({0}), no further improvement in"
+                                      + " the approximate solution is possible",
+                                        new String[] {
+                                          Double.toString(parRelativeTolerance)
+                                        });
+        } else if (maxCosine <= 2.2204e-16)  {
+          throw new EstimationException("orthogonality tolerance is too small ({0}),"
+                                      + " solution is orthogonal to the jacobian",
+                                        new String[] {
+                                          Double.toString(orthoTolerance)
+                                        });
+        }
+
+      }
+
+    }
+
+    throw new EstimationException("maximal number of evaluations exceeded ({0})",
+                                  new String[] {
+                                    Integer.toString(maxCostEval)
+                                  });
+
+  }
+
+  /** Determine the Levenberg-Marquardt parameter.
+   * <p>This implementation is a translation in Java of the MINPACK
+   * <a href="http://www.netlib.org/minpack/lmpar.f">lmpar</a>
+   * routine.</p>
+   * <p>This method sets the lmPar and lmDir attributes.</p>
+   * <p>The authors of the original fortran function are:</p>
+   * <ul>
+   *   <li>Argonne National Laboratory. MINPACK project. March 1980</li>
+   *   <li>Burton  S. Garbow</li>
+   *   <li>Kenneth E. Hillstrom</li>
+   *   <li>Jorge   J. More</li>
+   * </ul>
+   * <p>Luc Maisonobe did the Java translation.</p>
+   * @param qy array containing qTy
+   * @param delta upper bound on the euclidean norm of diagR * lmDir
+   * @param diag diagonal matrix
+   * @param work1 work array
+   * @param work2 work array
+   * @param work3 work array
+   */
+  private void determineLMParameter(double[] qy, double delta, double[] diag,
+                                    double[] work1, double[] work2, double[] work3) {
+
+    // compute and store in x the gauss-newton direction, if the
+    // jacobian is rank-deficient, obtain a least squares solution
+    for (int j = 0; j < rank; ++j) {
+      lmDir[permutation[j]] = qy[j];
+    }
+    for (int j = rank; j < cols; ++j) {
+      lmDir[permutation[j]] = 0;
+    }
+    for (int k = rank - 1; k >= 0; --k) {
+      int pk = permutation[k];
+      double ypk = lmDir[pk] / diagR[pk];
+      for (int i = 0, index = pk; i < k; ++i, index += cols) {
+        lmDir[permutation[i]] -= ypk * jacobian[index];
+      }
+      lmDir[pk] = ypk;
+    }
+
+    // evaluate the function at the origin, and test
+    // for acceptance of the Gauss-Newton direction
+    double dxNorm = 0;
+    for (int j = 0; j < solvedCols; ++j) {
+      int pj = permutation[j];
+      double s = diag[pj] * lmDir[pj];
+      work1[pj] = s;
+      dxNorm += s * s;
+    }
+    dxNorm = Math.sqrt(dxNorm);
+    double fp = dxNorm - delta;
+    if (fp <= 0.1 * delta) {
+      lmPar = 0;
+      return;
+    }
+
+    // if the jacobian is not rank deficient, the Newton step provides
+    // a lower bound, parl, for the zero of the function,
+    // otherwise set this bound to zero
+    double sum2, parl = 0;
+    if (rank == solvedCols) {
+      for (int j = 0; j < solvedCols; ++j) {
+        int pj = permutation[j];
+        work1[pj] *= diag[pj] / dxNorm; 
+      }
+      sum2 = 0;
+      for (int j = 0; j < solvedCols; ++j) {
+        int pj = permutation[j];
+        double sum = 0;
+        for (int i = 0, index = pj; i < j; ++i, index += cols) {
+          sum += jacobian[index] * work1[permutation[i]];
+        }
+        double s = (work1[pj] - sum) / diagR[pj];
+        work1[pj] = s;
+        sum2 += s * s;
+      }
+      parl = fp / (delta * sum2);
+    }
+
+    // calculate an upper bound, paru, for the zero of the function
+    sum2 = 0;
+    for (int j = 0; j < solvedCols; ++j) {
+      int pj = permutation[j];
+      double sum = 0;
+      for (int i = 0, index = pj; i <= j; ++i, index += cols) {
+        sum += jacobian[index] * qy[i];
+      }
+      sum /= diag[pj];
+      sum2 += sum * sum;
+    }
+    double gNorm = Math.sqrt(sum2);
+    double paru = gNorm / delta;
+    if (paru == 0) {
+      // 2.2251e-308 is the smallest positive real for IEE754
+      paru = 2.2251e-308 / Math.min(delta, 0.1);
+    }
+
+    // if the input par lies outside of the interval (parl,paru),
+    // set par to the closer endpoint
+    lmPar = Math.min(paru, Math.max(lmPar, parl));
+    if (lmPar == 0) {
+      lmPar = gNorm / dxNorm;
+    }
+
+    for (int countdown = 10; countdown >= 0; --countdown) {
+
+      // evaluate the function at the current value of lmPar
+      if (lmPar == 0) {
+        lmPar = Math.max(2.2251e-308, 0.001 * paru);
+      }
+      double sPar = Math.sqrt(lmPar);
+      for (int j = 0; j < solvedCols; ++j) {
+        int pj = permutation[j];
+        work1[pj] = sPar * diag[pj];
+      }
+      determineLMDirection(qy, work1, work2, work3);
+
+      dxNorm = 0;
+      for (int j = 0; j < solvedCols; ++j) {
+        int pj = permutation[j];
+        double s = diag[pj] * lmDir[pj];
+        work3[pj] = s;
+        dxNorm += s * s;
+      }
+      dxNorm = Math.sqrt(dxNorm);
+      double previousFP = fp;
+      fp = dxNorm - delta;
+
+      // if the function is small enough, accept the current value
+      // of lmPar, also test for the exceptional cases where parl is zero
+      if ((Math.abs(fp) <= 0.1 * delta)
+          || ((parl == 0) && (fp <= previousFP) && (previousFP < 0))) {
+        return;
+      }
+ 
+      // compute the Newton correction
+      for (int j = 0; j < solvedCols; ++j) {
+       int pj = permutation[j];
+        work1[pj] = work3[pj] * diag[pj] / dxNorm; 
+      }
+      for (int j = 0; j < solvedCols; ++j) {
+        int pj = permutation[j];
+        work1[pj] /= work2[j];
+        double tmp = work1[pj];
+        for (int i = j + 1; i < solvedCols; ++i) {
+          work1[permutation[i]] -= jacobian[i * cols + pj] * tmp;
+        }
+      }
+      sum2 = 0;
+      for (int j = 0; j < solvedCols; ++j) {
+        double s = work1[permutation[j]];
+        sum2 += s * s;
+      }
+      double correction = fp / (delta * sum2);
+
+      // depending on the sign of the function, update parl or paru.
+      if (fp > 0) {
+        parl = Math.max(parl, lmPar);
+      } else if (fp < 0) {
+        paru = Math.min(paru, lmPar);
+      }
+
+      // compute an improved estimate for lmPar
+      lmPar = Math.max(parl, lmPar + correction);
+
+    }
+  }
+
+  /** Solve a*x = b and d*x = 0 in the least squares sense.
+   * <p>This implementation is a translation in Java of the MINPACK
+   * <a href="http://www.netlib.org/minpack/qrsolv.f">qrsolv</a>
+   * routine.</p>
+   * <p>This method sets the lmDir and lmDiag attributes.</p>
+   * <p>The authors of the original fortran function are:</p>
+   * <ul>
+   *   <li>Argonne National Laboratory. MINPACK project. March 1980</li>
+   *   <li>Burton  S. Garbow</li>
+   *   <li>Kenneth E. Hillstrom</li>
+   *   <li>Jorge   J. More</li>
+   * </ul>
+   * <p>Luc Maisonobe did the Java translation.</p>
+   * @param qy array containing qTy
+   * @param diag diagonal matrix
+   * @param lmDiag diagonal elements associated with lmDir
+   * @param work work array
+   */
+  private void determineLMDirection(double[] qy, double[] diag,
+                                    double[] lmDiag, double[] work) {
+
+    // copy R and Qty to preserve input and initialize s
+    //  in particular, save the diagonal elements of R in lmDir
+    for (int j = 0; j < solvedCols; ++j) {
+      int pj = permutation[j];
+      for (int i = j + 1; i < solvedCols; ++i) {
+        jacobian[i * cols + pj] = jacobian[j * cols + permutation[i]];
+      }
+      lmDir[j] = diagR[pj];
+      work[j]  = qy[j];
+    }
+
+    // eliminate the diagonal matrix d using a Givens rotation
+    for (int j = 0; j < solvedCols; ++j) {
+
+      // prepare the row of d to be eliminated, locating the
+      // diagonal element using p from the Q.R. factorization
+      int pj = permutation[j];
+      double dpj = diag[pj];
+      if (dpj != 0) {
+        Arrays.fill(lmDiag, j + 1, lmDiag.length, 0);
+      }
+      lmDiag[j] = dpj;
+
+      //  the transformations to eliminate the row of d
+      // modify only a single element of Qty
+      // beyond the first n, which is initially zero.
+      double qtbpj = 0;
+      for (int k = j; k < solvedCols; ++k) {
+        int pk = permutation[k];
+
+        // determine a Givens rotation which eliminates the
+        // appropriate element in the current row of d
+        if (lmDiag[k] != 0) {
+
+          double sin, cos;
+          double rkk = jacobian[k * cols + pk];
+          if (Math.abs(rkk) < Math.abs(lmDiag[k])) {
+            double cotan = rkk / lmDiag[k];
+            sin   = 1.0 / Math.sqrt(1.0 + cotan * cotan);
+            cos   = sin * cotan;
+          } else {
+            double tan = lmDiag[k] / rkk;
+            cos = 1.0 / Math.sqrt(1.0 + tan * tan);
+            sin = cos * tan;
+          }
+
+          // compute the modified diagonal element of R and
+          // the modified element of (Qty,0)
+          jacobian[k * cols + pk] = cos * rkk + sin * lmDiag[k];
+          double temp = cos * work[k] + sin * qtbpj;
+          qtbpj = -sin * work[k] + cos * qtbpj;
+          work[k] = temp;
+
+          // accumulate the tranformation in the row of s
+          for (int i = k + 1; i < solvedCols; ++i) {
+            double rik = jacobian[i * cols + pk];
+            temp = cos * rik + sin * lmDiag[i];
+            lmDiag[i] = -sin * rik + cos * lmDiag[i];
+            jacobian[i * cols + pk] = temp;
+          }
+
+        }
+      }
+
+      // store the diagonal element of s and restore
+      // the corresponding diagonal element of R
+      int index = j * cols + permutation[j];
+      lmDiag[j]       = jacobian[index];
+      jacobian[index] = lmDir[j];
+
+    }
+
+    // solve the triangular system for z, if the system is
+    // singular, then obtain a least squares solution
+    int nSing = solvedCols;
+    for (int j = 0; j < solvedCols; ++j) {
+      if ((lmDiag[j] == 0) && (nSing == solvedCols)) {
+        nSing = j;
+      }
+      if (nSing < solvedCols) {
+        work[j] = 0;
+      }
+    }
+    if (nSing > 0) {
+      for (int j = nSing - 1; j >= 0; --j) {
+        int pj = permutation[j];
+        double sum = 0;
+        for (int i = j + 1; i < nSing; ++i) {
+          sum += jacobian[i * cols + pj] * work[i];
+        }
+        work[j] = (work[j] - sum) / lmDiag[j];
+      }
+    }
+
+    // permute the components of z back to components of lmDir
+    for (int j = 0; j < lmDir.length; ++j) {
+      lmDir[permutation[j]] = work[j];
+    }
+
+  }
+
+  /** Decompose a matrix A as A.P = Q.R using Householder transforms.
+   * <p>As suggested in the P. Lascaux and R. Theodor book
+   * <i>Analyse num&eacute;rique matricielle appliqu&eacute;e &agrave;
+   * l'art de l'ing&eacute;nieur</i> (Masson, 1986), instead of representing
+   * the Householder transforms with u<sub>k</sub> unit vectors such that:
+   * <pre>
+   * H<sub>k</sub> = I - 2u<sub>k</sub>.u<sub>k</sub><sup>t</sup>
+   * </pre>
+   * we use <sub>k</sub> non-unit vectors such that:
+   * <pre>
+   * H<sub>k</sub> = I - beta<sub>k</sub>v<sub>k</sub>.v<sub>k</sub><sup>t</sup>
+   * </pre>
+   * where v<sub>k</sub> = a<sub>k</sub> - alpha<sub>k</sub> e<sub>k</sub>.
+   * The beta<sub>k</sub> coefficients are provided upon exit as recomputing
+   * them from the v<sub>k</sub> vectors would be costly.</p>
+   * <p>This decomposition handles rank deficient cases since the tranformations
+   * are performed in non-increasing columns norms order thanks to columns
+   * pivoting. The diagonal elements of the R matrix are therefore also in
+   * non-increasing absolute values order.</p>
+   */
+  private void qrDecomposition() {
+
+    // initializations
+    for (int k = 0; k < cols; ++k) {
+      permutation[k] = k;
+      double norm2 = 0;
+      for (int index = k; index < jacobian.length; index += cols) {
+        double akk = jacobian[index];
+        norm2 += akk * akk;
+      }
+      jacNorm[k] = Math.sqrt(norm2);
+    }
+
+    // transform the matrix column after column
+    for (int k = 0; k < cols; ++k) {
+
+      // select the column with the greatest norm on active components
+      int nextColumn = -1;
+      double ak2 = Double.NEGATIVE_INFINITY;
+      for (int i = k; i < cols; ++i) {
+        double norm2 = 0;
+        int iDiag = k * cols + permutation[i];
+        for (int index = iDiag; index < jacobian.length; index += cols) {
+          double aki = jacobian[index];
+          norm2 += aki * aki;
+        }
+        if (norm2 > ak2) {
+          nextColumn = i;
+          ak2        = norm2;
+        }
+      }
+      if (ak2 == 0) {
+        rank = k;
+        return;
+      }
+      int pk                  = permutation[nextColumn];
+      permutation[nextColumn] = permutation[k];
+      permutation[k]          = pk;
+
+      // choose alpha such that Hk.u = alpha ek
+      int    kDiag = k * cols + pk;
+      double akk   = jacobian[kDiag];
+      double alpha = (akk > 0) ? -Math.sqrt(ak2) : Math.sqrt(ak2);
+      double betak = 1.0 / (ak2 - akk * alpha);
+      beta[pk]     = betak;
+
+      // transform the current column
+      diagR[pk]        = alpha;
+      jacobian[kDiag] -= alpha;
+
+      // transform the remaining columns
+      for (int dk = cols - 1 - k; dk > 0; --dk) {
+        int dkp = permutation[k + dk] - pk;
+        double gamma = 0;
+        for (int index = kDiag; index < jacobian.length; index += cols) {
+          gamma += jacobian[index] * jacobian[index + dkp];
+        }
+        gamma *= betak;
+        for (int index = kDiag; index < jacobian.length; index += cols) {
+          jacobian[index + dkp] -= gamma * jacobian[index];
+        }
+      }
+
+    }
+
+    rank = solvedCols;
+
+  }
+
+  /** Compute the product Qt.y for some Q.R. decomposition.
+   * @param y vector to multiply (will be overwritten with the result)
+   */
+  private void qTy(double[] y) {
+    for (int k = 0; k < cols; ++k) {
+      int pk = permutation[k];
+      int kDiag = k * cols + pk;
+      double gamma = 0;
+      for (int i = k, index = kDiag; i < rows; ++i, index += cols) {
+        gamma += jacobian[index] * y[i];
+      }
+      gamma *= beta[pk];
+      for (int i = k, index = kDiag; i < rows; ++i, index += cols) {
+        y[i] -= gamma * jacobian[index];
+      }
+    }
+  }
+
+  /** Array of measurements. */
+  private WeightedMeasurement[] measurements;
+
+  /** Array of parameters. */
+  private EstimatedParameter[] parameters;
+
+  /** Jacobian matrix.
+   * <p>Depending on the computation phase, this matrix is either in
+   * canonical form (just after the calls to updateJacobian) or in
+   * Q.R. decomposed form (after calls to qrDecomposition)</p>
+   */
+  private double[] jacobian;
+
+  /** Number of columns of the jacobian matrix. */
+  private int cols;
+
+  /** Number of solved variables. */
+  private int solvedCols;
+
+  /** Number of rows of the jacobian matrix. */
+  private int rows;
+
+  /** Diagonal elements of the R matrix in the Q.R. decomposition. */
+  private double[] diagR;
+
+  /** Norms of the columns of the jacobian matrix. */
+  private double[] jacNorm;
+
+  /** Coefficients of the Householder transforms vectors. */
+  private double[] beta;
+
+  /** Columns permutation array. */
+  private int[] permutation;
+
+  /** Rank of the jacobian matrix. */
+  private int rank;
+
+  /** Levenberg-Marquardt parameter. */
+  private double lmPar;
+
+  /** Parameters evolution direction associated with lmPar. */
+  private double[] lmDir;
+
+  /** Residuals array.
+   * <p>Depending on the computation phase, this array is either in
+   * canonical form (just after the calls to updateResiduals) or in
+   * premultiplied by Qt form (just after calls to qTy)</p>
+   */
+  private double[] residuals;
+
+  /** Cost value (square root of the sum of the residuals). */
+  private double cost;
+
+  /** Positive input variable used in determining the initial step bound. */
+  private double initialStepBoundFactor;
+
+  /** Maximal number of cost evaluations. */
+  private int maxCostEval;
+
+  /** Number of cost evaluations. */
+  private int costEvaluations;
+
+  /** Number of jacobian evaluations. */
+  private int jacobianEvaluations;
+
+  /** Desired relative error in the sum of squares. */
+  private double costRelativeTolerance;
+
+  /**  Desired relative error in the approximate solution parameters. */
+  private double parRelativeTolerance;
+
+  /** Desired max cosine on the orthogonality between the function vector
+   * and the columns of the jacobian. */
+  private double orthoTolerance;
+
+  private static final long serialVersionUID = 5387476316105068340L;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/LevenbergMarquardtEstimator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java Mon Feb 26 14:59:45 2007
@@ -0,0 +1,143 @@
+// 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.estimation;
+
+import java.io.Serializable;
+
+/** This class represents measurements in estimation problems.
+
+ * <p>This abstract class implements all the methods needed to handle
+ * measurements in a general way. It defines neither the {@link
+ * #getTheoreticalValue getTheoreticalValue} nor the {@link
+ * #getPartial getPartial} methods, which should be defined by
+ * sub-classes according to the specific problem.</p>
+
+ * <p>The {@link #getTheoreticalValue getTheoreticalValue} and {@link
+ * #getPartial getPartial} methods must always use the current
+ * estimate of the parameters set by the solver in the problem. These
+ * parameters can be retrieved through the {@link
+ * EstimationProblem#getAllParameters
+ * EstimationProblem.getAllParameters} method if the measurements are
+ * independant of the problem, or directly if they are implemented as
+ * inner classes of the problem.</p>
+
+ * <p>The instances for which the <code>ignored</code> flag is set
+ * through the {@link #setIgnored setIgnored} method are ignored by the
+ * solvers. This can be used to reject wrong measurements at some
+ * steps of the estimation.</p>
+
+ * @see EstimationProblem
+
+ * @version $Id: WeightedMeasurement.java 1705 2006-09-17 19:57:39Z luc $
+ * @author L. Maisonobe
+
+ */
+
+public abstract class WeightedMeasurement implements Serializable {
+
+  /** Simple constructor.
+   * Build a measurement with the given parameters, and set its ignore
+   * flag to false.
+   * @param weight weight of the measurement in the least squares problem
+   * (two common choices are either to use 1.0 for all measurements, or to
+   * use a value proportional to the inverse of the variance of the measurement
+   * type)
+   * @param measuredValue measured value
+   */
+  public WeightedMeasurement(double weight, double measuredValue) {
+    this.weight        = weight;
+    this.measuredValue = measuredValue;
+    ignored            = false;
+  }
+
+  /** Simple constructor.
+   * Build a measurement with the given parameters
+   * @param weight weight of the measurement in the least squares problem
+   * @param measuredValue measured value
+   * @param ignored true if the measurement should be ignored
+   */
+  public WeightedMeasurement(double weight, double measuredValue,
+                             boolean ignored) {
+    this.weight        = weight;
+    this.measuredValue = measuredValue;
+    this.ignored       = ignored;
+  }
+
+  /** Get the weight of the measurement in the least squares problem
+   * @return weight
+   */
+  public double getWeight() {
+    return weight;
+  }
+
+  /** Get the measured value
+   * @return measured value
+   */
+  public double getMeasuredValue() {
+    return measuredValue;
+  }
+
+  /** Get the residual for this measurement
+   * The residual is the measured value minus the theoretical value.
+   * @return residual
+   */
+  public double getResidual() {
+    return measuredValue - getTheoreticalValue();
+  }
+
+  /** Get the theoretical value expected for this measurement
+   * <p>The theoretical value is the value expected for this measurement
+   * if the model and its parameter were all perfectly known.</p>
+   * <p>The value must be computed using the current estimate of the parameters
+   * set by the solver in the problem.</p>
+   * @return theoretical value
+   */
+  public abstract double getTheoreticalValue();
+
+  /** Get the partial derivative of the {@link #getTheoreticalValue
+   * theoretical value} according to the parameter.
+   * <p>The value must be computed using the current estimate of the parameters
+   * set by the solver in the problem.</p>
+   * @param parameter parameter against which the partial derivative
+   * should be computed
+   * @return partial derivative of the {@link #getTheoreticalValue
+   * theoretical value}
+   */
+  public abstract double getPartial(EstimatedParameter parameter);
+
+  /** Set the ignore flag to the specified value
+   * Setting the ignore flag to true allow to reject wrong
+   * measurements, which sometimes can be detected only rather late.
+   * @param ignored value for the ignore flag
+   */
+  public void setIgnored(boolean ignored) {
+    this.ignored = ignored;
+  }
+
+  /** Check if this measurement should be ignored
+   * @return true if the measurement should be ignored
+   */
+  public boolean isIgnored() {
+    return ignored;
+  }
+
+  private final double  weight;
+  private final double  measuredValue;
+  private       boolean ignored;
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/WeightedMeasurement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html?view=auto&rev=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html (added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html Mon Feb 26 14:59:45 2007
@@ -0,0 +1,52 @@
+<html>
+<body>
+This package provides classes to solve estimation problems.
+
+<p>The estimation problems considered here are parametric problems where a user model
+depends on initially unknown scalar parameters and several measurements made on
+values that depend on the model are available. As an example, one can consider the
+flow rate of a river given rain data on its vicinity, or the center and radius of a
+circle given points on a ring.</p>
+
+<p>One important class of estimation problems is weighted least squares problems.
+They basically consist in finding the values for some parameters p<sub>k</sub> such
+that a cost function J = sum(w<sub>i</sub> r<sub>i</sub><sup>2</sup>) is minimized.
+The various r<sub>i</sub> terms represent the deviation r<sub>i</sub> =
+mes<sub>i</sub> - mod<sub>i</sub> between the measurements and the parameterized
+models. The w<sub>i</sub> factors are the measurements weights, they are often chosen
+either all equal to 1.0 or proportional to the inverse of the variance of the
+measurement type. The solver adjusts the values of the estimated parameters
+p<sub>k</sub> which are not bound. It does not touch the parameters which have been
+put in a bound state by the user.</p>
+ 
+<p>This package provides the {@link
+org.spaceroots.mantissa.estimation.EstimatedParameter EstimatedParameter} class to
+represent each estimated parameter, and the {@link
+org.spaceroots.mantissa.estimation.WeightedMeasurement WeightedMeasurement} abstract
+class the user can extend to define its measurements. All parameters and measurements
+are then provided to some {@link org.spaceroots.mantissa.estimation.Estimator
+Estimator} packed together in an {@link
+org.spaceroots.mantissa.estimation.EstimationProblem EstimationProblem} instance
+which acts only as a container. The package provides two common estimators for
+weighted least squares problems, one based on the {@link
+org.spaceroots.mantissa.estimation.GaussNewtonEstimator Gauss-Newton} method and the
+other one based on the {@link
+org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator Levenberg-Marquardt}
+method.</p>
+
+<p>The class diagram for the public classes of this package is displayed below. The
+orange boxes <code>UserProblem</code>, <code>UserFirstMeasurementType</code> and
+<code>UserSecondMeasurementType</code> are exemple of what the user should create to
+use this package: implement his own problem and measurement types using the {@link
+org.spaceroots.mantissa.estimation.EstimationProblem} interface and {@link
+org.spaceroots.mantissa.estimation.WeightedMeasurement} abstract class, and then use
+one of the provided estimators (for example {@link
+org.spaceroots.mantissa.estimation.GaussNewtonEstimator} or {@link
+org.spaceroots.mantissa.estimation.LevenbergMarquardtEstimator}) to solve it. The
+white boxes are the interfaces and classes already provided by the library.</p>
+
+<img src="doc-files/org_spaceroots_mantissa_estimation_classes.png" />
+
+@author L. Maisonobe
+</body>
+</html>
\ No newline at end of file

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/estimation/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java (from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/EstimatedParameterTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java?view=diff&rev=512061&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/EstimatedParameterTest.java&r1=512056&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java&r2=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/EstimatedParameterTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/EstimatedParameterTest.java Mon Feb 26 14:59:45 2007
@@ -15,7 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.estimation;
+package org.apache.commons.math.estimation;
+
+import org.apache.commons.math.estimation.EstimatedParameter;
 
 import junit.framework.*;
 

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java (from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/LevenbergMarquardtEstimatorTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java?view=diff&rev=512061&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/LevenbergMarquardtEstimatorTest.java&r1=512056&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java&r2=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/LevenbergMarquardtEstimatorTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/LevenbergMarquardtEstimatorTest.java Mon Feb 26 14:59:45 2007
@@ -15,13 +15,19 @@
  * limitations under the License.
  */
 
-package org.spaceroots.mantissa.estimation;
+package org.apache.commons.math.estimation;
 
 import java.util.ArrayList;
-import java.util.IdentityHashMap;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Set;
 
+import org.apache.commons.math.estimation.EstimatedParameter;
+import org.apache.commons.math.estimation.EstimationException;
+import org.apache.commons.math.estimation.EstimationProblem;
+import org.apache.commons.math.estimation.LevenbergMarquardtEstimator;
+import org.apache.commons.math.estimation.WeightedMeasurement;
+
 import junit.framework.*;
 
 /**
@@ -519,7 +525,7 @@
     }
 
     public EstimatedParameter[] getAllParameters() {
-      IdentityHashMap map = new IdentityHashMap();
+      HashMap map = new HashMap();
       for (int i = 0; i < measurements.length; ++i) {
         EstimatedParameter[] parameters = measurements[i].getParameters();
         for (int j = 0; j < parameters.length; ++j) {

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java (from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/MinpackTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java?view=diff&rev=512061&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/MinpackTest.java&r1=512056&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java&r2=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/MinpackTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/MinpackTest.java Mon Feb 26 14:59:45 2007
@@ -1,6 +1,12 @@
-package org.spaceroots.mantissa.estimation;
+package org.apache.commons.math.estimation;
 
 import java.util.Arrays;
+
+import org.apache.commons.math.estimation.EstimatedParameter;
+import org.apache.commons.math.estimation.EstimationException;
+import org.apache.commons.math.estimation.EstimationProblem;
+import org.apache.commons.math.estimation.LevenbergMarquardtEstimator;
+import org.apache.commons.math.estimation.WeightedMeasurement;
 
 import junit.framework.*;
 

Copied: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java (from r512056, jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/WeightedMeasurementTest.java)
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java?view=diff&rev=512061&p1=jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/WeightedMeasurementTest.java&r1=512056&p2=jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java&r2=512061
==============================================================================
--- jakarta/commons/proper/math/trunk/src/mantissa/tests-src/org/spaceroots/mantissa/estimation/WeightedMeasurementTest.java (original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/estimation/WeightedMeasurementTest.java Mon Feb 26 14:59:45 2007
@@ -15,7 +15,10 @@
 // specific language governing permissions and limitations
 // under the License.
 
-package org.spaceroots.mantissa.estimation;
+package org.apache.commons.math.estimation;
+
+import org.apache.commons.math.estimation.EstimatedParameter;
+import org.apache.commons.math.estimation.WeightedMeasurement;
 
 import junit.framework.*;
 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org