20 #ifndef MIRTK_LineSearch_H 21 #define MIRTK_LineSearch_H 23 #include "mirtk/LocalOptimizer.h" 25 #include "mirtk/Math.h" 55 mirtkPublicAggregateMacro(
double, Direction);
58 mirtkPublicAttributeMacro(
bool, Revert);
61 mirtkPublicAttributeMacro(
double, CurrentValue);
64 mirtkPublicAttributeMacro(
int, NumberOfIterations);
67 mirtkPublicAttributeMacro(
double, MinStepLength);
70 mirtkPublicAttributeMacro(
double, MaxStepLength);
73 mirtkPublicAttributeMacro(
double, StepLengthUnit);
76 mirtkPublicAttributeMacro(
double, StepLength);
112 virtual bool Set(
const char *,
const char *);
125 virtual double Run() = 0;
133 #define mirtkLineSearchMacro(name, strategy) \ 134 mirtkObjectMacro(name); \ 137 virtual mirtk::OptimizationMethod OptimizationMethod() const \ 139 return OM_LineSearch; \ 142 virtual mirtk::LineSearchStrategy Strategy() const { return strategy; } \ 155 case LS_None: str =
"None";
break;
157 case LS_Brent: str =
"Brent";
break;
158 default: str =
"Unknown";
break;
168 if (strcmp(str,
"None") == 0)
return true;
169 if (strcmp(str,
"linmin") == 0 || strcmp(str,
"LinMin") == 0) m =
LS_Brent;
184 if (
IsNaN(_CurrentValue)) {
185 Function()->Update(
false);
186 _CurrentValue = Function()->Value();
188 return _CurrentValue;
194 #endif // MIRTK_LineSearch_H
LineSearch(ObjectiveFunction *=NULL)
Constructor.
virtual ~LineSearch()
Destructor.
MIRTKCU_API bool IsNaN(double x)
Check if floating point value is not a number (NaN)
Inexact line search with adaptive step length.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
virtual void Initialize()
Initialize optimization.
virtual bool Set(const char *, const char *)
Set parameter value from string.
LineSearch & operator=(const LineSearch &)
Assignment operator.
Numerical recipes linmin function using Brent's method.
string ToString(const EnergyMeasure &value, int w, char c, bool left)
Convert energy measure enumeration value to string.
static LineSearch * New(LineSearchStrategy &, ObjectiveFunction *=NULL)
Instantiate line search implementing specified strategy.
bool FromString(const char *str, EnergyMeasure &value)
Convert energy measure string to enumeration value.
virtual LineSearchStrategy Strategy() const =0
Line search strategy implemented by this line search.
LineSearchStrategy
Enumeration of available line search strategies.