From 784e4f69ec67d511a0620a2b030688f186ebb959 Mon Sep 17 00:00:00 2001 From: Dimitri Pourbaix Date: Wed, 11 Aug 2010 13:40:39 +0000 Subject: [PATCH] MATH-405 corrected git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@984404 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractLeastSquaresOptimizer.java | 7 +-- .../general/LevenbergMarquardtOptimizer.java | 55 +++++++++++-------- .../optimization/general/MinpackTest.java | 11 ++-- 3 files changed, 39 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java index 152c30c3a..c4b19855a 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/AbstractLeastSquaresOptimizer.java @@ -247,12 +247,7 @@ public abstract class AbstractLeastSquaresOptimizer implements DifferentiableMul * @return chi-square value */ public double getChiSquare() { - double chiSquare = 0; - for (int i = 0; i < rows; ++i) { - final double residual = residuals[i]; - chiSquare += residual * residual * residualsWeights[i]; - } - return chiSquare; + return cost*cost; } /** diff --git a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java index 4cf4ee006..b41456eff 100644 --- a/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/general/LevenbergMarquardtOptimizer.java @@ -255,6 +255,8 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { double[] diag = new double[cols]; double[] oldX = new double[cols]; double[] oldRes = new double[rows]; + double[] oldObj = new double[rows]; + double[] qtf = new double[rows]; double[] work1 = new double[cols]; double[] work2 = new double[cols]; double[] work3 = new double[cols]; @@ -267,7 +269,9 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer { boolean firstIteration = true; VectorialPointValuePair current = new VectorialPointValuePair(point, objective); while (true) { - + for (int i=0;i