Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSPSAOptimizer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSPSAOptimizer.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-01-26 12:19:14 $
00007   Version:   $Revision: 1.8 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00014      PURPOSE.  See the above copyright notices for more information.
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 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   // For backward compatibility
00123   void Seta (double a) { SetSa(a);}
00124   double Geta () {return GetSa();}
00126 
00128   itkSetMacro( Sc, double );
00129   itkGetConstMacro( Sc, double );
00130   // For backward compatibility
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 
00207 protected:
00208 
00209   SPSAOptimizer();
00210   virtual ~SPSAOptimizer() {};
00211 
00213   void PrintSelf( std::ostream& os, Indent indent ) const;
00214 
00216   DerivativeType               m_Gradient; 
00217   double                       m_LearningRate;
00218   DerivativeType               m_Delta;
00219   bool                         m_Stop;
00220   StopConditionType            m_StopCondition;
00221   double                       m_StateOfConvergence;
00222   unsigned long                m_CurrentIteration;
00223 
00225   Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator;
00226 
00228   virtual double Compute_a( unsigned long k ) const;
00229 
00234   virtual double Compute_c( unsigned long k ) const;
00235 
00237   virtual void GenerateDelta( const unsigned int spaceDimension );
00238 
00243   virtual void ComputeGradient(
00244     const ParametersType & parameters,
00245     DerivativeType & gradient);
00246 
00247 private:
00248 
00249   SPSAOptimizer( const Self& );    // purposely not implemented
00250   void operator=( const Self& );  // purposely not implemented
00251     
00253   unsigned long                 m_MinimumNumberOfIterations;
00254   unsigned long                 m_MaximumNumberOfIterations;
00255   double                        m_StateOfConvergenceDecayRate;
00256   double                        m_Tolerance;
00257   bool                          m_Maximize;
00258   double                        m_GradientMagnitude;
00259   unsigned long                 m_NumberOfPerturbations;
00260 
00262   double                        m_Sa;
00263   double                        m_Sc;
00264   double                        m_A;
00265   double                        m_Alpha;
00266   double                        m_Gamma;
00267 
00268 }; // end class SPSAOptimizer
00269 
00270 } // end namespace itk
00271 
00272 #endif // end #ifndef __itkSPSAOptimizer_h
00273 

Generated at Sat Feb 28 13:36:59 2009 for ITK by doxygen 1.5.6 written by Dimitri van Heesch, © 1997-2000