ITK
4.0.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkGradientDescentOptimizerBasev4_h 00019 #define __itkGradientDescentOptimizerBasev4_h 00020 00021 #include "itkObjectToObjectOptimizerBase.h" 00022 #include "itkGradientDescentOptimizerBasev4ModifyGradientByScalesThreader.h" 00023 #include "itkGradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader.h" 00024 00025 namespace itk 00026 { 00038 class ITK_EXPORT GradientDescentOptimizerBasev4 00039 : public ObjectToObjectOptimizerBase 00040 { 00041 public: 00043 typedef GradientDescentOptimizerBasev4 Self; 00044 typedef ObjectToObjectOptimizerBase Superclass; 00045 typedef SmartPointer< Self > Pointer; 00046 typedef SmartPointer< const Self > ConstPointer; 00047 00049 itkTypeMacro(GradientDescentOptimizerBasev4, ObjectToObjectOptimizerBase); 00050 00052 typedef enum { 00053 MAXIMUM_NUMBER_OF_ITERATIONS, 00054 COSTFUNCTION_ERROR, 00055 UPDATE_PARAMETERS_ERROR, 00056 STEP_TOO_SMALL, 00057 QUASI_NEWTON_STEP_ERROR, 00058 OTHER_ERROR 00059 } StopConditionType; 00060 00062 typedef std::string StopConditionReturnStringType; 00063 00065 typedef std::ostringstream StopConditionDescriptionType; 00066 00068 typedef Superclass::MetricType MetricType; 00069 typedef MetricType::Pointer MetricTypePointer; 00070 00072 typedef MetricType::DerivativeType DerivativeType; 00073 00075 typedef Superclass::MeasureType MeasureType; 00076 00078 typedef Superclass::InternalComputationValueType InternalComputationValueType; 00079 00081 itkGetConstReferenceMacro( Gradient, DerivativeType ); 00082 00084 itkGetConstReferenceMacro(StopCondition, StopConditionType); 00085 00087 itkSetMacro(NumberOfIterations, SizeValueType); 00088 00090 itkGetConstReferenceMacro(NumberOfIterations, SizeValueType); 00091 00093 itkGetConstMacro(CurrentIteration, SizeValueType); 00094 00098 virtual void ResumeOptimization() = 0; 00099 00102 virtual void StopOptimization(void); 00103 00105 virtual const StopConditionReturnStringType GetStopConditionDescription() const; 00106 00107 protected: 00108 00110 GradientDescentOptimizerBasev4(); 00111 virtual ~GradientDescentOptimizerBasev4(); 00113 00114 friend class GradientDescentOptimizerBasev4ModifyGradientByScalesThreader; 00115 friend class GradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader; 00116 00117 typedef GradientDescentOptimizerBasev4ModifyGradientByScalesThreader::IndexRangeType IndexRangeType; 00118 00119 GradientDescentOptimizerBasev4ModifyGradientByScalesThreader::Pointer m_ModifyGradientByScalesThreader; 00120 GradientDescentOptimizerBasev4ModifyGradientByLearningRateThreader::Pointer m_ModifyGradientByLearningRateThreader; 00121 00123 virtual void EstimateLearningRate() = 0; 00124 00133 virtual void ModifyGradient(); 00134 00140 virtual void ModifyGradientByScalesOverSubRange( const IndexRangeType& subrange ) = 0; 00141 00147 virtual void ModifyGradientByLearningRateOverSubRange( const IndexRangeType& subrange ) = 0; 00148 00149 /* Common variables for optimization control and reporting */ 00150 bool m_Stop; 00151 StopConditionType m_StopCondition; 00152 StopConditionDescriptionType m_StopConditionDescription; 00153 SizeValueType m_NumberOfIterations; 00154 SizeValueType m_CurrentIteration; 00155 00157 DerivativeType m_Gradient; 00158 virtual void PrintSelf(std::ostream & os, Indent indent) const; 00159 00160 private: 00161 GradientDescentOptimizerBasev4( const Self & ); //purposely not implemented 00162 void operator=( const Self& ); //purposely not implemented 00163 00164 }; 00165 00166 } // end namespace itk 00167 00168 #endif 00169