ReFRACtor
|
The base class for all problem classes that implement a cost function. More...
#include <cost_func.h>
Public Types | |
enum | message_t { NONE, SOLVED, ERROR } |
Enum type for the message generated by the problem. More... | |
Public Member Functions | |
CostFunc () | |
Default Constructor. More... | |
virtual | ~CostFunc () |
virtual void | assert_parameter_correct (const blitz::Array< double, 1 > &x) const |
Checks that the new input parameters are correct. More... | |
virtual void | assert_parameter_set_correctly () const |
Checks that the parameters are set correctly. More... | |
virtual void | clear () |
Deletes data contents. More... | |
virtual double | cost ()=0 |
The cost function. More... | |
virtual double | cost_x (const blitz::Array< double, 1 > &x) |
The cost function with parameters. More... | |
virtual int | expected_parameter_size () const |
Returns the expected size of the parameters. More... | |
virtual message_t | message () const |
Returns a value of CostFunc::message_t type. More... | |
virtual const char *const | message_str () const |
Returns the string version of the problem message. More... | |
virtual int | num_cost_evaluations () const |
Returns the number of the times cost has been evaluated. More... | |
virtual int | parameter_size () const |
Returns the size of the parameters. More... | |
virtual void | parameters (const blitz::Array< double, 1 > &x) |
Sets the problem at a new point in the parameter space. More... | |
virtual blitz::Array< double, 1 > | parameters () const |
Returns the current parameters. More... | |
virtual bool | parameters_different (const blitz::Array< double, 1 > &x) const |
Checks whether or not new input parameters are different from the current ones. 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 | set (const ProblemState &s) |
Makes self a copy of the input state. More... | |
virtual void | zero_num_evaluations () |
Sets cost evaluation counter to zero. More... | |
Protected Member Functions | |
virtual void | increment_num_cost_evaluations () |
Increments (by 1) cost evaluation counter. More... | |
virtual void | set_num_cost_evaluations (int count) |
Sets the cost evaluation counter to a desired value. More... | |
Protected Attributes | |
message_t | mssg |
blitz::Array< double, 1 > | X |
The base class for all problem classes that implement a cost function.
The class CostFunc is the base class for all problem classes that implement a cost function (a scalar real function with a range that never includes negative numbers).
A cost function only (without derivatives of any order) can be optimized by methods such as the Sampling Method that do not require derivatives of any order.
Definition at line 20 of file cost_func.h.
Enum type for the message generated by the problem.
In general it is very difficult (probably not possible) to develop a general purpose stopping criterion for a general purpose optimization or curve fitting iterative algorithm. The stopping criterion could be very problem dependent. This enumerated type is used to send a message to the solver of a problem, and the iterative solver can optionally take the message into account in deciding how to proceed.
Enumerator | |
---|---|
NONE | There are no messages. |
SOLVED | The problem is solved. |
ERROR | There is an error in the problem. |
Definition at line 38 of file cost_func.h.
|
inline |
Default Constructor.
Definition at line 49 of file cost_func.h.
|
inlinevirtual |
Definition at line 54 of file cost_func.h.
|
virtualinherited |
Checks that the new input parameters are correct.
This method checks to see whether or not the new input parameters are correct. If the parameters are not correct then it throws an exception.
Definition at line 44 of file problem_state.cc.
|
inlinevirtualinherited |
Checks that the parameters are set correctly.
This method checks to see whether or not the parameters are set correctly. If the parameters are not set correctly then it throws an exception.
Definition at line 197 of file problem_state.h.
|
inlinevirtualinherited |
Deletes data contents.
This method deletes state. It must be reimplemented by other classes derived from this class to delete other saved components associated with the state as well.
Reimplemented in FullPhysics::NLLSProblemState, FullPhysics::ModelState, FullPhysics::CostFuncDiffState, and FullPhysics::CostFuncState.
Definition at line 100 of file problem_state.h.
|
pure virtual |
The cost function.
This method must be implemented by the classes derived from this class.
The parameters (the point in the parameter space) must have already been set before calling this method. The parameters are already set if parameters() method (see ProblemState class) or cost_x() method are already called successfully. If the parameters are already set, then this method returns the value of the cost function at the current set point.
Implemented in FullPhysics::NLLSProblem.
|
inlinevirtual |
The cost function with parameters.
This method also evaluates the cost function; however, it sets the problem at the input new point and then evaluates the cost function.
[in] | x | New set of parameters |
Definition at line 89 of file cost_func.h.
|
inlinevirtualinherited |
Returns the expected size of the parameters.
This method must be reimplemented by the problem class the inherits ProblemState. It is only in the context of an optimization problem that one knows what the size of the parameters (number of the dimensions of the parameter space) is.
This method is intentionally implemented here instead of being left as a pure virtual method. The intention is that the user to be able to create an object of this class or its derived classes for the purpose of preserving an older state of a problem if needed.
Reimplemented in FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, FullPhysics::NLLSProblemScaled, FullPhysics::ModelMeasureStandard, FullPhysics::ModelMeasureBard, FullPhysics::ModelMeasureMeyer, FullPhysics::FmNLLSProblem, FullPhysics::BardNLLSProblem, FullPhysics::BrownNLLSProblem, FullPhysics::FreudensteinRothNLLSProblem, FullPhysics::HelicalValleyNLLSProblem, FullPhysics::JennrichSampsonNLLSProblem, FullPhysics::MeyerNLLSProblem, FullPhysics::PowellNLLSProblem, FullPhysics::PowellSingularNLLSProblem, and FullPhysics::Rosenbrock2NLLSProblem.
Definition at line 185 of file problem_state.h.
|
inlineprotectedvirtual |
Increments (by 1) cost evaluation counter.
The developer of a derived class, where the true cost function evaluation is implemented, must also call this method when the cost function is evaluated.
It is possible to call this method in cost_x() method; however, at this level we do not know when the cost function gets truly evaluated.
The developer of a derived class can save the expensive components of a cost function evaluation and reuse them when cost is inquired and the parameters have not changed. Therefore, she has the options of calling increment_num_cost_evaluations()
If X1 and X2 are two different sets of parameters, then after the sequence of method calls
with the first design option mentioned above num_cost_evaluations() will return 4, but with the second option mentioned above num_cost_evaluations() will return 2.
Therefore, in my opinion it was best not to decide when to call this method at this level in CostFunc class.
Definition at line 198 of file cost_func.h.
|
inlinevirtual |
Returns a value of CostFunc::message_t type.
This method returns a problem generated message. The message is initialized as CostFunc::NONE. The implementation of a problem can optionally set it to other values as needed, and the solver of the problem can optionally take different course of actions for different messages.
It is assumed that the solver will not take any different course of action if the returned value is CostFunc::NONE. For other possible values check the comments on CostFunc::message_t.
Definition at line 127 of file cost_func.h.
|
virtual |
Returns the string version of the problem message.
If the method status() returns
then message_str() will return
respectively.
Definition at line 14 of file cost_func.cc.
|
inlinevirtual |
Returns the number of the times cost has been evaluated.
Definition at line 99 of file cost_func.h.
|
inlinevirtualinherited |
Returns the size of the parameters.
Definition at line 163 of file problem_state.h.
|
virtualinherited |
Sets the problem at a new point in the parameter space.
The method calls parameters_different() to determine whether or not the new parameters are different:
[in] | x | New set of parameters |
Reimplemented in FullPhysics::NLLSProblemScaled, FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, and FullPhysics::ModelMeasureStandard.
Definition at line 36 of file problem_state.cc.
|
inlinevirtualinherited |
Returns the current parameters.
Reimplemented in FullPhysics::NLLSProblemScaled, FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, and FullPhysics::ModelMeasureStandard.
Definition at line 153 of file problem_state.h.
|
virtualinherited |
Checks whether or not new input parameters are different from the current ones.
The methods checks to see whether or not the new input parameters (point in the parameter space) are different from the parameters maintained by the object for which the method is called.
If the size of the input parameters is not equal to the expected size of the parameters (check comments on expected_parameter_size), then the method will throw an exception.
If the object for which the method is called has currently no parameters set, then the method returns true. Otherwise, the method uses some algorithm to figure out when the difference is "big enough" to be considered different. If the method determines that the new input parameters are different from the current parameters, then it returns true, otherwise, it returns false.
[in] | x | New set of parameters |
Definition at line 9 of file problem_state.cc.
|
inlinevirtual |
Prints description of object.
Reimplemented from FullPhysics::ProblemState.
Reimplemented in FullPhysics::NLLSProblem, FullPhysics::CostFuncDiff, FullPhysics::NLLSProblemScaled, FullPhysics::NLLSMaxAPosteriori, FullPhysics::NLLSMaxLikelihood, FullPhysics::FmNLLSProblem, FullPhysics::BardNLLSProblem, FullPhysics::BrownNLLSProblem, FullPhysics::FreudensteinRothNLLSProblem, FullPhysics::HelicalValleyNLLSProblem, FullPhysics::JennrichSampsonNLLSProblem, FullPhysics::MeyerNLLSProblem, FullPhysics::PowellNLLSProblem, FullPhysics::PowellSingularNLLSProblem, and FullPhysics::Rosenbrock2NLLSProblem.
Definition at line 156 of file cost_func.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.
|
inlinevirtualinherited |
Makes self a copy of the input state.
This method makes the object, for which it is called, a copy of the input state.
[in] | s | another ProblemState |
Definition at line 88 of file problem_state.h.
|
inlineprotectedvirtual |
Sets the cost evaluation counter to a desired value.
This method sets the cost evaluation counter to a desired value. It is just provided if the developers of the derived classes have any use for it
[in] | count | Desired value for cost evaluation counter setting |
Definition at line 213 of file cost_func.h.
|
inlinevirtual |
Sets cost evaluation counter to zero.
Reimplemented in FullPhysics::CostFuncDiff.
Definition at line 107 of file cost_func.h.
|
protected |
Definition at line 163 of file cost_func.h.
|
protectedinherited |
Definition at line 222 of file problem_state.h.