ReFRACtor
|
The base class for all iterative optimizers. More...
#include <iterative_solver.h>
Public Types | |
enum | status_t { SUCCESS, CONTINUE, STALLED, ERROR, UNTRIED } |
Enum type for the status of the iterative solver. More... | |
Public Member Functions | |
IterativeSolver (int max_cost_function_calls, bool vrbs) | |
Constructor. More... | |
virtual | ~IterativeSolver () |
virtual std::vector< blitz::Array< double, 1 > > | accepted_points () const |
Returns a vector (std) of accepted points. More... | |
virtual void | add_observer (Observer< IterativeSolver > &Obs) |
Add an observer. More... | |
void | add_observer_and_keep_reference (boost::shared_ptr< Observer< IterativeSolver > > &Obs) |
Add an observer and keep a reference to it. More... | |
virtual std::vector< double > | cost_at_accepted_points () const |
Returns a vector (std) of cost function values at accepted points. More... | |
virtual int | num_accepted_steps () const |
Returns the number of the accepted steps. More... | |
virtual void | print (std::ostream &Os) const |
Prints description of object. More... | |
std::string | print_to_string () const |
Print to string. More... | |
virtual void | remove_observer (Observer< IterativeSolver > &Obs) |
Remove an observer. More... | |
virtual void | solve ()=0 |
The method that solves the optimization problem. More... | |
virtual status_t | status () const |
Returns a value of IterativeSolver::status_t type. More... | |
virtual const char *const | status_str () const |
Returns the string version of the solver status. More... | |
Protected Member Functions | |
void | add_observer_do (Observer< IterativeSolver > &Obs, IterativeSolver &t) |
Add an observer. More... | |
void | add_observer_do (Observer< IterativeSolver > &Obs) |
void | clean_dead_ptr () |
Remove any dead pointers. More... | |
void | notify_update_do (const IterativeSolver &Self) |
Function to call to notify Observers of a state change. More... | |
void | record_accepted_point (const blitz::Array< double, 1 > &point) |
Called to record an accepted point. More... | |
void | record_cost_at_accepted_point (double cost) |
Called to record the cost function value at an accepted point. More... | |
void | remove_observer_do (Observer< IterativeSolver > &Obs, IterativeSolver &t) |
Remove an observer. More... | |
void | remove_observer_do (Observer< IterativeSolver > &Obs) |
Protected Attributes | |
int | max_cost_f_calls |
std::list< boost::weak_ptr< Observer< IterativeSolver > > > | olist |
std::vector< boost::shared_ptr< Observer< IterativeSolver > > > | ref_list |
status_t | stat |
bool | verbose |
The base class for all iterative optimizers.
This class is the base class for iterative optimizers. No derivatives of any order appear in the class implementation because not all optimization problem solvers require derivatives.
An iterative solver, during the process of minimizing a cost function, moves from one point to the next in the parameter space. After computing a step, some optimization algorithms use some criteria to decide whether or not to take the step and to move to the next point. In the context of the class hierarchy rooted at this class, a step that is taken is called an accepted step, and a step that is not taken is called a rejected step. All the classes of the hierarchy that implement the solve() method must correctly record all the points and their associated cost function values after taking accepted steps only. The initial starting point and its cost value must also be recorded.
This class is not associated with any problem (from the problem class hierarchy). Problems may appear in different formats (even if equivalent): residual/Jacobian, cost-function/gradient, cost-function only ...
Definition at line 39 of file iterative_solver.h.
Enum type for the status of the iterative solver.
Definition at line 50 of file iterative_solver.h.
|
inline |
Constructor.
[in] | max_cost_function_calls | max number of times to evaluate cost function |
[in] | vrbs | if set to true, then a leaf class of this class hierarchy should display some diagnostic information during each iteration |
Definition at line 71 of file iterative_solver.h.
|
inlinevirtual |
Definition at line 77 of file iterative_solver.h.
|
inlinevirtual |
Returns a vector (std) of accepted points.
This method returns a std vector of accepted points in the parameter space. The initial starting point is always an accepted point. Then the second accepted point is the point obtained after taking the first accepted step from the initial (first) point. The third accepted point is the point obtained after taking the second accepted step from the second accepted point and so on.
In other words, if the initial point and all the accepted points after taking the accepted steps are recorded correctly, then
Therefore, if the recording of the accepted points is done correctly, and num_accepted_steps() returns 2, then
Definition at line 133 of file iterative_solver.h.
|
inlinevirtual |
Add an observer.
Implements FullPhysics::Observable< IterativeSolver >.
Definition at line 84 of file iterative_solver.h.
|
inlineinherited |
Add an observer and keep a reference to it.
See the discussion in the Observer class description for details.
Definition at line 107 of file observer.h.
|
inlineprotectedinherited |
Add an observer.
Definition at line 148 of file observer.h.
|
inlineprotectedinherited |
Definition at line 159 of file observer.h.
|
inlineprotectedinherited |
Remove any dead pointers.
Definition at line 196 of file observer.h.
|
inlinevirtual |
Returns a vector (std) of cost function values at accepted points.
This method returns a std vector of cost function values computed at the accepted points. In other words, if the accepted points and the cost function values at these points are recorded correctly, then
Definition at line 157 of file iterative_solver.h.
|
inlineprotectedinherited |
Function to call to notify Observers of a state change.
The object should pass itself to this function, so it can be passed to the Observers.
Definition at line 121 of file observer.h.
|
inlinevirtual |
Returns the number of the accepted steps.
Definition at line 96 of file iterative_solver.h.
|
inlinevirtual |
Prints description of object.
Reimplemented in FullPhysics::NLLSSolverLM, FullPhysics::ConnorSolverMAP, FullPhysics::IterativeSolverDer, FullPhysics::NLLSSolverGSLSM, FullPhysics::CostMinimizer, FullPhysics::NLLSSolver, FullPhysics::NLLSSolverGSL, FullPhysics::NLLSSolverGSLLMDER, FullPhysics::CostMinimizerGSL, and FullPhysics::NLLSSolverGSLLMSDER.
Definition at line 223 of file iterative_solver.h.
|
inlineinherited |
Print to string.
This is primarily useful for SWIG wrappers to this class, e.g. a to_s method in ruby.
Definition at line 31 of file printable.h.
|
inlineprotected |
Called to record an accepted point.
This method is called to record an accepted point. It is the responsibility of the implementer of the solve() method to record the accepted points. The accepted points must be recorded in the same order that they are achieved.
[in] | point | an accepted point in the parameter space |
Definition at line 246 of file iterative_solver.h.
|
inlineprotected |
Called to record the cost function value at an accepted point.
This method is called to record the cost function value at an accepted point. It is the responsibility of the implementer of the solve() method to record the cost function values at the accepted points. The cost values must be recorded in the same order that they are evaluated.
[in] | cost | cost function value at an accepted point in the parameter space |
Definition at line 269 of file iterative_solver.h.
|
inlinevirtual |
Remove an observer.
Implements FullPhysics::Observable< IterativeSolver >.
Definition at line 87 of file iterative_solver.h.
|
inlineprotectedinherited |
Remove an observer.
Definition at line 173 of file observer.h.
|
inlineprotectedinherited |
Definition at line 181 of file observer.h.
|
pure virtual |
The method that solves the optimization problem.
The algorithms that solve the optimization problem are implemented in this method by the leaf classes of the solver class hierarchy.
Implemented in FullPhysics::NLLSSolverLM, FullPhysics::ConnorSolverMAP, FullPhysics::NLLSSolverGSLSM, FullPhysics::NLLSSolverGSL, and FullPhysics::CostMinimizerGSL.
|
inlinevirtual |
Returns a value of IterativeSolver::status_t type.
This method returns the status of the solver. The status of the solver is initialized to IterativeSolver::UNTRIED, then it must be set to one of the following values by the implemented version of solve() method:
Please, read the comments on IterativeSolver::status_t type and its possible values.
Definition at line 190 of file iterative_solver.h.
|
virtual |
Returns the string version of the solver status.
If the method status() returns
then status_str() will return
respectively.
Definition at line 14 of file iterative_solver.cc.
|
protected |
Definition at line 229 of file iterative_solver.h.
|
protectedinherited |
Definition at line 200 of file observer.h.
|
protectedinherited |
Definition at line 201 of file observer.h.
|
protected |
Definition at line 232 of file iterative_solver.h.
|
protected |
Definition at line 231 of file iterative_solver.h.