Main       Commercial support       FAQ       Forum       Contact Us

Levenberg-Marquardt algorithm for multivariate optimization

The Levenberg-Marquardt Method is recommended, if such a function as F = f 2(x,...,x) + ... + f 2(x,...,x) needs to be minimized. The algorithm combines advantages of the steepest descent method (that is, minimization along the direction of the gradient) with the Newton method (that is, using a quadratic model to speed up the process of finding the minimum of a function). This algorithm obtained its operating stability from the steepest descent method, and adopted its accelerated convergence in the minimum vicinity from the Newton method. Standard implementation of the Levenberg-Marquardt algorithm (LMA), its drawbacks, and the updated algorithm version in the ALGLIB package are discussed below. The reader is recommended to familiarise himself/herself with the algorithm description on Wikipedia or in Numerical Recipes, prior to studying the following part. It is assumed hereinafter that the reader is familiar with the general principles of operating the Levenberg-Marquardt algorithm.

Implementation of the Levenberg-Marquardt Method in ALGLIB

The traditional version of the Levenberg-Marquardt algorithm supposes using the Jacobian matrix to make a quadratic model, taking one iteration step per the model, and the construction of a subsequent new model. There are a number of disadvantages in this approach, such as the algorithm's general inefficiency, high demands for hardware resources, and a decrease in convergence towards the minimum when solving problems of a certain class. These shortcomings are fully detailed below:

Implemented in the ALGLIB package is an updated algorithm version that is adjusted subject to the afore-mentioned observations. The new algorithm may use more comprehensive information on the task, including values of function f, the Jacobian matrix, the gradient of function F, and the Hessian of function F. The following algorithm versions may be used, depending on the information that is available:

Use of Algorithm and Reverse Communication

The optimization algorithm shall obtain values of a function/gradient/... during its operation. This problem is solved in most program packages by transferring the pointer to the function (C++, Delphi) or delegate (C#) which is used to calculate function value/gradient/Hessian.

The ALGLIB package, differently from other libraries, makes use of reverse communication to solve this problem. When a value (or derivatives) of a function needs/need to be calculated, the algorithm state is stored within a special structure, control is returned to the calling program, which makes all calculations and recalls the computing subroutine.

Thus, the optimization algorithm is operated in accordance in the following order:

  1. MinLMState data structure preparation by means of one of the algorithm initialization subrotuines (MinLMFJ, MinLMFGJ, MinLMFGH).
  2. Setting of additional optimization parameters with MinLMSetXXXXX functions.
  3. MinLMIteration subroutine call.
  4. If False is returned from the subroutine, then the algorithm operation is completed, and the minimum is found (the minimum itself can be obtained by calling the MinLMResults subprogram).
  5. If True is returned from the subroutine, the latter will make a request for information on the function. The function/gradient/Jacobian/Hessian shall be calculated according to the field of the MinLMState structure, which is set as True (this issue is fully detailed below).
  6. The MinLMIteration subroutine needs to be called again after the requested information is loaded into the MinLMState structure.

The following fields of the MinLMState structure are used in order to exchange information with the user:

The MinLMIteration subprogram can set one, and only one, of the following fields to True, subject to what exactly needs to be calculated:

The table given below will show which of the fields can be set by different LMA versions.

         NeedF   NeedFG  NeedFiJ NeedFGH XUpdated
MinLMFJ     X               X               X
MinLMFGJ    X       X       X               X
MinLMFGH    X       X               X       X

Manual entries

C++ minlm.h   
C# minlm.cs   
MPFR minlm.h   
Delphi minlm.pas   
FreePascal minlm.pas   
VBA minlm.bas   

This article is intended for personal use only.

Download ALGLIB

C#

C# source.

Downloads page

 

C++

C++ source.

Downloads page

 

C++, multiple precision arithmetic

C++ source. MPFR/GMP is used.

GMP source is available from gmplib.org. MPFR source is available from www.mpfr.org.

Downloads page

 

FreePascal

FreePascal source.

Downloads page

 

Delphi

Delphi source.

Downloads page

 

Visual Basic

VBA source.

Downloads page

 

 

ALGLIB project, 1999-2010