use of de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem in project elki by elki-project.
the class LevenbergMarquardtMethod method iterate.
/**
* Perform an iteration of the approximation loop.
*/
public void iterate() {
// 1+lambda
for (int i = 0; i < numfit; i++) {
System.arraycopy(alpha[i], 0, covmat[i], 0, numfit);
covmat[i][i] *= (1.0 + lambda);
}
// System.out.println("Chisq: " + chisq);
// System.out.println("Lambda: " + lambda);
// System.out.print("beta: ");
// for (double d : beta)
// System.out.print(d + " ");
// System.out.println();
// Solve the equation system (Gauss-Jordan)
LinearEquationSystem ls = new LinearEquationSystem(covmat, beta);
ls.solveByTotalPivotSearch();
// update covmat with the inverse
covmat = ls.getCoefficents();
// and deltaparams with the solution vector
deltaparams = ls.getRHS();
// deltaparams = beta;
// System.out.print("deltaparams: ");
// for (double d : deltaparams)
// System.out.print(d + " ");
// System.out.println();
int i2 = 0;
for (int i = 0; i < numparams; i++) {
if (dofit[i]) {
paramstry[i] = params[i] + deltaparams[i2];
i2++;
}
}
double newchisq = simulateParameters(paramstry);
// have the results improved?
if (newchisq < chisq) {
// TODO: Do we need a larger limit than MIN_NORMAL?
if (lambda * 0.1 > Double.MIN_NORMAL) {
lambda = lambda * 0.1;
}
chisq = newchisq;
// and da as new beta
for (int i = 0; i < numfit; i++) {
System.arraycopy(covmat[i], 0, alpha[i], 0, numfit);
beta[i] = deltaparams[i];
}
System.arraycopy(paramstry, 0, params, 0, numparams);
} else {
// Anyway, this should prevent overflows.
if (lambda * 10 < Double.MAX_VALUE) {
lambda = lambda * 10;
}
}
}
Aggregations