Moved convergence check block to allow returning before an exception
would be raised.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1497713 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2013-06-28 10:20:21 +00:00
parent 1e6e14cb5f
commit 74e699d076
2 changed files with 13 additions and 9 deletions

View File

@ -51,6 +51,10 @@ If the output is not quite correct, check for invisible trailing spaces!
</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>

View File

@ -139,6 +139,15 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
}
}
// 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 extends AbstractLeastSquaresOptimizer {
} 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();