00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkRegularStepGradientDescentBaseOptimizer_h
00018 #define __itkRegularStepGradientDescentBaseOptimizer_h
00019
00020 #include "itkSingleValuedNonLinearOptimizer.h"
00021
00022 namespace itk
00023 {
00024
00030 class ITK_EXPORT RegularStepGradientDescentBaseOptimizer :
00031 public SingleValuedNonLinearOptimizer
00032 {
00033 public:
00035 typedef RegularStepGradientDescentBaseOptimizer Self;
00036 typedef SingleValuedNonLinearOptimizer Superclass;
00037 typedef SmartPointer<Self> Pointer;
00038 typedef SmartPointer<const Self> ConstPointer;
00039
00041 itkNewMacro(Self);
00042
00044 itkTypeMacro( RegularStepGradientDescentBaseOptimizer,
00045 SingleValuedNonLinearOptimizer );
00046
00047
00049 typedef enum {
00050 GradientMagnitudeTolerance = 1,
00051 StepTooSmall = 2,
00052 ImageNotAvailable = 3,
00053 CostFunctionError = 4,
00054 MaximumNumberOfIterations = 5
00055 } StopConditionType;
00056
00058 itkSetMacro( Maximize, bool );
00059 itkGetConstReferenceMacro( Maximize, bool );
00060 itkBooleanMacro( Maximize );
00061 bool GetMinimize( ) const
00062 { return !m_Maximize; }
00063 void SetMinimize(bool v)
00064 { this->SetMaximize(!v); }
00065 void MinimizeOn(void)
00066 { SetMaximize( false ); }
00067 void MinimizeOff(void)
00068 { SetMaximize( true ); }
00070
00072 void StartOptimization( void );
00073
00076 void ResumeOptimization( void );
00077
00080 void StopOptimization( void );
00081
00083 itkSetMacro( MaximumStepLength, double );
00084 itkSetMacro( MinimumStepLength, double );
00085 itkSetMacro( RelaxationFactor, double );
00086 itkSetMacro( NumberOfIterations, unsigned long );
00087 itkSetMacro( GradientMagnitudeTolerance, double );
00088 itkGetConstReferenceMacro( CurrentStepLength, double);
00089 itkGetConstReferenceMacro( MaximumStepLength, double );
00090 itkGetConstReferenceMacro( MinimumStepLength, double );
00091 itkGetConstReferenceMacro( RelaxationFactor, double );
00092 itkGetConstReferenceMacro( NumberOfIterations, unsigned long );
00093 itkGetConstReferenceMacro( GradientMagnitudeTolerance, double );
00094 itkGetConstMacro( CurrentIteration, unsigned int );
00095 itkGetConstReferenceMacro( StopCondition, StopConditionType );
00096 itkGetConstReferenceMacro( Value, MeasureType );
00097 itkGetConstReferenceMacro( Gradient, DerivativeType );
00099
00100
00101 protected:
00102 RegularStepGradientDescentBaseOptimizer();
00103 virtual ~RegularStepGradientDescentBaseOptimizer() {};
00104 void PrintSelf(std::ostream& os, Indent indent) const;
00105
00109 virtual void AdvanceOneStep( void );
00110
00116 virtual void StepAlongGradient(
00117 double,
00118 const DerivativeType&)
00119 {
00120 ExceptionObject ex;
00121 ex.SetLocation(__FILE__);
00122 ex.SetDescription("This method MUST be overloaded in derived classes");
00123 throw ex;
00124 }
00126
00127
00128 private:
00129 RegularStepGradientDescentBaseOptimizer(const Self&);
00130 void operator=(const Self&);
00131
00132 protected:
00133 DerivativeType m_Gradient;
00134 DerivativeType m_PreviousGradient;
00135
00136 bool m_Stop;
00137 bool m_Maximize;
00138 MeasureType m_Value;
00139 double m_GradientMagnitudeTolerance;
00140 double m_MaximumStepLength;
00141 double m_MinimumStepLength;
00142 double m_CurrentStepLength;
00143 double m_RelaxationFactor;
00144 StopConditionType m_StopCondition;
00145 unsigned long m_NumberOfIterations;
00146 unsigned long m_CurrentIteration;
00147
00148
00149 };
00150
00151 }
00152
00153
00154
00155 #endif
00156
00157
00158
00159