34 template <
typename VECTORTYPE = CVectorDouble,
class USERPARAM = VECTORTYPE>
58 const VECTORTYPE&
x,
const USERPARAM&
y, VECTORTYPE& out)>;
64 VECTORTYPE& x_new,
const VECTORTYPE& x_old,
const VECTORTYPE& x_incr,
65 const USERPARAM& user_param)>;
101 VECTORTYPE& out_optimal_x,
const VECTORTYPE& x0,
TFunctorEval functor,
102 const VECTORTYPE& increments,
const USERPARAM& userParam,
105 const size_t maxIter = 200,
const NUMTYPE tau = 1e-3,
109 using namespace mrpt;
117 VECTORTYPE&
x = out_optimal_x;
120 ASSERT_(increments.size() == x0.size());
132 const size_t H_len = out_info.
H.
cols();
135 functor(
x, userParam, f_x);
137 g.matProductOf_Atb(J, f_x);
144 "End condition: math::norm_inf(g)<=e1 :%f\n",
152 VECTORTYPE xnew, f_xnew;
155 const size_t N =
x.size();
160 for (
size_t i = 0; i < N; i++) out_info.
path(iter, i) =
x[i];
165 while (!found && ++iter < maxIter)
169 for (
size_t k = 0; k < H_len; k++) H(k, k) += lambda;
173 h_lm.matProductOf_Ab(AUX,
g);
183 if (h_lm_n2 < e2 * (x_n2 + e2))
194 if (!x_increment_adder)
197 x_increment_adder(xnew,
x, h_lm, userParam);
199 functor(xnew, userParam, f_xnew);
200 const double F_xnew = pow(
math::norm(f_xnew), 2);
203 VECTORTYPE tmp(h_lm);
206 const double denom = tmp.dot(h_lm);
207 const double l = (F_x - F_xnew) / denom;
217 x, functor, increments, userParam, J);
219 g.matProductOf_Atb(J, f_x);
225 "End condition: math::norm_inf(g)<=e1 : %e\n",
228 lambda *= max(0.33, 1 - pow(2 * l - 1, 3));
240 for (
size_t i = 0; i < N; i++)
241 out_info.
path(iter, i) =
x[i];
242 out_info.
path(iter,
x.size()) = F_x;
251 if (returnPath) out_info.
path.
setSize(iter, N + 1);
typename VECTORTYPE::Scalar NUMTYPE
An implementation of the Levenberg-Marquardt algorithm for least-square minimization.
void matProductOf_AtA(const MAT_A &A)
this = AT * A
CLevenbergMarquardtTempl()
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 tak...
VerbosityLevel
Enumeration of available verbosity levels.
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
This file implements several operations that operate element-wise on individual or pairs of container...
VECTORTYPE last_err_vector
The last error vector returned by the user-provided functor.
void setMinLoggingLevel(const VerbosityLevel level)
Set the minimum logging level for which the incoming logs are going to be taken into account...
#define ASSERT_(f)
Defines an assertion mechanism.
This base provides a set of functions for maths stuff.
matrix_t path
Each row is the optimized value at each iteration.
Versatile class for consistent logging and management of output messages.
size_t iterations_executed
CMatrixDynamic< NUMTYPE > matrix_t
Scalar maximumDiagonal() const
Returns the maximum value in the diagonal.
matrix_t H
This matrix can be used to obtain an estimate of the optimal parameters covariance matrix: With COV ...
Derived inverse_LLt() const
Returns the inverse of a symmetric matrix using LLt.
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
Use: MRPT_LOG_DEBUG_STREAM("Var=" << value << " foo=" << foo_var);
size_type cols() const
Number of columns in the matrix.
void estimateJacobian(const VECTORLIKE &x, const std::function< void(const VECTORLIKE &x, const USERPARAM &y, VECTORLIKE3 &out)> &functor, const VECTORLIKE2 &increments, const USERPARAM &userParam, MATRIXLIKE &out_Jacobian)
Estimate the Jacobian of a multi-dimensional function around a point "x", using finite differences of...
CONTAINER::Scalar norm_inf(const CONTAINER &v)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
COutputLogger()
Default class constructor.
void setSize(size_t row, size_t col, bool zeroNewElements=false)
Changes the size of matrix, maintaining the previous contents.
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 + ...
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
std::string sprintf_vector(const char *fmt, const VEC &V)
Generates a string for a vector in the format [A,B,C,...] to std::cout, and the fmt string for each v...
std::function< void(const VECTORTYPE &x, const USERPARAM &y, VECTORTYPE &out)> TFunctorEval
The type of the function passed to execute.
CONTAINER::Scalar norm(const CONTAINER &v)