freSPSASOOptimizer.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003 Program:   F.R.E.E. - flexible registration evaluation engine
00004 Module:    $RCSfile: freSPSASOOptimizer.h,v $
00005   Language:  C++
00006 
00007 Language:  C++
00008 
00009 Copyright (c) 2003 University Heidelberg, University of applied science Heilbronn.
00010 All rights reserved.
00011 
00012 Portions of this code are covered under the ITK copyright.
00013 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00014 
00015 Portions of this code are covered under the VTK copyright.
00016 See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
00017 
00018 This software is distributed WITHOUT ANY WARRANTY; without even 
00019 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00020 PURPOSE.  See the above copyright notices for more information.
00021 
00022 =========================================================================*/
00023 #ifndef __freSPSASOOptimizer_h
00024 #define __freSPSASOOptimizer_h
00025 
00026 #include "freSetupOptimizationOptimizer.h"
00027 #include "freRegistrationObserver.h"
00028 #include "freItkSingleValuedCostFunctionWrapper.h"
00029 
00030 #include "itkSPSAOptimizer.h"
00031 
00032 namespace FREE
00033 {
00034 
00035 #define freGetWrappedConstMacro(name,type) \
00036   virtual type Get##name () const \
00037   { \
00038     return this->m_ItkOptimizer->Get##name (); \
00039   }
00040 
00041 #define freGetWrappedConstReferenceMacro(name,type) \
00042   virtual const type & Get##name () const \
00043   { \
00044   return this->m_ItkOptimizer->Get##name (); \
00045   }
00046 
00047 #define freSetWrappedMacro(name,type) \
00048   virtual void Set##name (const type _arg) \
00049   { \
00050     this->m_ItkOptimizer->Set##name ( _arg ); \
00051     this->Modified(); \
00052   } 
00053 
00059   class ITK_EXPORT SPSASOOptimizer : 
00060     public SetupOptimizationOptimizer
00061   {
00062   public:
00064     typedef SPSASOOptimizer  Self;
00065     typedef SetupOptimizationOptimizer                                          Superclass;
00066     typedef itk::SmartPointer<Self>               Pointer;
00067     typedef itk::SmartPointer<const Self>         ConstPointer;
00068 
00070     itkTypeMacro( SPSASOOptimizer, SetupOptimizationOptimizer );
00071 
00073     itkNewMacro(Self);
00074 
00075     virtual void GuessParameters(  unsigned long numberOfGradientEstimates,
00076       double initialStepSize);
00077 
00079     itkSetMacro( ValueUpdateRate, long );
00080     itkGetConstMacro( ValueUpdateRate, long );
00081 
00083     freGetWrappedConstMacro( CurrentIteration, unsigned long );
00085     freGetWrappedConstMacro( StopCondition, itk::SPSAOptimizer::StopConditionType );
00087     freGetWrappedConstMacro( LearningRate, double);
00089     freGetWrappedConstMacro( GradientMagnitude, double);
00091     freGetWrappedConstReferenceMacro( Gradient, itk::SPSAOptimizer::DerivativeType);
00092 
00094     freSetWrappedMacro( a, double );
00095     freGetWrappedConstMacro( a, double );
00096 
00098     freSetWrappedMacro( c, double );
00099     freGetWrappedConstMacro( c, double );
00100 
00102     freSetWrappedMacro( A, double );
00103     freGetWrappedConstMacro( A, double );
00104 
00106     freSetWrappedMacro( Alpha, double );
00107     freGetWrappedConstMacro( Alpha, double );
00108 
00110     freSetWrappedMacro( Gamma, double );
00111     freGetWrappedConstMacro( Gamma, double );
00112 
00114     freGetWrappedConstMacro( Maximize, bool );
00115     freSetWrappedMacro( Maximize, bool );
00116     void MaximizeOn()
00117     { this->m_ItkOptimizer->SetMaximize(true); }
00118     void MaximizeOff()
00119     { this->m_ItkOptimizer->SetMaximize(true); }
00120     bool GetMinimize( ) const
00121     { return !this->m_ItkOptimizer->GetMinimize(); }
00122     void SetMinimize(bool v)
00123     { this->m_ItkOptimizer->SetMinimize(v); }
00124     void MinimizeOn()
00125     { this->m_ItkOptimizer->MinimizeOn(); }
00126     void MinimizeOff()
00127     { this->m_ItkOptimizer->MinimizeOff(); }
00128 
00129     freSetWrappedMacro( NumberOfPerturbations, unsigned long );
00130     freGetWrappedConstMacro( NumberOfPerturbations, unsigned long );
00131 
00132     freGetWrappedConstMacro( StateOfConvergence, double );
00133 
00135     freSetWrappedMacro( StateOfConvergenceDecayRate, double );
00136     freGetWrappedConstMacro( StateOfConvergenceDecayRate, double );
00137 
00139     freSetWrappedMacro( MinimumNumberOfIterations, unsigned long);
00140     freGetWrappedConstMacro( MinimumNumberOfIterations, unsigned long);
00141 
00143     freSetWrappedMacro( MaximumNumberOfIterations, unsigned long );
00144     freGetWrappedConstMacro( MaximumNumberOfIterations, unsigned long );
00145 
00147     freSetWrappedMacro(Tolerance, double);
00148     freGetWrappedConstMacro(Tolerance, double);
00149 
00150     virtual void SetCostFunction( CostFunctionType * costFunction );
00151 
00152     virtual void SetInitialPosition (const ParametersType &param);
00153 
00154     virtual void StartOptimization( void );
00155 
00156     virtual bool IsStoppable() const;
00157     virtual void StopOptimization();
00158 
00159     virtual bool IsResumeable() const;
00160     virtual void ResumeOptimization();
00161 
00162     typedef itk::SPSAOptimizer ItkOptimizerType;
00163     typedef ItkOptimizerType::Pointer ItkOptimizerPointer;
00164 
00165     ItkOptimizerType * GetItkOptimizer();
00166 
00167   protected:
00168     SPSASOOptimizer();
00169     void PrintSelf(std::ostream& os, itk::Indent indent) const;
00170 
00171     void OnOptIteration(void* pSender, long threadID);
00172     void OnOptStart(void* pSender, long threadID);
00173     void OnOptEnd(void* pSender, long threadID);
00174 
00175     IterationObserver::Pointer m_IterationObserver;
00176     NotificationEvent<Self>::Pointer m_IterationNotificationEvent;
00177 
00178     typedef RegistrationObserverBase<itk::StartEvent> StartObserver;
00179     StartObserver::Pointer m_StartObserver;
00180     NotificationEvent<Self>::Pointer m_StartNotificationEvent;
00181 
00182     typedef RegistrationObserverBase<itk::EndEvent> EndObserver;
00183     EndObserver::Pointer m_EndObserver;
00184     NotificationEvent<Self>::Pointer m_EndNotificationEvent;
00185 
00186     ItkOptimizerPointer m_ItkOptimizer;
00187     ItkSingleValuedCostFunctionWrapper::Pointer m_CostFunctionWrapper;
00188 
00189     long m_ValueUpdateRate;
00190 
00191   private:  
00192     SPSASOOptimizer(const Self&); //purposely not implemented
00193     void operator=(const Self&);//purposely not implemented
00194   };
00195 
00196 } // end namespace FREE
00197 
00198 #endif
00199 
00200 

Generated at Sat Oct 13 17:41:41 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000