itkRegularStepGradientDescentBaseOptimizer.h
Go to the documentation of this file.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 Unknown = 6
00056 } StopConditionType;
00057
00059 itkSetMacro( Maximize, bool );
00060 itkGetConstReferenceMacro( Maximize, bool );
00061 itkBooleanMacro( Maximize );
00062 bool GetMinimize( ) const
00063 { return !m_Maximize; }
00064 void SetMinimize(bool v)
00065 { this->SetMaximize(!v); }
00066 void MinimizeOn(void)
00067 { SetMaximize( false ); }
00068 void MinimizeOff(void)
00069 { SetMaximize( true ); }
00071
00073 void StartOptimization( void );
00074
00077 void ResumeOptimization( void );
00078
00081 void StopOptimization( void );
00082
00084 itkSetMacro( MaximumStepLength, double );
00085 itkSetMacro( MinimumStepLength, double );
00086 itkSetMacro( RelaxationFactor, double );
00087 itkSetMacro( NumberOfIterations, unsigned long );
00088 itkSetMacro( GradientMagnitudeTolerance, double );
00089 itkGetConstReferenceMacro( CurrentStepLength, double);
00090 itkGetConstReferenceMacro( MaximumStepLength, double );
00091 itkGetConstReferenceMacro( MinimumStepLength, double );
00092 itkGetConstReferenceMacro( RelaxationFactor, double );
00093 itkGetConstReferenceMacro( NumberOfIterations, unsigned long );
00094 itkGetConstReferenceMacro( GradientMagnitudeTolerance, double );
00095 itkGetConstMacro( CurrentIteration, unsigned int );
00096 itkGetConstReferenceMacro( StopCondition, StopConditionType );
00097 itkGetConstReferenceMacro( Value, MeasureType );
00098 itkGetConstReferenceMacro( Gradient, DerivativeType );
00100
00102 virtual const std::string GetStopConditionDescription() const;
00103
00104 protected:
00105 RegularStepGradientDescentBaseOptimizer();
00106 virtual ~RegularStepGradientDescentBaseOptimizer() {};
00107 void PrintSelf(std::ostream& os, Indent indent) const;
00108
00112 virtual void AdvanceOneStep( void );
00113
00119 virtual void StepAlongGradient(
00120 double,
00121 const DerivativeType&)
00122 {
00123 ExceptionObject ex;
00124 ex.SetLocation(__FILE__);
00125 ex.SetDescription("This method MUST be overloaded in derived classes");
00126 throw ex;
00127 }
00129
00130 private:
00131 RegularStepGradientDescentBaseOptimizer(const Self&);
00132 void operator=(const Self&);
00133
00134 protected:
00135 DerivativeType m_Gradient;
00136 DerivativeType m_PreviousGradient;
00137
00138 bool m_Stop;
00139 bool m_Maximize;
00140 MeasureType m_Value;
00141 double m_GradientMagnitudeTolerance;
00142 double m_MaximumStepLength;
00143 double m_MinimumStepLength;
00144 double m_CurrentStepLength;
00145 double m_RelaxationFactor;
00146 StopConditionType m_StopCondition;
00147 unsigned long m_NumberOfIterations;
00148 unsigned long m_CurrentIteration;
00149 OStringStream m_StopConditionDescription;
00150 };
00151
00152 }
00153
00154 #endif
00155