Template Class CLevenbergMarquardtTempl

Nested Relationships

Nested Types

Inheritance Relationships

Base Type

  • public mrpt::system::COutputLogger

Class Documentation

template<typename VECTORTYPE = CVectorDouble, class USERPARAM = VECTORTYPE>
class CLevenbergMarquardtTempl : public mrpt::system::COutputLogger

An implementation of the Levenberg-Marquardt algorithm for least-square minimization.

Refer to: tutorial_math_levenberg_marquardt

Template Parameters:
  • VECTORTYPE – The type for input/output vectors

  • USERPARAM – The type of the additional constant parameters input to the user supplied evaluation functor. Default type is a vector of NUMTYPE.

Public Types

using NUMTYPE = typename VECTORTYPE::Scalar
using matrix_t = CMatrixDynamic<NUMTYPE>
using vector_t = VECTORTYPE
using TFunctorEval = std::function<void(const VECTORTYPE &x, const USERPARAM &y, VECTORTYPE &out)>

The type of the function passed to execute. The user must supply a function which evaluates the error of a given point in the solution space.

Param x:

The state point under examination.

Param y:

The same object passed to “execute” as the parameter “userParam”.

Param out:

The vector of (non-squared) errors, of the average square root error, for the given “x”. The functor code must set the size of this vector.

using TFunctorIncrement = std::function<void(VECTORTYPE &x_new, const VECTORTYPE &x_old, const VECTORTYPE &x_incr, const USERPARAM &user_param)>

The type of an optional functor passed to execute to replace the Euclidean addition “x_new = x_old + x_incr” by any other operation.

Public Functions

inline CLevenbergMarquardtTempl()
inline void execute(VECTORTYPE &out_optimal_x, const VECTORTYPE &x0, TFunctorEval functor, const VECTORTYPE &increments, const USERPARAM &userParam, TResultInfo &out_info, mrpt::system::VerbosityLevel verbosity = mrpt::system::LVL_INFO, const size_t maxIter = 200, const NUMTYPE tau = 1e-3, const NUMTYPE e1 = 1e-8, const NUMTYPE e2 = 1e-8, bool returnPath = true, TFunctorIncrement x_increment_adder = nullptr)

Executes the LM-method, with derivatives estimated from functor is a user-provided function which takes as input two vectors, in this order:

  • x: The parameters to be optimized.

  • userParam: The vector passed to the LM algorithm, unmodified. and must return the “error vector”, or the error (not squared) in each measured dimension, so the sum of the square of that output is the overall square error.

x_increment_adder Is an optional functor which may replace the Euclidean “x_new = x + x_increment” at the core of the incremental optimizer by any other operation. It can be used for example, in on-manifold optimizations.

struct TResultInfo

Public Members

NUMTYPE final_sqr_err = 0
NUMTYPE initial_sqr_err = 0
size_t iterations_executed = 0
VECTORTYPE last_err_vector

The last error vector returned by the user-provided functor.

matrix_t path

Each row is the optimized value at each iteration.

matrix_t H

This matrix can be used to obtain an estimate of the optimal parameters covariance matrix:

\[ COV = H M H^\top \]
With COV the covariance matrix of the optimal parameters, H this matrix, and M the covariance of the input (observations).