Click or drag to resize

LevenbergMarquardt Class

A class for finding minimum of a least squared problem on the form
f(x) = ||fv(x)||
where x and fv are multi-dimensional, of dimension dimx and dimf respectively.

It is using a Levenberg-Marquardt method or a Newton-Raphson method, according to UseLm.

Finding zeros of a nonlinear system of equations, i.e.
fv(x) = [0]
is a special case of a least square minimization problem, where the minimum is in the zero point and fv(x*) = (0).

If the Jacobian is available, it can be provided, otherwise it works by numerically calculating the Jacobian.

Inheritance Hierarchy
SystemObject
  DHIMath.NumericsLevenbergMarquardt

Namespace:  DHIMath.Numerics
Assembly:  DHI.Mike1D.Generic (in DHI.Mike1D.Generic.dll) Version: 16.0.0.0 (11.1.1.1111)
Syntax
C#
public class LevenbergMarquardt

The LevenbergMarquardt type exposes the following members.

Constructors
  NameDescription
Public methodLevenbergMarquardt(Int32, Int32, VectorFunction)
Constructor for minimizing/finding zeros of the function
Public methodLevenbergMarquardt(Int32, Int32, VectorFunction, VectorFunction)
Constructor for minimizing/finding zeros of the function

The jacobian must return the jacobian as a vector in column major ordering containing the coefficients [df1_dx1, df2_dx1, df1_dx2, df2_dx2].

Top
Properties
  NameDescription
Public propertyFx
Current function value in iteration
Public propertyJacobian
Setter for Jacobian.
Public propertyJacobianRecalc
Integer specifying how often the Jacobian is completely recalculated by a forward difference approximation.

Every iteration can either performs a rank-1 update of the the Jacobian or completely recalculate the Jacobian. This number specifies how often the Jacobian should be completely recalculated.

Set to 1 to recalculate in every iteration. Set to zero to never recalculate, but only use rank-1 updates.

Default is Max(dimx,10). When a Jacobian function is provided, this parameter is not used.

Public propertyLambdaScaling
Scaling factor in J'*J+lambda*I, replacing the diagonal of I by those in LambdaScaling

By default they are [1,...,1]. They can not be negative.

Public propertyMaxFunctionEval
Maximum number of function evaluations. Default 200

This may not be hit exactly, since one iteration can trigger several function evaluations.

In case a Jacobian is not provided, this can be set app.

MaxIter + dimx*MaxIter/JacobianRecalc,
since the number of evaluations per iteration is 1 per default and then dimx evaluations per 1/JacobianRecalc iterations

Public propertyMaxIter
Maximum number of iterations. Default 100
Public propertyMaxLineSearchIter
Maximum number of line search iterations. Default 0.
Public propertyNumFunctionEval
Hold the number of function evaluations for the last solve.
Public propertyNumIter
Hold the actual number of iterations for the last solve.
Public propertyNumJacobianEval
Hold the number of Jacobian evaluations for the last solve.
Public propertyRelativeDx
Relative dx used when calculating Jacobian numerically by a forward difference approximation.

Default value is 1e-6;

The forward difference has the form:

dx = RelativeDx*Math.Abs(x)
df/dx = (f(x+dx)-f(x)) / dx;

Public propertyTau
used in starting value for Marquardt parameter:
lambda = Tau * max( diag(J(x0)'*J(x0)) )

Default value is 1e-3

Public propertyTolG
Tolerance value for steepest descent direction, used in stopping criteria, stopping when:
||g||_inf <= TolG

Default value is 1e-6. It is recommended to set a lower value when not using LM (UseLm).

Public propertyTolX
Tolerance value for change in parameter vector, used in stopping criteria, stopping when:
||dx||_2 <= TolX*(||x||_2 + TolX)
It combines a relative and absolute stopping criteria

Default value is 1e-9.

Public propertyUseLineSearch
Flag specifying whether a line search approach is to be used. Default false.
Public propertyUseLm
Flag whether a LM algorithm should be used. Default true. If set to false the Newton-Raphson method will be used. The Newton-Raphson method can only be used for finding zeros, not for minimizing in generel, and only for square systems, dimx = dimf.
Public propertyX
Current value in iteration
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberJacobianTest(Int32, Int32, Double, VectorFunction, VectorFunction)
Calculates the 2-norm difference between the exact and the numeric jacobian, on an element-wise basis (not matrix norm, but element/vector norm)
Public methodStatic memberJacobianTest(Int32, Int32, Double, VectorFunction, VectorFunction, Double)
Calculates the 2-norm difference between the exact and the numeric jacobian, on an element-wise basis (not matrix norm, but element/vector norm)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodSolve
Minimize/Solves for zeros, using x as starting point and updating the value of x as a result.

The user must check whether the solution is acceptable before using it.

Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Public fieldIterations
Stores all intermediate x-array solution values for all iterations, in case StoreIterations is set. If the StoreIterations is not set, this is null.

The residual is decreasing with each x-array in the list.

Public fieldLambdaCutRel
Relative lambda value deceding when to set lambda to zero, in order to try to get quadratic convergence close to the solution.

Default value is zero (disabled). Values must be positive and reasonable values are in the range [0,1], where a value close to zero will change behavior seldomly.

Public fieldLambdaDecreaseMinFac
When decreasing lambda, this sets the minimum decrease factor

Default value is 1.0/5.0. Values must be positive and in the range ]0,1[.

Public fieldLambdaUpdateFactor
When updating lambda, an optimal update factor is calculated. This scales the update factor. Set greater than 1 in order to get a larger lambda, which can increase stability.

Default value is 1. Value must be positive and larger than 1.

Public fieldNewValueAction
If set, the action method is called every time a new x value has been computed. If the x-array argument is changed, the method must return true, otherwise it should return false.

Changing the x-values can be used to constrain the x values to a certain set of values.

Changing the x-values may significantly decrease convergence speed, and it may produce a suboptimal solution, even though an optimal solution is nearby.

Public fieldStoreIterations
Flag indicating whether x-array solution values for all iterations should be stored. .
Top
See Also