Function levenberg_marquardt
pub(crate) fn levenberg_marquardt<F>(
start: &[f64],
evaluate: F,
tolerance: SolveTolerance,
cap: usize,
) -> Result<Fitted, FitFailure>Expand description
Levenberg-Marquardt over a parameter vector.
Converged by any of four tests: the residual norm below the tolerance, the
gradient orthogonal to the residual (GRADIENT_TOLERANCE), a step below
the parameters’ last digit, or an accepted step that stopped improving.
evaluate returns the residual vector and its Jacobian at one parameter
point — together, because the caller obtains both from one seeded pass
and splitting them would double the work. jacobian[i][j] is
∂rᵢ/∂paramⱼ.
The step solves the damped normal equations (JᵀJ + λI)δ = −Jᵀr. Damping
falls when a step improves the residual norm and rises when it does not,
which is what makes the method fall back toward gradient descent where
Gauss-Newton would overshoot.
§Errors
FitFailure::Unconverged at the cap, FitFailure::Singular when no
damping makes the normal equations invertible.