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 __itkSPSAOptimizer_h
00018 #define __itkSPSAOptimizer_h
00019
00020 #include "itkSingleValuedNonLinearOptimizer.h"
00021 #include "itkMersenneTwisterRandomVariateGenerator.h"
00022
00023
00024 namespace itk
00025 {
00026
00043 class ITK_EXPORT SPSAOptimizer
00044 : public SingleValuedNonLinearOptimizer
00045 {
00046 public:
00047
00049 typedef SPSAOptimizer Self;
00050 typedef SingleValuedNonLinearOptimizer Superclass;
00051 typedef SmartPointer<Self> Pointer;
00052 typedef SmartPointer<const Self> ConstPointer;
00053
00055 itkNewMacro( Self );
00056
00058 itkTypeMacro( SPSAOptimizer, SingleValuedNonLinearOptimizer );
00059
00061 typedef enum {
00062 Unknown,
00063 MaximumNumberOfIterations,
00064 BelowTolerance,
00065 MetricError } StopConditionType;
00066
00068 virtual void AdvanceOneStep( void );
00069
00071 void StartOptimization( void );
00072
00075 void ResumeOptimization( void );
00076
00079 void StopOptimization( void );
00080
00082 virtual MeasureType GetValue( void ) const;
00083
00085 virtual MeasureType GetValue( const ParametersType & parameters ) const;
00086
00100 virtual void GuessParameters(
00101 unsigned long numberOfGradientEstimates,
00102 double initialStepSize);
00103
00105 itkGetConstMacro( CurrentIteration, unsigned long );
00106
00108 itkGetConstMacro( StopCondition, StopConditionType );
00109
00111 itkGetConstMacro( LearningRate, double);
00112
00114 itkGetConstMacro( GradientMagnitude, double);
00115
00117 itkGetConstReferenceMacro( Gradient, DerivativeType);
00118
00120 itkSetMacro( Sa, double );
00121 itkGetConstMacro( Sa, double );
00122
00123 void Seta (double a) { SetSa(a);}
00124 double Geta () {return GetSa();}
00126
00128 itkSetMacro( Sc, double );
00129 itkGetConstMacro( Sc, double );
00130
00131 void Setc (double c) {SetSc(c);}
00132 double Getc () {return GetSc();}
00134
00136 itkSetMacro( A, double );
00137 itkGetConstMacro( A, double );
00139
00141 itkSetMacro( Alpha, double );
00142 itkGetConstMacro( Alpha, double );
00144
00146 itkSetMacro( Gamma, double );
00147 itkGetConstMacro( Gamma, double );
00149
00151 itkGetConstMacro( Maximize, bool );
00152 itkSetMacro( Maximize, bool );
00153 itkBooleanMacro( Maximize );
00154 bool GetMinimize( ) const
00155 { return !m_Maximize; }
00156 void SetMinimize(bool v)
00157 { this->SetMaximize(!v); }
00158 void MinimizeOn()
00159 { this->MaximizeOff(); }
00160 void MinimizeOff()
00161 { this->MaximizeOn(); }
00163
00169 itkSetMacro( NumberOfPerturbations, unsigned long );
00170 itkGetConstMacro( NumberOfPerturbations, unsigned long );
00172
00173
00185 itkGetConstMacro( StateOfConvergence, double );
00186
00188 itkSetMacro( StateOfConvergenceDecayRate, double );
00189 itkGetConstMacro( StateOfConvergenceDecayRate, double );
00191
00193 itkSetMacro( MinimumNumberOfIterations, unsigned long);
00194 itkGetConstMacro( MinimumNumberOfIterations, unsigned long);
00196
00198 itkSetMacro( MaximumNumberOfIterations, unsigned long );
00199 itkGetConstMacro( MaximumNumberOfIterations, unsigned long );
00201
00203 itkSetMacro(Tolerance, double);
00204 itkGetConstMacro(Tolerance, double);
00206
00208 const std::string GetStopConditionDescription() const;
00209
00210 protected:
00211
00212 SPSAOptimizer();
00213 virtual ~SPSAOptimizer() {};
00214
00216 void PrintSelf( std::ostream& os, Indent indent ) const;
00217
00219 DerivativeType m_Gradient;
00220 double m_LearningRate;
00221 DerivativeType m_Delta;
00222 bool m_Stop;
00223 StopConditionType m_StopCondition;
00224 double m_StateOfConvergence;
00225 unsigned long m_CurrentIteration;
00226
00228 Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator;
00229
00231 virtual double Compute_a( unsigned long k ) const;
00232
00237 virtual double Compute_c( unsigned long k ) const;
00238
00240 virtual void GenerateDelta( const unsigned int spaceDimension );
00241
00246 virtual void ComputeGradient(
00247 const ParametersType & parameters,
00248 DerivativeType & gradient);
00249
00250 private:
00251
00252 SPSAOptimizer( const Self& );
00253 void operator=( const Self& );
00254
00256 unsigned long m_MinimumNumberOfIterations;
00257 unsigned long m_MaximumNumberOfIterations;
00258 double m_StateOfConvergenceDecayRate;
00259 double m_Tolerance;
00260 bool m_Maximize;
00261 double m_GradientMagnitude;
00262 unsigned long m_NumberOfPerturbations;
00263
00265 double m_Sa;
00266 double m_Sc;
00267 double m_A;
00268 double m_Alpha;
00269 double m_Gamma;
00270
00271 };
00272
00273 }
00274
00275 #endif // end #ifndef __itkSPSAOptimizer_h
00276