commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [4/8] git commit: MATH-1144 Point must be retrieved after the call to "evaluate" (to ensure that the validated parameters are actually used by the optimizer).
Date Mon, 03 Nov 2014 10:43:38 GMT
MATH-1144
Point must be retrieved after the call to "evaluate" (to ensure that
the validated parameters are actually used by the optimizer).


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/566c4d59
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/566c4d59
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/566c4d59

Branch: refs/heads/master
Commit: 566c4d59a177be4b65d17540576eeb34d28d24ce
Parents: 4c5cda2
Author: Gilles <erans@apache.org>
Authored: Wed Oct 15 22:14:46 2014 +0200
Committer: Gilles <erans@apache.org>
Committed: Wed Oct 15 22:14:46 2014 +0200

----------------------------------------------------------------------
 .../fitting/leastsquares/GaussNewtonOptimizer.java    |  1 +
 .../leastsquares/LevenbergMarquardtOptimizer.java     | 14 +++++++-------
 .../leastsquares/LevenbergMarquardtOptimizerTest.java |  1 +
 3 files changed, 9 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/566c4d59/src/main/java/org/apache/commons/math3/fitting/leastsquares/GaussNewtonOptimizer.java
----------------------------------------------------------------------
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 6ee88f6..bc4503c 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) {

http://git-wip-us.apache.org/repos/asf/commons-math/blob/566c4d59/src/main/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizer.java
----------------------------------------------------------------------
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 dac53d2..358d240 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<Evaluation> checker
-                = problem.getConvergenceChecker();
+        // Convergence criterion.
+        final ConvergenceChecker<Evaluation> 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;

http://git-wip-us.apache.org/repos/asf/commons-math/blob/566c4d59/src/test/java/org/apache/commons/math3/fitting/leastsquares/LevenbergMarquardtOptimizerTest.java
----------------------------------------------------------------------
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 b6373d4..c6910ff 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


Mime
View raw message