Removed usage of "protected" fields "cols" and "rows".


git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1407501 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gilles Sadowski 2012-11-09 15:48:56 +00:00
parent 4ece62e101
commit b76ce72cf0
1 changed files with 8 additions and 7 deletions

View File

@ -120,6 +120,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
} }
final double[] currentPoint = getStartPoint(); final double[] currentPoint = getStartPoint();
final int nC = currentPoint.length;
// iterate until convergence is reached // iterate until convergence is reached
PointVectorValuePair current = null; PointVectorValuePair current = null;
@ -136,9 +137,9 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
current = new PointVectorValuePair(currentPoint, currentObjective); current = new PointVectorValuePair(currentPoint, currentObjective);
// build the linear problem // build the linear problem
final double[] b = new double[cols]; final double[] b = new double[nC];
final double[][] a = new double[cols][cols]; final double[][] a = new double[nC][nC];
for (int i = 0; i < rows; ++i) { for (int i = 0; i < nR; ++i) {
final double[] grad = weightedJacobian.getRow(i); final double[] grad = weightedJacobian.getRow(i);
final double weight = residualsWeights[i]; final double weight = residualsWeights[i];
@ -148,15 +149,15 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
// compute the normal equation // compute the normal equation
final double wr = weight * residual; final double wr = weight * residual;
for (int j = 0; j < cols; ++j) { for (int j = 0; j < nC; ++j) {
b[j] += wr * grad[j]; b[j] += wr * grad[j];
} }
// build the contribution matrix for measurement i // build the contribution matrix for measurement i
for (int k = 0; k < cols; ++k) { for (int k = 0; k < nC; ++k) {
double[] ak = a[k]; double[] ak = a[k];
double wgk = weight * grad[k]; double wgk = weight * grad[k];
for (int l = 0; l < cols; ++l) { for (int l = 0; l < nC; ++l) {
ak[l] += wgk * grad[l]; ak[l] += wgk * grad[l];
} }
} }
@ -170,7 +171,7 @@ public class GaussNewtonOptimizer extends AbstractLeastSquaresOptimizer {
new QRDecomposition(mA).getSolver(); new QRDecomposition(mA).getSolver();
final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray(); final double[] dX = solver.solve(new ArrayRealVector(b, false)).toArray();
// update the estimated parameters // update the estimated parameters
for (int i = 0; i < cols; ++i) { for (int i = 0; i < nC; ++i) {
currentPoint[i] += dX[i]; currentPoint[i] += dX[i];
} }
} catch (SingularMatrixException e) { } catch (SingularMatrixException e) {