Click or drag to resize

LevenbergMarquardt2D Class

A class for finding minimum of a least squared problem on the form
f(x,y) = 0.5*||fv(x,y)||
where fv is a 2D function - returns a vector of length 2.

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,y) = [0,0]
is a special case of a least square minimization problem, where the minimum is in the zero point and fv(x*,y*) = (0,0).

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

Inheritance Hierarchy
SystemObject
  DHIMath.NumericsLevenbergMarquardt2D

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 LevenbergMarquardt2D

The LevenbergMarquardt2D type exposes the following members.

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

The jacobian must return a vector containing the coefficients [df1_dx1, df1_dx2, df2_dx1, df2_dx2].

Top
Properties
  NameDescription
Public propertyJacobian
Function to calculate Jacobian of input function.
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 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 + 2*MaxIter/JacobianRecalc,
since the number of evaluations per iteration is 1 per default and then 2 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.
Top
Methods
  NameDescription
Public methodStatic memberCalcJacobian
Calculates numerically the Jacobian
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(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(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
Stored iteration values. Only used when StoreIterations is set.
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 fieldStoreIterations
Flag indicating whether iteration vaues should be stored in Iterations
Top
See Also