ITK  4.13.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:
48 
51 
53  typedef enum {
60  OTHER_ERROR
61  } StopConditionType;
62 
64  typedef typename Superclass::StopConditionReturnStringType StopConditionReturnStringType;
65 
68 
70  typedef TInternalComputationValueType InternalComputationValueType;
71 
73  typedef typename Superclass::MetricType MetricType;
74  typedef typename MetricType::Pointer MetricTypePointer;
75 
78 
81 
82  typedef typename Superclass::ScalesType ScalesType;
83 
84  typedef typename Superclass::ParametersType ParametersType;
85 
89 
91  itkGetConstReferenceMacro( Gradient, DerivativeType );
92 
94  itkGetConstReferenceMacro(StopCondition, StopConditionType);
95 
97  virtual void SetNumberOfIterations( const SizeValueType numberOfIterations ) ITK_OVERRIDE
98  {
99  itkDebugMacro("setting NumberOfIterations to " << numberOfIterations );
100  if ( this->m_NumberOfIterations != numberOfIterations)
101  {
102  this->m_NumberOfIterations = numberOfIterations;
103  this->Modified();
104  }
105  }
107 
109  virtual SizeValueType GetNumberOfIterations() const ITK_OVERRIDE
110  {
111  return this->m_NumberOfIterations;
112  }
113 
115  virtual SizeValueType GetCurrentIteration() const ITK_OVERRIDE
116  {
117  return this->m_CurrentIteration;
118  }
119 
121  virtual void StartOptimization( bool doOnlyInitialization = false ) ITK_OVERRIDE;
122 
126  virtual void ResumeOptimization() = 0;
127 
130  virtual void StopOptimization();
131 
133  virtual const StopConditionReturnStringType GetStopConditionDescription() const ITK_OVERRIDE;
134 
147  virtual void ModifyGradientByScales();
148  virtual void ModifyGradientByLearningRate();
150 
152 
158  virtual void ModifyGradientByScalesOverSubRange( const IndexRangeType& subrange ) = 0;
159 
168  virtual void ModifyGradientByLearningRateOverSubRange( const IndexRangeType& subrange ) = 0;
169 
170 protected:
171 
174  virtual ~GradientDescentOptimizerBasev4Template() ITK_OVERRIDE;
176 
180  bool m_DoEstimateLearningRateAtEachIteration;
181 
185  bool m_DoEstimateLearningRateOnce;
186 
193  TInternalComputationValueType m_MaximumStepSizeInPhysicalUnits;
194 
199  bool m_UseConvergenceMonitoring;
200 
205  SizeValueType m_ConvergenceWindowSize;
206 
208  typename ConvergenceMonitoringType::Pointer m_ConvergenceMonitoring;
209 
210  typename DomainThreader<ThreadedIndexedContainerPartitioner, Self>::Pointer m_ModifyGradientByScalesThreader;
211  typename DomainThreader<ThreadedIndexedContainerPartitioner, Self>::Pointer m_ModifyGradientByLearningRateThreader;
212 
213  /* Common variables for optimization control and reporting */
214  bool m_Stop;
215  StopConditionType m_StopCondition;
216  StopConditionDescriptionType m_StopConditionDescription;
217 
219  DerivativeType m_Gradient;
220  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
221 
222 private:
223 
224  ITK_DISALLOW_COPY_AND_ASSIGN(GradientDescentOptimizerBasev4Template);
225 
226 };
227 
229 typedef GradientDescentOptimizerBasev4Template<double> GradientDescentOptimizerBasev4;
230 
231 } // end namespace itk
232 
233 #ifndef ITK_MANUAL_INSTANTIATION
234 #include "itkGradientDescentOptimizerBasev4.hxx"
235 #endif
236 
237 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
Light weight base class for most itk classes.
Superclass::StopConditionDescriptionType StopConditionDescriptionType
Multi-threaded processing on a domain by processing sub-domains per thread.
Superclass::StopConditionReturnStringType StopConditionReturnStringType
virtual SizeValueType GetCurrentIteration() const override
virtual SizeValueType GetNumberOfIterations() const override
unsigned long SizeValueType
Definition: itkIntTypes.h:143
virtual void SetNumberOfIterations(const SizeValueType numberOfIterations) override
Class which monitors convergence during the course of optimization.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Abstract base for object-to-object optimizers.
ObjectToObjectOptimizerBaseTemplate< TInternalComputationValueType > Superclass
ThreadedIndexedContainerPartitioner::IndexRangeType IndexRangeType
itk::Function::WindowConvergenceMonitoringFunction< TInternalComputationValueType > ConvergenceMonitoringType