ITK
4.1.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 __itkGradientDescentOptimizer_h 00019 #define __itkGradientDescentOptimizer_h 00020 00021 #include "itkIntTypes.h" 00022 #include "itkSingleValuedNonLinearOptimizer.h" 00023 #include <string> 00024 namespace itk 00025 { 00050 class ITK_EXPORT GradientDescentOptimizer: 00051 public SingleValuedNonLinearOptimizer 00052 { 00053 public: 00055 typedef GradientDescentOptimizer Self; 00056 typedef SingleValuedNonLinearOptimizer Superclass; 00057 typedef SmartPointer< Self > Pointer; 00058 typedef SmartPointer< const Self > ConstPointer; 00059 00061 itkNewMacro(Self); 00062 00064 itkTypeMacro(GradientDescentOptimizer, SingleValuedNonLinearOptimizer); 00065 00067 typedef enum { 00068 MaximumNumberOfIterations, 00069 MetricError 00070 } StopConditionType; 00071 00073 itkGetConstReferenceMacro(Maximize, bool); 00074 itkSetMacro(Maximize, bool); 00075 itkBooleanMacro(Maximize); 00076 bool GetMinimize() const 00077 { return !m_Maximize; } 00078 void SetMinimize(bool v) 00079 { this->SetMaximize(!v); } 00080 void MinimizeOn() 00081 { this->MaximizeOff(); } 00082 void MinimizeOff() 00083 { this->MaximizeOn(); } 00085 00087 virtual void AdvanceOneStep(void); 00088 00090 void StartOptimization(void); 00091 00094 void ResumeOptimization(void); 00095 00098 void StopOptimization(void); 00099 00101 itkSetMacro(LearningRate, double); 00102 00104 itkGetConstReferenceMacro(LearningRate, double); 00105 00107 itkSetMacro(NumberOfIterations, SizeValueType); 00108 00110 itkGetConstReferenceMacro(NumberOfIterations, SizeValueType); 00111 00113 itkGetConstMacro(CurrentIteration, SizeValueType); 00114 00116 itkGetConstReferenceMacro(Value, double); 00117 00119 itkGetConstReferenceMacro(StopCondition, StopConditionType); 00120 const std::string GetStopConditionDescription() const; 00122 00124 itkGetConstReferenceMacro(Gradient, DerivativeType); 00125 protected: 00126 GradientDescentOptimizer(); 00127 virtual ~GradientDescentOptimizer() {} 00128 void PrintSelf(std::ostream & os, Indent indent) const; 00130 00131 // made protected so subclass can access 00132 DerivativeType m_Gradient; 00133 00134 bool m_Maximize; 00135 00136 double m_LearningRate; 00137 private: 00138 GradientDescentOptimizer(const Self &); //purposely not implemented 00139 void operator=(const Self &); //purposely not implemented 00140 00141 bool m_Stop; 00142 double m_Value; 00143 StopConditionType m_StopCondition; 00144 SizeValueType m_NumberOfIterations; 00145 SizeValueType m_CurrentIteration; 00146 std::ostringstream m_StopConditionDescription; 00147 }; 00148 } // end namespace itk 00149 00150 #endif 00151