ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkGradientDescentOptimizerBasev4.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 itkGradientDescentOptimizerBasev4_h
19 #define itkGradientDescentOptimizerBasev4_h
20 
24 #include "itkDomainThreader.h"
25 
26 namespace itk
27 {
38 template<typename TInternalComputationValueType>
39 class ITK_TEMPLATE_EXPORT GradientDescentOptimizerBasev4Template
40  : public ObjectToObjectOptimizerBaseTemplate<TInternalComputationValueType>
41 {
42 public:
43  ITK_DISALLOW_COPY_AND_ASSIGN(GradientDescentOptimizerBasev4Template);
44 
50 
53 
55  typedef enum {
62  OTHER_ERROR
63  } StopConditionType;
64 
66  using StopConditionReturnStringType = typename Superclass::StopConditionReturnStringType;
67 
69  using StopConditionDescriptionType = typename Superclass::StopConditionDescriptionType;
70 
72  using InternalComputationValueType = TInternalComputationValueType;
73 
75  using MetricType = typename Superclass::MetricType;
76  using MetricTypePointer = typename MetricType::Pointer;
77 
80 
82  using MeasureType = typename Superclass::MeasureType;
83 
84  using ScalesType = typename Superclass::ScalesType;
85 
86  using ParametersType = typename Superclass::ParametersType;
87 
90 
92  itkGetConstReferenceMacro( Gradient, DerivativeType );
93 
95  itkGetConstReferenceMacro(StopCondition, StopConditionType);
96 
98  void SetNumberOfIterations( const SizeValueType numberOfIterations ) override
99  {
100  itkDebugMacro("setting NumberOfIterations to " << numberOfIterations );
101  if ( this->m_NumberOfIterations != numberOfIterations)
102  {
103  this->m_NumberOfIterations = numberOfIterations;
104  this->Modified();
105  }
106  }
108 
111  {
112  return this->m_NumberOfIterations;
113  }
114 
117  {
118  return this->m_CurrentIteration;
119  }
120 
122  void StartOptimization( bool doOnlyInitialization = false ) override;
123 
127  virtual void ResumeOptimization() = 0;
128 
131  virtual void StopOptimization();
132 
134  const StopConditionReturnStringType GetStopConditionDescription() const override;
135 
148  virtual void ModifyGradientByScales();
149  virtual void ModifyGradientByLearningRate();
151 
153 
159  virtual void ModifyGradientByScalesOverSubRange( const IndexRangeType& subrange ) = 0;
160 
169  virtual void ModifyGradientByLearningRateOverSubRange( const IndexRangeType& subrange ) = 0;
170 
171 protected:
172 
175  ~GradientDescentOptimizerBasev4Template() override = default;
177 
182 
187 
194  TInternalComputationValueType m_MaximumStepSizeInPhysicalUnits;
195 
201 
207 
210 
213 
214  /* Common variables for optimization control and reporting */
215  bool m_Stop{false};
218 
221  void PrintSelf(std::ostream & os, Indent indent) const override;
222 
223 private:
224 
225 };
226 
229 
230 } // end namespace itk
231 
232 #ifndef ITK_MANUAL_INSTANTIATION
233 #include "itkGradientDescentOptimizerBasev4.hxx"
234 #endif
235 
236 #endif
Light weight base class for most itk classes.
unsigned long SizeValueType
Definition: itkIntTypes.h:83
typename MetricType::DerivativeType DerivativeType
DomainThreader< ThreadedIndexedContainerPartitioner, Self >::Pointer m_ModifyGradientByLearningRateThreader
Class which monitors convergence during the course of optimization.
typename Superclass::StopConditionDescriptionType StopConditionDescriptionType
typename Superclass::StopConditionReturnStringType StopConditionReturnStringType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetNumberOfIterations(const SizeValueType numberOfIterations) override
DomainThreader< ThreadedIndexedContainerPartitioner, Self >::Pointer m_ModifyGradientByScalesThreader
ThreadedIndexedContainerPartitioner::IndexRangeType IndexRangeType
Abstract base for object-to-object optimizers.