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 2012/11/12 12:36:41 UTC
svn commit: r1408250 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general:
AbstractLeastSquaresOptimizer.java GaussNewtonOptimizer.java
LevenbergMarquardtOptimizer.java
Author: erans
Date: Mon Nov 12 11:36:40 2012
New Revision: 1408250
URL: http://svn.apache.org/viewvc?rev=1408250&view=rev
Log:
MATH-887
Changed "computeWeightedJacobian" to return exactly that, instead of the
weighted Jacobian matrix multiplied by -1. Changed subclasses accordingly.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java?rev=1408250&r1=1408249&r2=1408250&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/AbstractLeastSquaresOptimizer.java Mon Nov 12 11:36:40 2012
@@ -148,7 +148,8 @@ public abstract class AbstractLeastSquar
*/
@Deprecated
protected void updateJacobian() {
- computeWeightedJacobian(point);
+ final RealMatrix weightedJacobian = computeWeightedJacobian(point);
+ weightedResidualJacobian = weightedJacobian.scalarMultiply(-1).getData();
}
/**
@@ -183,15 +184,7 @@ public abstract class AbstractLeastSquar
}
}
- // XXX What is the purpose of the multiplication by -1?
- final RealMatrix weightedJacobian
- = weightMatrixSqrt.multiply(MatrixUtils.createRealMatrix(jacobianData)).scalarMultiply(-1);
-
- // XXX For backwards-compatibility (field "weightedResidualJacobian"
- // must be removed in 4.0).
- weightedResidualJacobian = weightedJacobian.getData();
-
- return weightedJacobian;
+ return weightMatrixSqrt.multiply(MatrixUtils.createRealMatrix(jacobianData));
}
/**
@@ -201,8 +194,8 @@ public abstract class AbstractLeastSquar
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
* if the maximal number of evaluations is exceeded.
* @deprecated As of 3.1. Please use {@link #computeResiduals(double[])},
- * {@link #computeObjectiveValue(double[])} and {@link #computeCost(double[])}
- * instead.
+ * {@link #computeObjectiveValue(double[])}, {@link #computeCost(double[])}
+ * and {@link #setCost(double)} instead.
*/
@Deprecated
protected void updateResidualsAndCost() {
@@ -212,7 +205,7 @@ public abstract class AbstractLeastSquar
// Compute cost.
cost = computeCost(res);
- // Compute weighted residuals. XXX To be moved to "LevenbergMarquardtOptimizer".
+ // Compute weighted residuals.
final ArrayRealVector residuals = new ArrayRealVector(res);
weightedResiduals = weightMatrixSqrt.operate(residuals).toArray();
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizer.java?rev=1408250&r1=1408249&r2=1408250&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/GaussNewtonOptimizer.java Mon Nov 12 11:36:40 2012
@@ -143,9 +143,7 @@ public class GaussNewtonOptimizer extend
final double[] grad = weightedJacobian.getRow(i);
final double weight = residualsWeights[i];
- // XXX Minus sign could be left out if "weightedJacobian"
- // would be defined differently.
- final double residual = -currentResiduals[i];
+ final double residual = currentResiduals[i];
// compute the normal equation
final double wr = weight * residual;
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.java?rev=1408250&r1=1408249&r2=1408250&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.java Mon Nov 12 11:36:40 2012
@@ -839,11 +839,14 @@ public class LevenbergMarquardtOptimizer
* pivoting. The diagonal elements of the R matrix are therefore also in
* non-increasing absolute values order.</p>
*
- * @param jacobian Weighte Jacobian matrix at the current point.
+ * @param jacobian Weighted Jacobian matrix at the current point.
* @exception ConvergenceException if the decomposition cannot be performed
*/
private void qrDecomposition(RealMatrix jacobian) throws ConvergenceException {
- weightedJacobian = jacobian.getData();
+ // Code in this class assumes that the weighted Jacobian is -(W^(1/2) J),
+ // hence the multiplication by -1.
+ weightedJacobian = jacobian.scalarMultiply(-1).getData();
+
final int nR = weightedJacobian.length;
final int nC = weightedJacobian[0].length;