Skip to content
Snippets Groups Projects
Commit 3f28f711 authored by Jesper Andersson's avatar Jesper Andersson
Browse files

Levenberg-Marquardt no catches exceptions due to singular Hessian

parent b73c8f6b
No related branches found
No related tags found
No related merge requests found
......@@ -353,9 +353,17 @@ NonlinOut levmar(const NonlinParam& p, const NonlinCF& cfo)
H->AddTo(i,i,p.Lambda()-olambda);
}
}
ColumnVector step = -H->SolveForx(g,SYM_POSDEF,p.EquationSolverTol(),p.EquationSolverMaxIter());
double ncf = cfo.cf(p.Par()+step);
if (success = (ncf < p.CF())) { // If last step successful
ColumnVector step;
double ncf = 0.0;
bool inv_fail = false; // Signals failure of equation solving
try {
step = -H->SolveForx(g,SYM_POSDEF,p.EquationSolverTol(),p.EquationSolverMaxIter());
ncf = cfo.cf(p.Par()+step);
}
catch(...) {
inv_fail = true;
}
if (!inv_fail && (success = (ncf < p.CF()))) { // If last step successful
olambda = 0.0; // Pristine Hessian, so no need to undo old lambda
p.SetPar(p.Par()+step); // Set attempt as new parameters
p.SetLambda(p.Lambda()/10.0); // Decrease nudge factor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment