ITK  4.2.0
Insight Segmentation and Registration Toolkit
itkRegularStepGradientDescentBaseOptimizer.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkRegularStepGradientDescentBaseOptimizer_h
19 #define __itkRegularStepGradientDescentBaseOptimizer_h
20 
21 #include "itkIntTypes.h"
23 
24 namespace itk
25 {
34 {
35 public:
41 
43  itkNewMacro(Self);
44 
48 
50  typedef enum {
51  GradientMagnitudeTolerance = 1,
52  StepTooSmall = 2,
53  ImageNotAvailable = 3,
54  CostFunctionError = 4,
55  MaximumNumberOfIterations = 5,
56  Unknown = 6
57  } StopConditionType;
58 
60  itkSetMacro(Maximize, bool);
61  itkGetConstReferenceMacro(Maximize, bool);
62  itkBooleanMacro(Maximize);
63  bool GetMinimize() const
64  { return !m_Maximize; }
65  void SetMinimize(bool v)
66  { this->SetMaximize(!v); }
67  void MinimizeOn(void)
68  { SetMaximize(false); }
69  void MinimizeOff(void)
70  { SetMaximize(true); }
72 
74  void StartOptimization(void);
75 
78  void ResumeOptimization(void);
79 
82  void StopOptimization(void);
83 
85  itkSetMacro(MaximumStepLength, double);
86  itkSetMacro(MinimumStepLength, double);
87  itkSetMacro(RelaxationFactor, double);
88  itkSetMacro(NumberOfIterations, SizeValueType);
89  itkSetMacro(GradientMagnitudeTolerance, double);
90  itkGetConstReferenceMacro(CurrentStepLength, double);
91  itkGetConstReferenceMacro(MaximumStepLength, double);
92  itkGetConstReferenceMacro(MinimumStepLength, double);
93  itkGetConstReferenceMacro(RelaxationFactor, double);
94  itkGetConstReferenceMacro(NumberOfIterations, SizeValueType);
95  itkGetConstReferenceMacro(GradientMagnitudeTolerance, double);
96  itkGetConstMacro(CurrentIteration, unsigned int);
97  itkGetConstReferenceMacro(StopCondition, StopConditionType);
98  itkGetConstReferenceMacro(Value, MeasureType);
99  itkGetConstReferenceMacro(Gradient, DerivativeType);
101 
103  virtual const std::string GetStopConditionDescription() const;
104 
105 protected:
108  void PrintSelf(std::ostream & os, Indent indent) const;
109 
113  virtual void AdvanceOneStep(void);
114 
120  virtual void StepAlongGradient(
121  double,
122  const DerivativeType &)
123  {
124  ExceptionObject ex;
125 
126  ex.SetLocation(__FILE__);
127  ex.SetDescription("This method MUST be overloaded in derived classes");
128  throw ex;
129  }
130 
131 private:
132  RegularStepGradientDescentBaseOptimizer(const Self &); //purposely not
133  // implemented
134  void operator=(const Self &); //purposely not
135 
136  // implemented
137 protected:
140 
141  bool m_Stop;
152  std::ostringstream m_StopConditionDescription;
153 };
154 } // end namespace itk
155 
156 #endif
157