#optimization #computer-vision #squares #marquardt #levenberg

no-std levenberg-marquardt

Levenberg-Marquardt algorithm built on top of nalgebra

18 releases (breaking)

0.14.0 Jul 22, 2024
0.13.1 Sep 2, 2023
0.13.0 Jan 27, 2023
0.12.0 Feb 4, 2022
0.4.0 Mar 8, 2020

#91 in Algorithms

Download history 509/week @ 2024-08-14 498/week @ 2024-08-21 677/week @ 2024-08-28 759/week @ 2024-09-04 534/week @ 2024-09-11 629/week @ 2024-09-18 727/week @ 2024-09-25 826/week @ 2024-10-02 875/week @ 2024-10-09 851/week @ 2024-10-16 1102/week @ 2024-10-23 913/week @ 2024-10-30 573/week @ 2024-11-06 1278/week @ 2024-11-13 847/week @ 2024-11-20 704/week @ 2024-11-27

3,564 downloads per month
Used in 4 crates

MIT license

185KB
4K SLoC

levenberg-marquardt

Discord Crates.io MIT/Apache docs.rs LoC ci

Solver for nonlinear least squares problems

The implementation is a port of the classic MINPACK implementation of the Levenberg-Marquardt (LM) algorithm. This version of the algorithm is sometimes referred to as exact LM.

All current unit tests indicate that we achieved identical output (on a floating-point level) to the MINPACK implementation, especially for rank deficient unstable problems. This was mainly useful for testing. The Fortran algorithm was extended with NaN and inf handling, similar to what lmfit does.

The crate offers a feature called minpack-compat which sets floating-point constants to the ones used by MINPACK and removes the termination criterion of "zero residuals". This is necessary for identical output to MINPACK but generally not recommended.

Usage

See the docs for detailed information.

impl LeastSquaresProblem<f64> for Problem {
    // define this trait for the problem you want to solve
}
let problem = Problem::new(initial_params);
let (problem, report) = LevenbergMarquardt::new().minimize(problem);
assert!(report.termination.was_successful());

References

Software:

  • The MINPACK Fortran implementation.
  • A C version/update, lmfit.
  • A Python implementation in pwkit.

One original reference for the algorithm seems to be

Moré J.J. (1978) The Levenberg-Marquardt algorithm: Implementation and theory. In: Watson G.A. (eds) Numerical Analysis. Lecture Notes in Mathematics, vol 630. Springer, Berlin, Heidelberg.

by one of the authors of MINPACK.

The algorithm is also described in the form as implemented by this crate in the book "Numerical Optimization" by Nocedal and Wright, chapters 4 and 10.

Dependencies

~3MB
~65K SLoC