diff --git a/src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java b/src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java index 6ee88f664..bc4503c32 100644 --- a/src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java +++ b/src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java @@ -230,6 +230,7 @@ public class GaussNewtonOptimizer implements LeastSquaresOptimizer { current = lsp.evaluate(currentPoint); final RealVector currentResiduals = current.getResiduals(); final RealMatrix weightedJacobian = current.getJacobian(); + currentPoint = current.getPoint(); // Check convergence. if (previous != null) { diff --git a/src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java b/src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java index dac53d215..358d24019 100644 --- a/src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java +++ b/src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java @@ -294,16 +294,14 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { /** {@inheritDoc} */ public Optimum optimize(final LeastSquaresProblem problem) { - //pull in relevant data from the problem as locals + // Pull in relevant data from the problem as locals. final int nR = problem.getObservationSize(); // Number of observed data. final int nC = problem.getParameterSize(); // Number of parameters. - final double[] currentPoint = problem.getStart().toArray(); - //counters + // Counters. final Incrementor iterationCounter = problem.getIterationCounter(); final Incrementor evaluationCounter = problem.getEvaluationCounter(); - //convergence criterion - final ConvergenceChecker checker - = problem.getConvergenceChecker(); + // Convergence criterion. + final ConvergenceChecker checker = problem.getConvergenceChecker(); // arrays shared with the other private methods final int solvedCols = FastMath.min(nR, nC); @@ -327,9 +325,10 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { // Evaluate the function at the starting point and calculate its norm. evaluationCounter.incrementCount(); //value will be reassigned in the loop - Evaluation current = problem.evaluate(new ArrayRealVector(currentPoint)); + Evaluation current = problem.evaluate(problem.getStart()); double[] currentResiduals = current.getResiduals().toArray(); double currentCost = current.getCost(); + double[] currentPoint = current.getPoint().toArray(); // Outer loop. boolean firstIteration = true; @@ -447,6 +446,7 @@ public class LevenbergMarquardtOptimizer implements LeastSquaresOptimizer { current = problem.evaluate(new ArrayRealVector(currentPoint)); currentResiduals = current.getResiduals().toArray(); currentCost = current.getCost(); + currentPoint = current.getPoint().toArray(); // compute the scaled actual reduction double actRed = -1.0; diff --git a/src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java b/src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java index b6373d416..c6910fff7 100644 --- a/src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java +++ b/src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java @@ -307,6 +307,7 @@ public class LevenbergMarquardtOptimizerTest = optimizer.optimize(builder(circle).maxIterations(50).start(init).parameterValidator(cheatValidator).build()); final int cheatNumEval = cheatOptimum.getEvaluations(); Assert.assertTrue(cheatNumEval < numEval); + System.out.println("n=" + numEval + " nc=" + cheatNumEval); } @Test