MRPT / mrpt

:zap: The Mobile Robot Programming Toolkit (MRPT)
https://docs.mrpt.org/reference/latest/
BSD 3-Clause "New" or "Revised" License
1.94k stars 628 forks source link

Levenberg-Marquardt method with time-series data optimisation #102

Closed benedict1986 closed 9 years ago

benedict1986 commented 9 years ago

Hi, I am writing to ask a question about writing the cost function for LM method. In the function template,

typedef void (*TFunctorEval)( const VECTORTYPE &x, const USERPARAM &y, VECTORTYPE &out);

we can use x, y and out as parameters. As I understand, x is the initial value for optimisating variables, y is observation data and output is the optimisation result. My questions is what if y = [y1, y2, ..., yT] and yt = [u, v, w]'? How can I pass the total length (T) of the time-series? If y is a 3D parameter, does out also is a 3D vector with the error in each dimension?

Thank you

jlblancoc commented 9 years ago

Hi,

Since USERPARAM is a template parameter, nothing prevents you from defining a struct with all the data you need, for example:

struct MyInputData { std::vector y_data; size_t anything_else; ...

};

then the eval function could be like:

typedef void (*TFunctorEval)( const Eigen::VectorXd &x, const MyInputData &y, Eigen::VectorXd &out);

benedict1986 commented 9 years ago

Hi, thank you for answering my question. I tried to code it according to your suggestion but still get an error.

My function is defined as

void Function(const CVectorDouble &x, tuple<CVectorDouble, CVectorDouble> *a, CVectorDouble &out_f)

and it is used as

CLevenbergMarquardt::execute(xHat, X, &Function, increments_x, Y, info, false, 100);

I got the error as

1   IntelliSense: argument of type "void (*)(const mrpt::math::CVectorDouble &x, std::tuple<mrpt::math::CVectorDouble, mrpt::math::CVectorDouble> &a, mrpt::math::CVectorDouble &out_f)" is incompatible with parameter of type "void (*)(const mrpt::math::CVectorDouble &x, const mrpt::math::CVectorDouble &y, mrpt::math::CVectorDouble &out)"

Do I have to change the code in

template < typename VECTORTYPE = Eigen::VectorXd, class USERPARAM = VECTORTYPE >

or

typedef void (*TFunctorEval)( const VECTORTYPE &x, const USERPARAM &y, VECTORTYPE &out);

in file CLevenbergMarquardt.h?

Thank you.