ITK  5.4.0
Insight Toolkit
itkGradientDescentOptimizerBasev4.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 itkGradientDescentOptimizerBasev4_h
19 #define itkGradientDescentOptimizerBasev4_h
20 
24 #include "itkDomainThreader.h"
25 
26 namespace itk
27 {
39 template <typename TInternalComputationValueType>
40 class ITK_TEMPLATE_EXPORT GradientDescentOptimizerBasev4Template
41  : public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_MOVE(GradientDescentOptimizerBasev4Template);
45 
51 
54 
55 #if !defined(ITK_LEGACY_REMOVE)
56 
57  static constexpr itk::StopConditionObjectToObjectOptimizerEnum MAXIMUM_NUMBER_OF_ITERATIONS =
59  static constexpr itk::StopConditionObjectToObjectOptimizerEnum COSTFUNCTION_ERROR =
61  static constexpr itk::StopConditionObjectToObjectOptimizerEnum UPDATE_PARAMETERS_ERROR =
63  static constexpr itk::StopConditionObjectToObjectOptimizerEnum STEP_TOO_SMALL =
65  static constexpr itk::StopConditionObjectToObjectOptimizerEnum CONVERGENCE_CHECKER_PASSED =
67  static constexpr itk::StopConditionObjectToObjectOptimizerEnum GRADIENT_MAGNITUDE_TOLEARANCE =
69  static constexpr itk::StopConditionObjectToObjectOptimizerEnum OTHER_ERROR =
71 #endif
72 
74  using typename Superclass::StopConditionReturnStringType;
75 
77  using typename Superclass::StopConditionDescriptionType;
78 
80  using InternalComputationValueType = TInternalComputationValueType;
81 
83  using typename Superclass::MetricType;
85 
87  using typename Superclass::DerivativeType;
88 
90  using typename Superclass::MeasureType;
91 
92  using typename Superclass::ScalesType;
93 
94  using typename Superclass::ParametersType;
95 
98 
100  itkGetConstReferenceMacro(Gradient, DerivativeType);
101 
103  itkGetConstReferenceMacro(StopCondition, StopConditionObjectToObjectOptimizerEnum);
104 
106  void
107  StartOptimization(bool doOnlyInitialization = false) override;
108 
112  virtual void
113  ResumeOptimization() = 0;
114 
117  virtual void
118  StopOptimization();
119 
122  GetStopConditionDescription() const override;
123 
136  virtual void
137  ModifyGradientByScales();
138  virtual void
139  ModifyGradientByLearningRate();
143 
149  virtual void
150  ModifyGradientByScalesOverSubRange(const IndexRangeType & subrange) = 0;
151 
160  virtual void
161  ModifyGradientByLearningRateOverSubRange(const IndexRangeType & subrange) = 0;
162 
163 protected:
166  ~GradientDescentOptimizerBasev4Template() override = default;
172  bool m_DoEstimateLearningRateAtEachIteration{};
173 
177  bool m_DoEstimateLearningRateOnce{};
178 
185  TInternalComputationValueType m_MaximumStepSizeInPhysicalUnits{};
186 
191  bool m_UseConvergenceMonitoring{};
192 
197  SizeValueType m_ConvergenceWindowSize{};
198 
200  typename ConvergenceMonitoringType::Pointer m_ConvergenceMonitoring{};
201 
202  typename DomainThreader<ThreadedIndexedContainerPartitioner, Self>::Pointer m_ModifyGradientByScalesThreader{};
203  typename DomainThreader<ThreadedIndexedContainerPartitioner, Self>::Pointer m_ModifyGradientByLearningRateThreader{};
204 
205  /* Common variables for optimization control and reporting */
206  bool m_Stop{ false };
208  StopConditionDescriptionType m_StopConditionDescription{};
209 
211  DerivativeType m_Gradient{};
212  void
213  PrintSelf(std::ostream & os, Indent indent) const override;
214 
215 private:
216 };
217 
220 
221 } // end namespace itk
222 
223 #ifndef ITK_MANUAL_INSTANTIATION
224 # include "itkGradientDescentOptimizerBasev4.hxx"
225 #endif
226 
227 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::MAXIMUM_NUMBER_OF_ITERATIONS
itkThreadedIndexedContainerPartitioner.h
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::CONVERGENCE_CHECKER_PASSED
itk::ObjectToObjectOptimizerBaseTemplate::StopConditionReturnStringType
std::string StopConditionReturnStringType
Definition: itkObjectToObjectOptimizerBase.h:148
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::GRADIENT_MAGNITUDE_TOLEARANCE
itk::GradientDescentOptimizerBasev4Template
class ITK_FORWARD_EXPORT GradientDescentOptimizerBasev4Template
Definition: itkGradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader.h:27
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::COSTFUNCTION_ERROR
itk::GradientDescentOptimizerBasev4Template::IndexRangeType
ThreadedIndexedContainerPartitioner::IndexRangeType IndexRangeType
Definition: itkGradientDescentOptimizerBasev4.h:142
itkWindowConvergenceMonitoringFunction.h
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer
StopConditionObjectToObjectOptimizer
Definition: itkObjectToObjectOptimizerBase.h:42
itkOverrideGetNameOfClassMacro
itkOverrideGetNameOfClassMacro(AddImageFilter)
itk::Function::WindowConvergenceMonitoringFunction
Class which monitors convergence during the course of optimization.
Definition: itkWindowConvergenceMonitoringFunction.h:39
itk::GradientDescentOptimizerBasev4Template::InternalComputationValueType
TInternalComputationValueType InternalComputationValueType
Definition: itkGradientDescentOptimizerBasev4.h:80
itk::ObjectToObjectOptimizerBaseTemplate::DerivativeType
typename MetricType::DerivativeType DerivativeType
Definition: itkObjectToObjectOptimizerBase.h:139
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::UPDATE_PARAMETERS_ERROR
itk::GradientDescentOptimizerBasev4Template
Definition: itkGradientDescentOptimizerBasev4.h:40
itk::GradientDescentOptimizerBasev4Template::MetricTypePointer
typename MetricType::Pointer MetricTypePointer
Definition: itkGradientDescentOptimizerBasev4.h:84
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::OTHER_ERROR
itkObjectToObjectOptimizerBase.h
itk::ObjectToObjectOptimizerBaseTemplate
Abstract base for object-to-object optimizers.
Definition: itkObjectToObjectOptimizerBase.h:113
itk::ObjectToObjectOptimizerBaseTemplate::StopConditionDescriptionType
std::ostringstream StopConditionDescriptionType
Definition: itkObjectToObjectOptimizerBase.h:151
itk::ThreadedIndexedContainerPartitioner::IndexRangeType
DomainType IndexRangeType
Definition: itkThreadedIndexedContainerPartitioner.h:66
StopCondition
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::STEP_TOO_SMALL
itkDomainThreader.h
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83