ITK  6.0.0
Insight Toolkit
itkRegularStepGradientDescentBaseOptimizer.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
25namespace itk
26{
32{
33public:
38 enum class StopCondition : uint8_t
39 {
40 GradientMagnitudeTolerance = 1,
41 StepTooSmall = 2,
42 ImageNotAvailable = 3,
43 CostFunctionError = 4,
44 MaximumNumberOfIterations = 5,
45 Unknown = 6
46 };
47};
48// Define how to print enumeration
49extern ITKOptimizers_EXPORT std::ostream &
51
59{
60public:
61 ITK_DISALLOW_COPY_AND_MOVE(RegularStepGradientDescentBaseOptimizer);
62
68
70 itkNewMacro(Self);
71
73 itkOverrideGetNameOfClassMacro(RegularStepGradientDescentBaseOptimizer);
74
76#if !defined(ITK_LEGACY_REMOVE)
77 // We need to expose the enum values at the class level
78 // for backwards compatibility
79 static constexpr StopConditionEnum GradientMagnitudeTolerance = StopConditionEnum::GradientMagnitudeTolerance;
80 static constexpr StopConditionEnum StepTooSmall = StopConditionEnum::StepTooSmall;
81 static constexpr StopConditionEnum ImageNotAvailable = StopConditionEnum::ImageNotAvailable;
82 static constexpr StopConditionEnum CostFunctionError = StopConditionEnum::CostFunctionError;
83 static constexpr StopConditionEnum MaximumNumberOfIterations = StopConditionEnum::MaximumNumberOfIterations;
84 static constexpr StopConditionEnum Unknown = StopConditionEnum::Unknown;
85#endif
87 itkSetMacro(Maximize, bool);
88 itkGetConstReferenceMacro(Maximize, bool);
89 itkBooleanMacro(Maximize);
90 bool
92 {
93 return !m_Maximize;
94 }
95 void
97 {
98 this->SetMaximize(!v);
99 }
100 void
102 {
103 SetMaximize(false);
104 }
105 void
107 {
108 SetMaximize(true);
109 }
113 void
115
118 void
120
123 void
125
127 itkSetMacro(MaximumStepLength, double);
128 itkSetMacro(MinimumStepLength, double);
129 itkSetMacro(RelaxationFactor, double);
130 itkSetMacro(NumberOfIterations, SizeValueType);
131 itkSetMacro(GradientMagnitudeTolerance, double);
132 itkGetConstReferenceMacro(CurrentStepLength, double);
133 itkGetConstReferenceMacro(MaximumStepLength, double);
134 itkGetConstReferenceMacro(MinimumStepLength, double);
135 itkGetConstReferenceMacro(RelaxationFactor, double);
136 itkGetConstReferenceMacro(NumberOfIterations, SizeValueType);
137 itkGetConstReferenceMacro(GradientMagnitudeTolerance, double);
138 itkGetConstMacro(CurrentIteration, unsigned int);
139 itkGetConstReferenceMacro(StopCondition, StopConditionEnum);
140 itkGetConstReferenceMacro(Value, MeasureType);
141 itkGetConstReferenceMacro(Gradient, DerivativeType);
145 std::string
147
148protected:
151 void
152 PrintSelf(std::ostream & os, Indent indent) const override;
153
157 virtual void
159
165 virtual void
167 {
168 ExceptionObject ex;
169
170 ex.SetLocation(__FILE__);
171 ex.SetDescription("This method MUST be overloaded in derived classes");
172 throw ex;
173 }
174
175private:
176protected:
177 DerivativeType m_Gradient{};
178 DerivativeType m_PreviousGradient{};
179
180 bool m_Stop{ false };
181 bool m_Maximize{};
182 MeasureType m_Value{};
183 double m_GradientMagnitudeTolerance{};
184 double m_MaximumStepLength{};
185 double m_MinimumStepLength{};
186 double m_CurrentStepLength{};
187 double m_RelaxationFactor{};
188 StopConditionEnum m_StopCondition{};
189 SizeValueType m_NumberOfIterations{};
190 SizeValueType m_CurrentIteration{};
191 std::ostringstream m_StopConditionDescription{};
192};
193} // end namespace itk
194
195#endif
Array class with size defined at construction time.
Definition: itkArray.h:48
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Contains all enum classes for RegularStepGradientDescentBaseOptimizer class.
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void StepAlongGradient(double, const DerivativeType &)
std::string GetStopConditionDescription() const override
~RegularStepGradientDescentBaseOptimizer() override=default
This class is a base for the Optimization methods that optimize a single valued function.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
ITKCommon_EXPORT std::ostream & operator<<(std::ostream &out, typename AnatomicalOrientation::CoordinateEnum value)
unsigned long SizeValueType
Definition: itkIntTypes.h:86