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 2014/02/18 15:33:00 UTC

svn commit: r1569355 - /commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java

Author: luc
Date: Tue Feb 18 14:33:00 2014
New Revision: 1569355

URL: http://svn.apache.org/r1569355
Log:
Clean up LeastSquaresFactory

* There are now 3 factory methods: one using the previous interfaces, one using
  the new interfaces with weights, and one using the new interfaces without
  weights.

* Make model(...) method public.

* Fix javadoc typo

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java?rev=1569355&r1=1569354&r2=1569355&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/fitting/leastsquares/LeastSquaresFactory.java Tue Feb 18 14:33:00 2014
@@ -56,40 +56,50 @@ public class LeastSquaresFactory {
 
     /**
      * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem}
-     * from the given elements. There will be no weights applied (Identity weights).
+     * from the given elements.
      *
      * @param model          the model function. Produces the computed values.
      * @param observed       the observed (target) values
      * @param start          the initial guess.
+     * @param weight         the weight matrix
      * @param checker        convergence checker
      * @param maxEvaluations the maximum number of times to evaluate the model
      * @param maxIterations  the maximum number to times to iterate in the algorithm
      * @return the specified General Least Squares problem.
      */
     public static LeastSquaresProblem create(final MultivariateJacobianFunction model,
-                                             final double[] observed,
-                                             final double[] start,
+                                             final RealVector observed,
+                                             final RealVector start,
+                                             final RealMatrix weight,
                                              final ConvergenceChecker<Evaluation> checker,
                                              final int maxEvaluations,
                                              final int maxIterations) {
-        return create(
-                model,
-                new ArrayRealVector(observed, false),
-                new ArrayRealVector(start, false),
-                checker,
-                maxEvaluations,
-                maxIterations
-        );
+        return weightMatrix(
+                create(
+                        model,
+                        observed,
+                        start,
+                        checker,
+                        maxEvaluations,
+                        maxIterations
+                ),
+                weight);
     }
 
     /**
      * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem}
-     * from the given elements. There will be no weights applied (Identity weights).
+     * from the given elements.
+     * <p/>
+     * This factory method is provided for continuity with previous interfaces. Newer
+     * applications should use {@link #create(MultivariateJacobianFunction, RealVector,
+     * RealVector, ConvergenceChecker, int, int)}, or {@link #create(MultivariateJacobianFunction,
+     * RealVector, RealVector, RealMatrix, ConvergenceChecker, int, int)}.
      *
      * @param model          the model function. Produces the computed values.
      * @param jacobian       the jacobian of the model with respect to the parameters
      * @param observed       the observed (target) values
      * @param start          the initial guess.
+     * @param weight         the weight matrix
      * @param checker        convergence checker
      * @param maxEvaluations the maximum number of times to evaluate the model
      * @param maxIterations  the maximum number to times to iterate in the algorithm
@@ -99,13 +109,15 @@ public class LeastSquaresFactory {
                                              final MultivariateMatrixFunction jacobian,
                                              final double[] observed,
                                              final double[] start,
+                                             final RealMatrix weight,
                                              final ConvergenceChecker<Evaluation> checker,
                                              final int maxEvaluations,
                                              final int maxIterations) {
         return create(
-                combine(model, jacobian),
-                observed,
-                start,
+                model(model, jacobian),
+                new ArrayRealVector(observed, false),
+                new ArrayRealVector(start, false),
+                weight,
                 checker,
                 maxEvaluations,
                 maxIterations
@@ -113,41 +125,6 @@ public class LeastSquaresFactory {
     }
 
     /**
-     * Create a {@link org.apache.commons.math3.fitting.leastsquares.LeastSquaresProblem}
-     * from the given elements.
-     *
-     * @param model          the model function. Produces the computed values.
-     * @param jacobian       the jacobian of the model with respect to the parameters
-     * @param observed       the observed (target) values
-     * @param start          the initial guess.
-     * @param weight         the weight matrix
-     * @param checker        convergence checker
-     * @param maxEvaluations the maximum number of times to evaluate the model
-     * @param maxIterations  the maximum number to times to iterate in the algorithm
-     * @return the specified General Least Squares problem.
-     */
-    public static LeastSquaresProblem create(final MultivariateVectorFunction model,
-                                             final MultivariateMatrixFunction jacobian,
-                                             final double[] observed,
-                                             final double[] start,
-                                             final RealMatrix weight,
-                                             final ConvergenceChecker<Evaluation> checker,
-                                             final int maxEvaluations,
-                                             final int maxIterations) {
-        return weightMatrix(
-                create(
-                        model,
-                        jacobian,
-                        observed,
-                        start,
-                        checker,
-                        maxEvaluations,
-                        maxIterations
-                ),
-                weight);
-    }
-
-    /**
      * Apply a dense weight matrix to the {@link LeastSquaresProblem}.
      *
      * @param problem the unweighted problem
@@ -167,7 +144,7 @@ public class LeastSquaresFactory {
     }
 
     /**
-     * Apply a diagon weight matrix to the {@link LeastSquaresProblem}.
+     * Apply a diagonal weight matrix to the {@link LeastSquaresProblem}.
      *
      * @param problem the unweighted problem
      * @param weights the diagonal of the weight matrix
@@ -260,7 +237,7 @@ public class LeastSquaresFactory {
      * @param jacobian the Jacobian function
      * @return a function that computes both at the same time
      */
-    private static MultivariateJacobianFunction combine(
+    public static MultivariateJacobianFunction model(
             final MultivariateVectorFunction value,
             final MultivariateMatrixFunction jacobian
     ) {