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

## 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,
)