ocra-recipes
Doxygen documentation for the ocra-recipes repository
|
NewtonSolver class. More...
#include <NewtonSolver.h>
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 OptimizationResult & | solve () |
const OptimizationResult & | getLastResult () 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 () |
Variable & | getProblemVariable () |
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 |
NewtonSolver class.
This class implements a Newton Method to optimize a weighted sum of squared functions: The functions 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 with the jacobian matrix of .
The solver is taking itself the squared norm of each function, so that the ocra Objective instance has to contain , not | f_i |^2_2.
Let us define , and . Starting from an initial guess , the algorithm performs iterations until the residual is smaller than 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 . In case the solver is called repeatedly and the user does not provide an initial guess, the last 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.
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.
ocra::NewtonSolver::NewtonSolver | ( | bool | fullNewton = true | ) |
Definition at line 6 of file NewtonSolver.cpp.
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.
|
protectedvirtual |
Implements ocra::Solver.
Definition at line 131 of file NewtonSolver.cpp.
|
protectedvirtual |
Implements ocra::Solver.
Definition at line 101 of file NewtonSolver.cpp.
|
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.
|
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.
|
virtual |
Returns the state of the solver (e.g. matrices) as a string.
Implements ocra::Solver.
Definition at line 96 of file NewtonSolver.cpp.