ocra-recipes
Doxygen documentation for the ocra-recipes repository
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
ocra::NewtonSolver Class Reference

NewtonSolver class. More...

#include <NewtonSolver.h>

Inheritance diagram for ocra::NewtonSolver:
[legend]
Collaboration diagram for ocra::NewtonSolver:
[legend]

Classes

struct  eNewtonInfo
 

Public Types

typedef Eigen::Map< MatrixXd > MatrixMap
 
typedef Eigen::Map< VectorXd > VectorMap
 

Public Member Functions

 NewtonSolver (bool fullNewton=true)
 
void setAdaptativeAlpha (bool adapt)
 
bool getAdaptativeAlpha () const
 
void setEpsilon (double eps)
 
double getEpsilon () const
 
void setMaxIter (int maxIter)
 
int getMaxIter () const
 
void set_x0 (const VectorXd &x0)
 
const VectorXd & get_x0 () const
 
void printValuesAtSolution ()
 
std::string toString ()
 
void addObjective (GenericObjective &obj)
 
void removeObjective (Function &obj)
 
void removeObjective (GenericObjective &obj)
 
- Public Member Functions inherited from ocra::Solver
const std::vector< int > & findMapping (Variable &var)
 
virtual ~Solver ()
 
const OptimizationResultsolve ()
 
const OptimizationResultgetLastResult () const
 
void printStatus (std::ostream &os)
 
virtual const std::string & getMoreInfo () const
 
void setMemoryLevel (int level)
 
void setAutoDumpFile (const std::string &file)
 
void activateAutoDump ()
 
void deactivateAutoDump ()
 
void dump (const std::string &file="") const
 
int n ()
 
VariablegetProblemVariable ()
 
void setVariableValue (const VectorXd &value)
 
- Public Member Functions inherited from ocra::ObserverSubject
 ObserverSubject ()
 
virtual ~ObserverSubject ()
 
- Public Member Functions inherited from ocra::Observer
virtual ~Observer ()
 
template<int EVT>
void bind (SubjectBase< EVT > &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
template<int EVT>
void stopPropagation ()
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void bind (subject_type &subject)
 Call this method to automatically propagate observed events to observers connected to the subject given in argument. More...
 
- Public Member Functions inherited from ocra::Subject
virtual ~Subject ()
 
template<int EVT, class Derived , class Base >
void connect (Derived &object, void(Base::*newCallback)(int)) const
 Call this method to register a non-static method as a callback. More...
 
template<int EVT>
void connect (void(*newCallback)(int)) const
 Call this method to register a free function as a callback. More...
 
template<int EVT, class Derived , class Base >
void disconnect (Derived &object, void(Base::*callbackToErase)(int)) const
 Disconnect non-static method. More...
 
template<int EVT>
void disconnect (void(*callbackToErase)(int)) const
 Disconnect free function. More...
 
template<int EVT>
void propagate () const
 
template<int EVT>
void propagate (int timestamp) const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
void connect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type newCallback) const
 Call this method to register a non-static method as a callback. More...
 
void connect (typename SubjectBaseTraits< EVT, void >::callback_type newCallback) const
 Call this method to register a free function as a callback. More...
 
void disconnect (T &object, typename SubjectBaseTraits< EVT, T >::callback_type callback) const
 Disconnect non-static method. More...
 
void disconnect (typename SubjectBaseTraits< EVT, void >::callback_type callbackToErase) const
 Disconnect free function. More...
 
void propagate (int timestamp) const
 
void propagate () const
 
- Public Member Functions inherited from ocra::NamedInstance
 NamedInstance (const std::string &name)
 
const std::string & getName () const
 
virtual ~NamedInstance ()
 

Protected Member Functions

void doPrepare ()
 
void doSolve ()
 
void doConclude ()
 
- Protected Member Functions inherited from ocra::Solver
 Solver ()
 
void internalAddObjective (const GenericObjective &objective)
 
void internalAddConstraint (const GenericConstraint &constraint)
 
void internalRemoveObjective (const GenericObjective &objective)
 
void internalRemoveConstraint (const GenericConstraint &constraint)
 
virtual void onConstraintResize (int timestamp)
 
virtual void onObjectiveResize (int timestamp)
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_RESIZE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
void stopPropagation ()
 Call this method from your callbacks to avoid propagation to the bound subject (if any). More...
 
 ObserverBase ()
 
 ~ObserverBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_RESIZE >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_DEPENDENCIES >
 SubjectBase ()
 
 ~SubjectBase ()
 
- Protected Member Functions inherited from ocra::SubjectBase< EVT_CHANGE_VALUE >
 SubjectBase ()
 
 ~SubjectBase ()
 

Additional Inherited Members

- Protected Types inherited from ocra::ObserverBase< EVT_RESIZE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_DEPENDENCIES >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Types inherited from ocra::ObserverBase< EVT_CHANGE_VALUE >
typedef SubjectBase< EVT > subject_type
 
typedef InvokerBase< EVT > invoker_type
 
- Protected Attributes inherited from ocra::Solver
OptimizationResult _result
 

Detailed Description

NewtonSolver class.

Warning
None

This class implements a Newton Method to optimize a weighted sum of squared functions: $ \mbox{min.} \dfrac{1}{2} \sum_i{ w_i \left\| f_i \right\|^2_2} $ The functions $ f_i $ must provide their jacobian. Additionnaly if they can provides their hessian, it will be used for a complete Newton Method, unless the user choosed to use a quasi-Newton approach. If a function can't produce its hessian, or a quasi Newton method is asked, the hessian will be approximated by $ J_i^t J_i $ with $ J_i $ the jacobian matrix of $ f_i $.

The solver is taking itself the squared norm of each function, so that the ocra Objective instance has to contain $ f_i $, not | f_i |^2_2.

Let us define $ F(x) = \dfrac{1}{2} \sum_i{ w_i \left\| f_i(x) \right\|^2_2} $, and $ H(x)=\frac{\partial^2 F}{\partial x^2}(x)$. Starting from an initial guess $ x_0 $, the algorithm performs iterations $ x_{n+1} = x_n - \alpha H(x_n)^{-1} \nabla F(x_n) $ until the residual $ \left\|x_{n+1} - x_n\right\|_2$ is smaller than $ \epsilon $ or the maximal number of iterations has been reached.

The following parameters and options can be changed by the user:

In case the initial guess has not the good size, or was not initialized, the algorithm starts from $ x_0=0 $. In case the solver is called repeatedly and the user does not provide an initial guess, the last $ x_n $ of the previous run is used (unless the problem changed its size, in which case 0 will be used).

Definition at line 51 of file NewtonSolver.h.

Member Typedef Documentation

typedef Eigen::Map<MatrixXd> ocra::NewtonSolver::MatrixMap

Definition at line 55 of file NewtonSolver.h.

typedef Eigen::Map<VectorXd> ocra::NewtonSolver::VectorMap

Definition at line 56 of file NewtonSolver.h.

Constructor & Destructor Documentation

ocra::NewtonSolver::NewtonSolver ( bool  fullNewton = true)

Definition at line 6 of file NewtonSolver.cpp.

Member Function Documentation

void ocra::NewtonSolver::addObjective ( GenericObjective obj)

Add/remove an objective. Will throw a runtime_error in case obj already exist and is added again, or if one tries to remove obj and obj does not appear in the problem.

Definition at line 64 of file NewtonSolver.cpp.

void ocra::NewtonSolver::doConclude ( )
protectedvirtual

Implements ocra::Solver.

Definition at line 131 of file NewtonSolver.cpp.

void ocra::NewtonSolver::doPrepare ( void  )
protectedvirtual

Implements ocra::Solver.

Definition at line 101 of file NewtonSolver.cpp.

void ocra::NewtonSolver::doSolve ( void  )
protectedvirtual

Implements ocra::Solver.

Definition at line 116 of file NewtonSolver.cpp.

const VectorXd & ocra::NewtonSolver::get_x0 ( ) const

Definition at line 59 of file NewtonSolver.cpp.

bool ocra::NewtonSolver::getAdaptativeAlpha ( ) const

Definition at line 27 of file NewtonSolver.cpp.

double ocra::NewtonSolver::getEpsilon ( ) const

Definition at line 38 of file NewtonSolver.cpp.

int ocra::NewtonSolver::getMaxIter ( ) const

Definition at line 49 of file NewtonSolver.cpp.

void ocra::NewtonSolver::printValuesAtSolution ( void  )
virtual

Implements ocra::Solver.

Definition at line 89 of file NewtonSolver.cpp.

void ocra::NewtonSolver::removeObjective ( Function obj)

Definition at line 71 of file NewtonSolver.cpp.

void ocra::NewtonSolver::removeObjective ( GenericObjective obj)

Definition at line 83 of file NewtonSolver.cpp.

void ocra::NewtonSolver::set_x0 ( const VectorXd &  x0)

Definition at line 54 of file NewtonSolver.cpp.

void ocra::NewtonSolver::setAdaptativeAlpha ( bool  adapt)

Definition at line 22 of file NewtonSolver.cpp.

void ocra::NewtonSolver::setEpsilon ( double  eps)

Definition at line 32 of file NewtonSolver.cpp.

void ocra::NewtonSolver::setMaxIter ( int  maxIter)

Definition at line 43 of file NewtonSolver.cpp.

std::string ocra::NewtonSolver::toString ( )
virtual

Returns the state of the solver (e.g. matrices) as a string.

Implements ocra::Solver.

Definition at line 96 of file NewtonSolver.cpp.


The documentation for this class was generated from the following files: