MATH-887
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:
parent
00d309c45d
commit
6080bc88a8
|
@ -148,7 +148,8 @@ public abstract class AbstractLeastSquaresOptimizer
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected void updateJacobian() {
|
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?
|
return weightMatrixSqrt.multiply(MatrixUtils.createRealMatrix(jacobianData));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,8 +194,8 @@ public abstract class AbstractLeastSquaresOptimizer
|
||||||
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
|
* @throws org.apache.commons.math3.exception.TooManyEvaluationsException
|
||||||
* if the maximal number of evaluations is exceeded.
|
* if the maximal number of evaluations is exceeded.
|
||||||
* @deprecated As of 3.1. Please use {@link #computeResiduals(double[])},
|
* @deprecated As of 3.1. Please use {@link #computeResiduals(double[])},
|
||||||
* {@link #computeObjectiveValue(double[])} and {@link #computeCost(double[])}
|
* {@link #computeObjectiveValue(double[])}, {@link #computeCost(double[])}
|
||||||
* instead.
|
* and {@link #setCost(double)} instead.
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
protected void updateResidualsAndCost() {
|
protected void updateResidualsAndCost() {
|
||||||
|
@ -212,7 +205,7 @@ public abstract class AbstractLeastSquaresOptimizer
|
||||||
// Compute cost.
|
// Compute cost.
|
||||||
cost = computeCost(res);
|
cost = computeCost(res);
|
||||||
|
|
||||||
// Compute weighted residuals. XXX To be moved to "LevenbergMarquardtOptimizer".
|
// Compute weighted residuals.
|
||||||
final ArrayRealVector residuals = new ArrayRealVector(res);
|
final ArrayRealVector residuals = new ArrayRealVector(res);
|
||||||
weightedResiduals = weightMatrixSqrt.operate(residuals).toArray();
|
weightedResiduals = weightMatrixSqrt.operate(residuals).toArray();
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,9 +143,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
|
|
||||||
final double[] grad = weightedJacobian.getRow(i);
|
final double[] grad = weightedJacobian.getRow(i);
|
||||||
final double weight = residualsWeights[i];
|
final double weight = residualsWeights[i];
|
||||||
// XXX Minus sign could be left out if "weightedJacobian"
|
final double residual = currentResiduals[i];
|
||||||
// would be defined differently.
|
|
||||||
final double residual = -currentResiduals[i];
|
|
||||||
|
|
||||||
// compute the normal equation
|
// compute the normal equation
|
||||||
final double wr = weight * residual;
|
final double wr = weight * residual;
|
||||||
|
|
|
@ -839,11 +839,14 @@ public class LevenbergMarquardtOptimizer extends AbstractLeastSquaresOptimizer {
|
||||||
* pivoting. The diagonal elements of the R matrix are therefore also in
|
* pivoting. The diagonal elements of the R matrix are therefore also in
|
||||||
* non-increasing absolute values order.</p>
|
* 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
|
* @exception ConvergenceException if the decomposition cannot be performed
|
||||||
*/
|
*/
|
||||||
private void qrDecomposition(RealMatrix jacobian) throws ConvergenceException {
|
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 nR = weightedJacobian.length;
|
||||||
final int nC = weightedJacobian[0].length;
|
final int nC = weightedJacobian[0].length;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue