You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/06/28 12:20:21 UTC

svn commit: r1497713 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java

Author: erans
Date: Fri Jun 28 10:20:21 2013
New Revision: 1497713

URL: http://svn.apache.org/r1497713
Log:
MATH-993
Moved convergence check block to allow returning before an exception
would be raised.

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1497713&r1=1497712&r2=1497713&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Fri Jun 28 10:20:21 2013
@@ -51,6 +51,10 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="x.y" date="TBD" description="TBD">
+      <action dev="erans" type="fix" issue="MATH-993">
+        In "GaussNewtonOptimizer", check for convergence before updating the
+        parameters estimation for the next iteration.
+      </action>
       <action dev="luc" type="add" issue="MATH-967" due-to="Oleksandr Kornieiev">
         Added midpoint integration method.
       </action>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java?rev=1497713&r1=1497712&r2=1497713&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optim/nonlinear/vector/jacobian/GaussNewtonOptimizer.java Fri Jun 28 10:20:21 2013
@@ -139,6 +139,15 @@ public class GaussNewtonOptimizer extend
                 }
             }
 
+            // Check convergence.
+            if (previous != null) {
+                converged = checker.converged(getIterations(), previous, current);
+                if (converged) {
+                    setCost(computeCost(currentResiduals));
+                    return current;
+                }
+            }
+
             try {
                 // solve the linearized least squares problem
                 RealMatrix mA = new BlockRealMatrix(a);
@@ -153,15 +162,6 @@ public class GaussNewtonOptimizer extend
             } catch (SingularMatrixException e) {
                 throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM);
             }
-
-            // Check convergence.
-            if (previous != null) {
-                converged = checker.converged(getIterations(), previous, current);
-                if (converged) {
-                    setCost(computeCost(currentResiduals));
-                    return current;
-                }
-            }
         }
         // Must never happen.
         throw new MathInternalError();