Registered Member
|
Hi guys, I've been trying to get the Nonlinear Optimization module (Levenberg Marquardt) in Eigen to work and I'm running into a little trouble.
The examples listed in the tests all have preentered data hardcoded in the objective functions. How do you pass in a data set into the function e.g. at runtime? For instance, lets say I was making a program that fits a curve to a set of points that I read in from a file (defined at user prompt). Much appreciated, thanks! |
Registered Member
|
When you create your functor class with operator() and df(), you can simply define another function in that class, say initDataPoints(...) which will set all the required data; for your case, these are the data points you read from a file.
|
Registered Member
|
Thanks, I ended up adding member objects to do the job
struct Objective_functor : Functor<double> { Objective_functor(int n_par, int m_dat, vtkPolyData *BdryElms, vtkPolyData *LRS) : Functor<double>(n_par,m_dat) ,myBdryElms(BdryElms), myLRS(LRS) {} //Put data objects here vtkPolyData *myBdryElms; vtkPolyData *myLRS; int operator()(const VectorXd &x, VectorXd &fvec) const //fvec evaulation {.... ..} } //Calling the instance Objective_functor functor(n_par,m_dat,BdryElms,LRS_post); ... |
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]