ITK  5.2.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  * 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 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 StopConditionReturnStringType = typename Superclass::StopConditionReturnStringType;
75 
77  using StopConditionDescriptionType = typename Superclass::StopConditionDescriptionType;
78 
80  using InternalComputationValueType = TInternalComputationValueType;
81 
83  using MetricType = typename Superclass::MetricType;
84  using MetricTypePointer = typename MetricType::Pointer;
85 
88 
90  using MeasureType = typename Superclass::MeasureType;
91 
92  using ScalesType = typename Superclass::ScalesType;
93 
94  using ParametersType = typename Superclass::ParametersType;
95 
98 
100  itkGetConstReferenceMacro(Gradient, DerivativeType);
101 
103  itkGetConstReferenceMacro(StopCondition, StopConditionObjectToObjectOptimizerEnum);
104 
106  void
107  SetNumberOfIterations(const SizeValueType numberOfIterations) override
108  {
109  itkDebugMacro("setting NumberOfIterations to " << numberOfIterations);
110  if (this->m_NumberOfIterations != numberOfIterations)
111  {
112  this->m_NumberOfIterations = numberOfIterations;
113  this->Modified();
114  }
115  }
117 
120  GetNumberOfIterations() const override
121  {
122  return this->m_NumberOfIterations;
123  }
124 
127  GetCurrentIteration() const override
128  {
129  return this->m_CurrentIteration;
130  }
131 
133  void
134  StartOptimization(bool doOnlyInitialization = false) override;
135 
139  virtual void
140  ResumeOptimization() = 0;
141 
144  virtual void
145  StopOptimization();
146 
148  const StopConditionReturnStringType
149  GetStopConditionDescription() const override;
150 
163  virtual void
164  ModifyGradientByScales();
165  virtual void
166  ModifyGradientByLearningRate();
168 
170 
176  virtual void
177  ModifyGradientByScalesOverSubRange(const IndexRangeType & subrange) = 0;
178 
187  virtual void
188  ModifyGradientByLearningRateOverSubRange(const IndexRangeType & subrange) = 0;
189 
190 protected:
193  ~GradientDescentOptimizerBasev4Template() override = default;
195 
200 
205 
212  TInternalComputationValueType m_MaximumStepSizeInPhysicalUnits;
213 
219 
225 
228 
231 
232  /* Common variables for optimization control and reporting */
233  bool m_Stop{ false };
236 
239  void
240  PrintSelf(std::ostream & os, Indent indent) const override;
241 
242 private:
243 };
244 
247 
248 } // end namespace itk
249 
250 #ifndef ITK_MANUAL_INSTANTIATION
251 # include "itkGradientDescentOptimizerBasev4.hxx"
252 #endif
253 
254 #endif
itk::GradientDescentOptimizerBasev4Template::m_Gradient
DerivativeType m_Gradient
Definition: itkGradientDescentOptimizerBasev4.h:238
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::MAXIMUM_NUMBER_OF_ITERATIONS
itkThreadedIndexedContainerPartitioner.h
itk::GradientDescentOptimizerBasev4Template::StopConditionDescriptionType
typename Superclass::StopConditionDescriptionType StopConditionDescriptionType
Definition: itkGradientDescentOptimizerBasev4.h:77
itk::GradientDescentOptimizerBasev4Template::m_UseConvergenceMonitoring
bool m_UseConvergenceMonitoring
Definition: itkGradientDescentOptimizerBasev4.h:218
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::CONVERGENCE_CHECKER_PASSED
itk::GradientDescentOptimizerBasev4Template::m_MaximumStepSizeInPhysicalUnits
TInternalComputationValueType m_MaximumStepSizeInPhysicalUnits
Definition: itkGradientDescentOptimizerBasev4.h:212
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::GradientDescentOptimizerBasev4Template::ParametersType
typename Superclass::ParametersType ParametersType
Definition: itkGradientDescentOptimizerBasev4.h:94
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::COSTFUNCTION_ERROR
itk::GradientDescentOptimizerBasev4Template::IndexRangeType
ThreadedIndexedContainerPartitioner::IndexRangeType IndexRangeType
Definition: itkGradientDescentOptimizerBasev4.h:169
itkWindowConvergenceMonitoringFunction.h
itk::GradientDescentOptimizerBasev4Template::m_StopCondition
StopConditionObjectToObjectOptimizerEnum m_StopCondition
Definition: itkGradientDescentOptimizerBasev4.h:234
itk::GradientDescentOptimizerBasev4Template::MetricType
typename Superclass::MetricType MetricType
Definition: itkGradientDescentOptimizerBasev4.h:83
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::GradientDescentOptimizerBasev4Template::m_StopConditionDescription
StopConditionDescriptionType m_StopConditionDescription
Definition: itkGradientDescentOptimizerBasev4.h:235
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer
StopConditionObjectToObjectOptimizer
Definition: itkObjectToObjectOptimizerBase.h:42
itk::GradientDescentOptimizerBasev4Template::m_ConvergenceWindowSize
SizeValueType m_ConvergenceWindowSize
Definition: itkGradientDescentOptimizerBasev4.h:224
itk::GradientDescentOptimizerBasev4Template::SetNumberOfIterations
void SetNumberOfIterations(const SizeValueType numberOfIterations) override
Definition: itkGradientDescentOptimizerBasev4.h:107
itk::GradientDescentOptimizerBasev4Template::m_ModifyGradientByScalesThreader
DomainThreader< ThreadedIndexedContainerPartitioner, Self >::Pointer m_ModifyGradientByScalesThreader
Definition: itkGradientDescentOptimizerBasev4.h:229
itk::GradientDescentOptimizerBasev4Template::m_ConvergenceMonitoring
ConvergenceMonitoringType::Pointer m_ConvergenceMonitoring
Definition: itkGradientDescentOptimizerBasev4.h:227
itk::Function::WindowConvergenceMonitoringFunction
Class which monitors convergence during the course of optimization.
Definition: itkWindowConvergenceMonitoringFunction.h:39
itk::GradientDescentOptimizerBasev4Template::StopConditionReturnStringType
typename Superclass::StopConditionReturnStringType StopConditionReturnStringType
Definition: itkGradientDescentOptimizerBasev4.h:74
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::GetCurrentIteration
SizeValueType GetCurrentIteration() const override
Definition: itkGradientDescentOptimizerBasev4.h:127
itk::GradientDescentOptimizerBasev4Template
Definition: itkGradientDescentOptimizerBasev4.h:40
itk::GradientDescentOptimizerBasev4Template::m_DoEstimateLearningRateOnce
bool m_DoEstimateLearningRateOnce
Definition: itkGradientDescentOptimizerBasev4.h:204
itk::GradientDescentOptimizerBasev4Template::MetricTypePointer
typename MetricType::Pointer MetricTypePointer
Definition: itkGradientDescentOptimizerBasev4.h:84
itk::GradientDescentOptimizerBasev4Template::GetNumberOfIterations
SizeValueType GetNumberOfIterations() const override
Definition: itkGradientDescentOptimizerBasev4.h:120
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::GradientDescentOptimizerBasev4Template::m_DoEstimateLearningRateAtEachIteration
bool m_DoEstimateLearningRateAtEachIteration
Definition: itkGradientDescentOptimizerBasev4.h:199
itk::ThreadedIndexedContainerPartitioner::IndexRangeType
DomainType IndexRangeType
Definition: itkThreadedIndexedContainerPartitioner.h:66
itk::GradientDescentOptimizerBasev4Template::DerivativeType
typename Superclass::DerivativeType DerivativeType
Definition: itkGradientDescentOptimizerBasev4.h:87
StopCondition
itk::GradientDescentOptimizerBasev4Template::m_ModifyGradientByLearningRateThreader
DomainThreader< ThreadedIndexedContainerPartitioner, Self >::Pointer m_ModifyGradientByLearningRateThreader
Definition: itkGradientDescentOptimizerBasev4.h:230
itk::ObjectToObjectOptimizerBaseTemplateEnums::StopConditionObjectToObjectOptimizer::STEP_TOO_SMALL
itk::GradientDescentOptimizerBasev4Template::ScalesType
typename Superclass::ScalesType ScalesType
Definition: itkGradientDescentOptimizerBasev4.h:92
itkDomainThreader.h
itk::SizeValueType
unsigned long SizeValueType
Definition: itkIntTypes.h:83
itk::GradientDescentOptimizerBasev4Template::MeasureType
typename Superclass::MeasureType MeasureType
Definition: itkGradientDescentOptimizerBasev4.h:90