Changed "computeWeightedJacobian" to return exactly that, instead of the
weighted Jacobian matrix multiplied by -1. Changed subclasses accordingly.


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1408250 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-11-12 11:36:40 +00:00
parent 00d309c45d
commit 6080bc88a8
3 changed files with 12 additions and 18 deletions

View File

@ -148,7 +148,8 @@ public abstract class AbstractLeastSquaresOptimizer
*/
@Deprecated
protected void updateJacobian() {
computeWeightedJacobian(point);
final RealMatrix weightedJacobian = computeWeightedJacobian(point);
weightedResidualJacobian = weightedJacobian.scalarMultiply(-1).getData();
}
/**
@ -183,15 +184,7 @@ public abstract class AbstractLeastSquaresOptimizer
}
}
// 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 AbstractLeastSquaresOptimizer
* @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 AbstractLeastSquaresOptimizer
// 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();
}

View File

@ -143,9 +143,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
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;

View File

@ -839,11 +839,14 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
* 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;