ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGradientDescentOptimizer.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 itkGradientDescentOptimizer_h
19 #define itkGradientDescentOptimizer_h
20 
21 #include "itkIntTypes.h"
23 #include "ITKOptimizersExport.h"
24 #include <string>
25 namespace itk
26 {
52 class ITKOptimizers_EXPORT GradientDescentOptimizer:
54 {
55 public:
56  ITK_DISALLOW_COPY_AND_ASSIGN(GradientDescentOptimizer);
57 
63 
65  itkNewMacro(Self);
66 
69 
71  typedef enum {
73  MetricError
74  } StopConditionType;
75 
77  itkGetConstReferenceMacro(Maximize, bool);
78  itkSetMacro(Maximize, bool);
79  itkBooleanMacro(Maximize);
80  bool GetMinimize() const
81  { return !m_Maximize; }
82  void SetMinimize(bool v)
83  { this->SetMaximize(!v); }
84  void MinimizeOn()
85  { this->MaximizeOff(); }
86  void MinimizeOff()
87  { this->MaximizeOn(); }
89 
91  virtual void AdvanceOneStep();
92 
94  void StartOptimization() override;
95 
98  void ResumeOptimization();
99 
102  void StopOptimization();
103 
105  itkSetMacro(LearningRate, double);
106 
108  itkGetConstReferenceMacro(LearningRate, double);
109 
111  itkSetMacro(NumberOfIterations, SizeValueType);
112 
114  itkGetConstReferenceMacro(NumberOfIterations, SizeValueType);
115 
117  itkGetConstMacro(CurrentIteration, SizeValueType);
118 
120  itkGetConstReferenceMacro(Value, double);
121 
123  itkGetConstReferenceMacro(StopCondition, StopConditionType);
124  const std::string GetStopConditionDescription() const override;
126 
128  itkGetConstReferenceMacro(Gradient, DerivativeType);
129 
130 protected:
132  ~GradientDescentOptimizer() override = default;
133  void PrintSelf(std::ostream & os, Indent indent) const override;
134 
135  // made protected so subclass can access
136  DerivativeType m_Gradient;
137 
138  bool m_Maximize{false};
139 
140  double m_LearningRate{1.0};
141 
142 private:
143  bool m_Stop{false};
144  double m_Value{0.0};
145  StopConditionType m_StopCondition{MaximumNumberOfIterations};
146  SizeValueType m_NumberOfIterations{100};
147  SizeValueType m_CurrentIteration{0};
148  std::ostringstream m_StopConditionDescription;
149 };
150 } // end namespace itk
151 
152 #endif
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
Implement a gradient descent optimizer.
This class is a base for the Optimization methods that optimize a single valued function.
Control indentation during Print() invocation.
Definition: itkIndent.h:49