20 #ifndef MIRTK_LocalOptimizer_H 21 #define MIRTK_LocalOptimizer_H 23 #include "mirtk/Observable.h" 25 #include "mirtk/Math.h" 26 #include "mirtk/Array.h" 27 #include "mirtk/Queue.h" 28 #include "mirtk/OptimizationMethod.h" 29 #include "mirtk/ObjectiveFunction.h" 30 #include "mirtk/ObjectFactory.h" 37 class StoppingCriterion;
54 mirtkPublicAttributeMacro(
int, NumberOfSteps);
57 mirtkPublicAttributeMacro(
double, Epsilon);
60 mirtkPublicAttributeMacro(
double, Delta);
63 mirtkReadOnlyAttributeMacro(Deque<double>, LastValues);
66 mirtkReadOnlyAttributeMacro(
double, LastValuesSlope);
69 mirtkPublicAttributeMacro(
int, NumberOfLastValues);
72 mirtkReadOnlyAttributeMacro(
bool,
Converged);
75 Array<class StoppingCriterion *> _StoppingCriteria;
117 virtual bool Set(
const char *,
const char *);
169 virtual bool Converged(
int iter,
double value,
const double *delta);
180 virtual double Run() = 0;
189 #define mirtkOptimizerMacro(name, method) \ 190 mirtkObjectMacro(name); \ 193 static enum OptimizationMethod ID() { return method; } \ 195 virtual enum OptimizationMethod OptimizationMethod() const { return method; }\ 200 #define mirtkRegisterOptimizerMacro(type) \ 201 mirtk::LocalOptimizer::Factory() \ 202 .Register(type::ID(), type::NameOfType(), \ 203 mirtk::New<mirtk::LocalOptimizer, type>) 206 #define mirtkAutoRegisterOptimizerMacro(type) \ 207 mirtkAutoRegisterObjectTypeMacro(mirtk::LocalOptimizer::Factory(), \ 208 mirtk::OptimizationMethod, type::ID(), \ 209 mirtk::LocalOptimizer, type) 219 if (
IsInf(value))
return false;
220 return prev - value > _Epsilon;
226 #endif // MIRTK_LocalOptimizer_H LocalOptimizer(ObjectiveFunction *=NULL)
Constructor.
static FactoryType & Factory()
Get global optimizer factory instance.
void ClearStoppingCriteria()
Delete all stopping criteria.
class StoppingCriterion * StoppingCriterion(int)
Get the n-th stopping criterion.
void RemoveStoppingCriterion(StoppingCriterion *)
Remove stopping criterion and revoke ownership of the object.
ObjectFactory< enum OptimizationMethod, LocalOptimizer > FactoryType
Type of optimizer factory.
virtual bool Converged(int iter, double value, const double *delta)
MIRTKCU_API bool IsNaN(double x)
Check if floating point value is not a number (NaN)
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
static LocalOptimizer * New(enum OptimizationMethod, ObjectiveFunction *=NULL)
Construct optimizer.
int NumberOfStoppingCriteria() const
Get number of stopping criteria.
virtual bool Set(const char *, const char *)
Set parameter value from string.
MIRTKCU_API bool IsInf(double x)
Check if floating point value represents infinity.
virtual ~LocalOptimizer()
Destructor.
void AddStoppingCriterion(StoppingCriterion *)
Add stopping criterion and take over ownership of the object.
virtual enum OptimizationMethod OptimizationMethod() const =0
Optimization method implemented by this optimizer.
virtual ParameterList Parameter() const
Get parameter name/value pairs.
bool IsImprovement(double prev, double value) const
OptimizationMethod
Enumeration of available optimization methods.
virtual void Initialize()
Initialize optimization.
LocalOptimizer & operator=(const LocalOptimizer &)
Assignment operator.