InexactLineSearch.h
1 /*
2  * Medical Image Registration ToolKit (MIRTK)
3  *
4  * Copyright 2013-2015 Imperial College London
5  * Copyright 2013-2015 Andreas Schuh
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 #ifndef MIRTK_InexactLineSearch_H
21 #define MIRTK_InexactLineSearch_H
22 
23 #include "mirtk/LineSearch.h"
24 
25 
26 namespace mirtk {
27 
28 
29 /**
30  * Searches sufficiently optimal step length along search direction
31  *
32  * This local optimizer implements an inexact line search with adaptive step
33  * size control, increasing the step size while steps are accepted, and
34  * decreasing it when a step did not yield a sufficient improvement.
35  */
37 {
38  mirtkAbstractMacro(InexactLineSearch);
39 
40  // ---------------------------------------------------------------------------
41  // Attributes
42 
43  /// Maximum number consecutive rejected steps
44  mirtkPublicAttributeMacro(int, MaxRejectedStreak);
45 
46  /// Whether to start new search using step length of previous search
47  mirtkPublicAttributeMacro(bool, ReusePreviousStepLength);
48 
49  /// Whether (reused) step length is strictly limited by [min, max]
50  ///
51  /// 0: Step length is allowed to exceed max which may be the case when the
52  /// previously accumulated total step length is being reused.
53  /// 1: Incremental steps are strictly limited to [min, max].
54  /// 2: Accumulated total step length is strictly limited to [min, max].
55  /// 3: Equivalent to 2, but indicates that both incremental and accumulated
56  /// step length ranges have been restricted.
57  mirtkPublicAttributeMacro(int, StrictStepLengthRange);
58 
59  /// Whether to refuse any function parameter sign changes
60  ///
61  /// If \c false for a particular function parameter, the line search sets
62  /// the function parameter to zero whenever the sign of the parameter would
63  /// change when taking a full step along the scaled gradient direction.
64  mirtkPublicAggregateMacro(bool, AllowSignChange);
65 
66 protected:
67 
68  /// Previous function parameters
70 
71  /// Line search direction scaled by current step length
73 
74 private:
75 
76  /// Copy attributes of this class from another instance
77  void CopyAttributes(const InexactLineSearch &);
78 
79  // ---------------------------------------------------------------------------
80  // Construction/Destruction
81 public:
82 
83  using LineSearch::Function;
84 
85  /// Constructor
87 
88  /// Copy constructor
90 
91  /// Assignment operator
93 
94  /// Destructor
95  virtual ~InexactLineSearch();
96 
97  /// Set objective function
98  virtual void Function(ObjectiveFunction *);
99 
100  // ---------------------------------------------------------------------------
101  // Parameters
102  using LineSearch::Parameter;
103 
104  /// Set parameter value from string
105  virtual bool Set(const char *, const char *);
106 
107  /// Get parameters as key/value as string map
108  virtual ParameterList Parameter() const;
109 
110  // ---------------------------------------------------------------------------
111  // Optimization
112 protected:
113 
114  /// Take step in search direction
115  ///
116  /// \returns Maximum change of DoF
117  double Advance(double);
118 
119  /// Revert step in search direction
120  void Retreat(double);
121 
122  /// Evaluate objective function for a given step length
123  ///
124  /// This function takes a step in the given direction with the specified
125  /// step length and evaluates the objective function value at this point.
126  /// It then restores the function parameters by reverting the step again.
127  ///
128  /// \returns Objective function value at new point.
129  double Value(double, double * = NULL);
130 
131 };
132 
133 
134 } // namespace mirtk
135 
136 #endif // MIRTK_InexactLineSearch_H
InexactLineSearch(ObjectiveFunction *=NULL)
Constructor.
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
virtual ~InexactLineSearch()
Destructor.
double * _ScaledDirection
Line search direction scaled by current step length.
Array< Pair< string, string > > ParameterList
Ordered list of parameter name/value pairs.
Definition: Object.h:38
virtual ParameterList Parameter() const
Get parameters as key/value as string map.
double * _CurrentDoFValues
Previous function parameters.
Definition: IOConfig.h:41
double Advance(double)
virtual void Function(ObjectiveFunction *)
Set objective function.
virtual bool Set(const char *, const char *)
Set parameter value from string.
double Value(double, double *=NULL)
InexactLineSearch & operator=(const InexactLineSearch &)
Assignment operator.
void Retreat(double)
Revert step in search direction.