template class mrpt::math::CLevenbergMarquardtTempl

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

Refer to this page for more details on the algorithm and its usage.

Parameters:

NUMTYPE

The numeric type for all the operations (float, double, or long double)

USERPARAM

The type of the “y” input to the user supplied evaluation functor. Default type is a vector of NUMTYPE.

#include <mrpt/math/CLevenbergMarquardt.h>

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

    typedef typename VECTORTYPE::Scalar NUMTYPE;
    typedef CMatrixDynamic<NUMTYPE> matrix_t;
    typedef VECTORTYPE vector_t;
    typedef std::function<void(const VECTORTYPE&x, const USERPARAM&y, VECTORTYPE&out)> TFunctorEval;
    typedef std::function<void(VECTORTYPE&x_new, const VECTORTYPE&x_old, const VECTORTYPE&x_incr, const USERPARAM&user_param)> TFunctorIncrement;

    // structs

    struct TResultInfo;

    //
methods

    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
        );
};

Inherited Members

public:
    // structs

    struct TMsg;

Typedefs

typedef std::function<void(const VECTORTYPE&x, const USERPARAM&y, VECTORTYPE&out)> TFunctorEval

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.

Parameters:

x

The state point under examination.

y

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

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.

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

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

Methods

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.