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: 2007/03/29 19:37:01 $
00007   Version:   $Revision: 1.4 $
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( a, double );
00121   itkGetConstMacro( a, double );
00123 
00125   itkSetMacro( c, double );
00126   itkGetConstMacro( c, double );
00128 
00130   itkSetMacro( A, double );
00131   itkGetConstMacro( A, double );
00133 
00135   itkSetMacro( Alpha, double );
00136   itkGetConstMacro( Alpha, double );
00138 
00140   itkSetMacro( Gamma, double );
00141   itkGetConstMacro( Gamma, double );
00143 
00145   itkGetConstMacro( Maximize, bool );
00146   itkSetMacro( Maximize, bool );
00147   itkBooleanMacro( Maximize );
00148   bool GetMinimize( ) const
00149     { return !m_Maximize; }
00150   void SetMinimize(bool v)
00151     { this->SetMaximize(!v); }
00152   void MinimizeOn()
00153     { this->MaximizeOff(); }
00154   void MinimizeOff()
00155     { this->MaximizeOn(); }
00157 
00163   itkSetMacro( NumberOfPerturbations, unsigned long );
00164   itkGetConstMacro( NumberOfPerturbations, unsigned long );
00166 
00167 
00179   itkGetConstMacro( StateOfConvergence, double );
00180 
00182   itkSetMacro( StateOfConvergenceDecayRate, double );
00183   itkGetConstMacro( StateOfConvergenceDecayRate, double );
00185 
00187   itkSetMacro( MinimumNumberOfIterations, unsigned long);
00188   itkGetConstMacro( MinimumNumberOfIterations, unsigned long);
00190 
00192   itkSetMacro( MaximumNumberOfIterations, unsigned long );
00193   itkGetConstMacro( MaximumNumberOfIterations, unsigned long );
00195 
00197   itkSetMacro(Tolerance, double);
00198   itkGetConstMacro(Tolerance, double);
00200 
00201 protected:
00202 
00203   SPSAOptimizer();
00204   virtual ~SPSAOptimizer() {};
00205 
00207   void PrintSelf( std::ostream& os, Indent indent ) const;
00208 
00210   DerivativeType               m_Gradient; 
00211   double                       m_LearningRate;
00212   DerivativeType               m_Delta;
00213   bool                         m_Stop;
00214   StopConditionType            m_StopCondition;
00215   double                       m_StateOfConvergence;
00216   unsigned long                m_CurrentIteration;
00217 
00219   Statistics::MersenneTwisterRandomVariateGenerator::Pointer m_Generator;
00220 
00222   virtual double Compute_a( unsigned long k ) const;
00223 
00228   virtual double Compute_c( unsigned long k ) const;
00229 
00231   virtual void GenerateDelta( const unsigned int spaceDimension );
00232 
00237   virtual void ComputeGradient(
00238     const ParametersType & parameters,
00239     DerivativeType & gradient);
00240 
00241 private:
00242 
00243   SPSAOptimizer( const Self& );    // purposely not implemented
00244   void operator=( const Self& );  // purposely not implemented
00245     
00247   unsigned long                 m_MinimumNumberOfIterations;
00248   unsigned long                 m_MaximumNumberOfIterations;
00249   double                        m_StateOfConvergenceDecayRate;
00250   double                        m_Tolerance;
00251   bool                          m_Maximize;
00252   double                        m_GradientMagnitude;
00253   unsigned long                 m_NumberOfPerturbations;
00254 
00256   double                        m_a;
00257   double                        m_c;
00258   double                        m_A;
00259   double                        m_Alpha;
00260   double                        m_Gamma;
00261 
00262 }; // end class SPSAOptimizer
00263 
00264 } // end namespace itk
00265 
00266 #endif // end #ifndef __itkSPSAOptimizer_h
00267 

Generated at Thu Nov 6 00:19:40 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000