This forum has been archived. All content is frozen. Please use KDE Discuss instead.

LM Solver Example?

Tags: None
(comma "," separated)
daviddoria
Registered Member
Posts
46
Karma
0
OS

LM Solver Example?

Fri Nov 04, 2011 9:24 pm
I tried to look through LevenbergMarquardt.h, but I didn't get very far. I tried to make a very simple example that minimizes the function f(x) = x^2 :

http://programmingexamples.net/index.ph ... gMarquardt

The first error I run into is:

error: ‘struct MyFunctor’ has no member named ‘values’

I'm not sure what the Functor is supposed to store in 'values'? Can anyone explain the structure of this LM implementation a bit more?

Thanks,

David
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: LM Solver Example?

Fri Nov 04, 2011 9:52 pm
have a look at the file unsupported/test/NonLinearOptimizaiton.cpp, line 104 to 162 for an example.
daviddoria
Registered Member
Posts
46
Karma
0
OS

Re: LM Solver Example?

Fri Nov 04, 2011 10:01 pm
Yea I looked at that - that's how I got as far as I did :). I don't understand what 'values' and 'inputs' are? I thought operator() should just return f(x), while df() should return a derivative? Why does the Functor have to have a state (i.e. 'values' and 'inputs')?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: LM Solver Example?

Fri Nov 04, 2011 10:20 pm
values() is the number of constraints, and inputs() the number of unknows.
mliberty
Registered Member
Posts
3
Karma
0

Re: LM Solver Example?

Sat Nov 05, 2011 2:09 pm
I recently started using the NonLinearOptimization library, and I had similar issues with the interface for the NonLinearOptimization functor, which is really much more than just a functor. Here is what I found:

LevenbergMarquardt requires the functor to have the methods values(), operator() and df(), and it requires that the input vector and Jacobian matrix are Eigen::Dynamic. Compile-time constant lengths are not supported. (This took me way to long to figure out). Although not used, the examples all include the method input().

To numerically compute your Jacobian, use the NumericalDiff library which requires the methods values(), operator() and the typedefs Scalar, InputType, ValueType and JacobianType. It also requires the enums InputsAtCompileTime and ValuesAtCompileTime which MUST be Eigen::Dynamic for use with LevenbergMarquardt.
daviddoria
Registered Member
Posts
46
Karma
0
OS

Re: LM Solver Example?

Sat Nov 05, 2011 2:15 pm
mliberty -

I got a (very simple) example working with a numerical derivative:

http://programmingexamples.net/index.ph ... tNumerical

If you would add an example on that wiki of a more complicated one (using NumericalDiff as you mentioned) it would be a big help!

David
forrestrm
Registered Member
Posts
3
Karma
0
OS

Re: LM Solver Example?

Mon Nov 07, 2011 11:21 pm
I'm having a similar issue figure out what is needed for the functor: see viewtopic.php?f=74&t=97683

Is there a requirement in the LM algorithm for you to have an over-constrained problem (functor.values() >= functor.inputs())? The algorithm is returning LevenbergMarquardtSpace::ImproperInputParameters when I give it an under constrained problem. Any suggestions?

thanks,
Forrest


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]