ITK  4.13.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 #include "ITKOptimizersExport.h"
24 
25 namespace itk
26 {
33 class ITKOptimizers_EXPORT RegularStepGradientDescentBaseOptimizer:
35 {
36 public:
42 
44  itkNewMacro(Self);
45 
49 
51  typedef enum {
52  GradientMagnitudeTolerance = 1,
53  StepTooSmall = 2,
54  ImageNotAvailable = 3,
55  CostFunctionError = 4,
56  MaximumNumberOfIterations = 5,
57  Unknown = 6
58  } StopConditionType;
59 
61  itkSetMacro(Maximize, bool);
62  itkGetConstReferenceMacro(Maximize, bool);
63  itkBooleanMacro(Maximize);
64  bool GetMinimize() const
65  { return !m_Maximize; }
66  void SetMinimize(bool v)
67  { this->SetMaximize(!v); }
68  void MinimizeOn(void)
69  { SetMaximize(false); }
70  void MinimizeOff(void)
71  { SetMaximize(true); }
73 
75  virtual void StartOptimization(void) ITK_OVERRIDE;
76 
79  void ResumeOptimization();
80 
83  void StopOptimization();
84 
86  itkSetMacro(MaximumStepLength, double);
87  itkSetMacro(MinimumStepLength, double);
88  itkSetMacro(RelaxationFactor, double);
89  itkSetMacro(NumberOfIterations, SizeValueType);
90  itkSetMacro(GradientMagnitudeTolerance, double);
91  itkGetConstReferenceMacro(CurrentStepLength, double);
92  itkGetConstReferenceMacro(MaximumStepLength, double);
93  itkGetConstReferenceMacro(MinimumStepLength, double);
94  itkGetConstReferenceMacro(RelaxationFactor, double);
95  itkGetConstReferenceMacro(NumberOfIterations, SizeValueType);
96  itkGetConstReferenceMacro(GradientMagnitudeTolerance, double);
97  itkGetConstMacro(CurrentIteration, unsigned int);
98  itkGetConstReferenceMacro(StopCondition, StopConditionType);
99  itkGetConstReferenceMacro(Value, MeasureType);
100  itkGetConstReferenceMacro(Gradient, DerivativeType);
102 
104  virtual const std::string GetStopConditionDescription() const ITK_OVERRIDE;
105 
106 protected:
108  virtual ~RegularStepGradientDescentBaseOptimizer() ITK_OVERRIDE {}
109  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
110 
114  virtual void AdvanceOneStep();
115 
121  virtual void StepAlongGradient(
122  double,
123  const DerivativeType &)
124  {
125  ExceptionObject ex;
126 
127  ex.SetLocation(__FILE__);
128  ex.SetDescription("This method MUST be overloaded in derived classes");
129  throw ex;
130  }
131 
132 private:
133  ITK_DISALLOW_COPY_AND_ASSIGN(RegularStepGradientDescentBaseOptimizer);
134 
135 protected:
136  DerivativeType m_Gradient;
137  DerivativeType m_PreviousGradient;
138 
139  bool m_Stop;
141  MeasureType m_Value;
150  std::ostringstream m_StopConditionDescription;
151 };
152 } // end namespace itk
153 
154 #endif
Light weight base class for most itk classes.
virtual void SetDescription(const std::string &s)
virtual void SetLocation(const std::string &s)
This class is a base for the Optimization methods that optimize a single valued function.
unsigned long SizeValueType
Definition: itkIntTypes.h:143
Standard exception handling object.
virtual void StepAlongGradient(double, const DerivativeType &)
Control indentation during Print() invocation.
Definition: itkIndent.h:49