Re: [eigen] Non linear solver questions

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hello Thomas

Another question: Is it possible to define the number of equations and unknowns not in compile time but during program running?

Best regards
Koldo

On Mon, Jun 13, 2011 at 12:03 AM, Thomas Capricelli <orzel@xxxxxxxxxxxxxxx> wrote:


Hi,


Sorry for the delay, I was away from internet for the whole last week, which is pretty unusual for me. Here are my answers.



On Friday 10 June 2011 09:19:31 Koldo Ramirez wrote:

> For example, look at this code:

>

> VectorXd x(2);

>

> hybrd_functor functor;

> HybridNonLinearSolver<hybrd_functor> solver(functor);

> solver.parameters.nb_of_subdiagonals = 1;

> solver.parameters.nb_of_superdiagonals = 1;

> solver.diag.setConstant(n, 1.);

> solver.useExternalScaling = true;

> if (solver.solveNumericalDiff(x) != 1)

> Cout() << "No convergence!";

>

> Questions:

> - What is the purpose of nb_of_subdiagonals, superdiagonals, setConstant(),

> useExternalScaling and another parameters?


There is an optimization for the case where the jacobian is known to be 'banded' as in http://en.wikipedia.org/wiki/Banded_matrix

You can see the big "if (msum>=n)" in fdjac1.h

The default value (-1) for sub/super diagonals means that the jacobian is dense (not banded).


The optimizer uses weighting (or scaling). It can either use what it thinks is the best (default case), or use scaling values provided by the user (there are cases where the use knows better than the default case).

This is what useExternalScaling does. If it set to False, solve.diag is not used at all. If it is set to True, then solve.diag provides the weighting used by the algorithm.

More information can be found from the two PDFs found on :

http://devernay.free.fr/hacks/cminpack/cminpack..html



> - Are there other parameters to indicate max. number of iterations and

> required precision?


solver.parameters.maxfev can be set to give a maximum number of 'function evaluations', which is as close as possible to "number of iterations". One step of the algorithm can trigger several function evaluation.


solver.parameter.xtol and solver.parameter.epsfcn can be set to tweak the precision parameters. The previous PDF url provide the original documentation about those.

Default values are ok for most cases.


> - If solveNumericalDiff() returns 1 the solver has converged successfully.

> Are there other parameters to check the quality of the results?


It's somewhat more complicated. solveNumericalDiff(), as other methods in this optimizer, returns a 'Status' (described at the very beginning of HybridNonLinearSolver.h).

Running = -1,

ImproperInputParameters = 0,

RelativeErrorTooSmall = 1,

TooManyFunctionEvaluation = 2,

TolTooSmall = 3,

NotMakingProgressJacobian = 4,

NotMakingProgressIterations = 5,

UserAsked = 6


UserAsked means that the functor function returned a negative value (which allow the functor to stop the algorithm, this is mainly used for interactive run of the algorithm).

Running and ImproperInputParameters are easy to understand.

All other values mean that the algorithm stopped, and the value provides detail about the stop criteria that triggered the stop. It provides an information about the quality of result.



> - You use a "functor" struct which calculates the equations and gives the

> Jacobian if available. Could have been possible to use a pointer to a

> function instead?


It could. This is a technical choice. Using a functor is more "c++" and is more coherent with other parts of Eigen..


best wishes,

Thomas

--

Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>

http://www.freehackers.org/thomas





Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/