freRegStepGradDescOptimizerControllerBase.txx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freRegStepGradDescOptimizerControllerBase.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 
00023 #ifndef __freRegStepGradDescOptimizerControllerBase_txx
00024 #define __freRegStepGradDescOptimizerControllerBase_txx
00025 
00026 #include "freRegStepGradDescOptimizerControllerBase.h"
00027 #include "freExceptions.h"
00028 
00029 namespace FREE
00030 {
00031 
00035 
00036 template <class TOptimizer>
00037 const char* const RegStepGradDescOptimizerControllerBase<TOptimizer>::cParam_RelaxationFactor = "RelaxationFactor";
00038 template <class TOptimizer>
00039 const char* const RegStepGradDescOptimizerControllerBase<TOptimizer>::cParamDsc_RelaxationFactor = "Factor of relaxation, when optimizer changes direction.";
00040 
00041 template <class TOptimizer>
00042 RegStepGradDescOptimizerControllerBase<TOptimizer>::
00043 RegStepGradDescOptimizerControllerBase()
00044 {
00045   //Profile settings
00046   this->UpdateControllerID(ControllerID::RegStepGradDescOptimizerControllerBase);
00047   this->m_Description = "Base class for a regular step gradient descent approach.";
00048 };
00049 
00050 template <class TOptimizer>
00051 void
00052 RegStepGradDescOptimizerControllerBase<TOptimizer>::
00053 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00054                 const SessionComponentCache* pComponentCache,
00055                 bool bRegardOldSetup) const
00056 {
00057   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00058 
00059         //Parameters
00060   profile.Parameters().AddParameter(cParam_DynamicLevelStepLength,Parameter::PVTBool,cParamDsc_DynamicLevelStepLength,1,"true",-1,true);
00061   profile.Parameters().AddParameter(cParam_MaxStepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_MaxStepLength,1,"1.0",-1,true);
00062   profile.Parameters().AddParameter(cParam_MinStepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_MinStepLength,1,"0.01",-1,true);
00063   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTULong,cParamDsc_Iterations,1,"100",-1,true);
00064   profile.Parameters().AddParameter(cParam_GradMagTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_GradMagTolerance,1,"0.0001");
00065   profile.Parameters().AddParameter(cParam_RelaxationFactor,CtrlProfile::Parameter::PVTDouble,cParamDsc_RelaxationFactor,1,"0.5");
00066 
00067 };
00068 
00069 template <class TOptimizer>
00070 void
00071 RegStepGradDescOptimizerControllerBase<TOptimizer>::
00072 ActualizeMainComponent(ComponentType* pMainComponent,
00073                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00074                                                                                          const unsigned int& iActLevel) const
00075 {
00076   double dMaxStepLength = 0;
00077   double dRelaxationFactor;
00078   double dMinStepLength;
00079   unsigned long lNrOfIterations;
00080   double dGradMagTolerance;
00081   bool bDynamicLevelStepLength;
00082 
00083   try
00084   {
00085     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lNrOfIterations,0,iActLevel,true);
00086     SessionAccessor::GetParameterValue(pComponentCache,cParam_DynamicLevelStepLength,bDynamicLevelStepLength,0,iActLevel,true);
00087     SessionAccessor::GetParameterValue(pComponentCache,cParam_MinStepLength,dMinStepLength,0,iActLevel,true);
00088     SessionAccessor::GetParameterValue(pComponentCache,cParam_GradMagTolerance,dGradMagTolerance,0,iActLevel,true);
00089     SessionAccessor::GetParameterValue(pComponentCache,cParam_RelaxationFactor,dRelaxationFactor,0,iActLevel,true);
00090           if ((iActLevel!=0)&(bDynamicLevelStepLength))
00091           {
00092                   dMaxStepLength = pMainComponent->GetCurrentStepLength();
00093           }
00094           else
00095           {
00096       SessionAccessor::GetParameterValue(pComponentCache,cParam_MaxStepLength,dMaxStepLength,0,iActLevel,true);
00097           }
00098   }
00099   catchAllNPassMacro("Error while retrieving parameter values.");
00100 
00101   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00102   pMainComponent->SetScales(scales);
00103 
00104   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00105   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00106   bool bMinimize;
00107   smpDirection->GetParameterValue(bMinimize);
00108   pMainComponent->SetMaximize( !bMinimize);
00109 
00110   pMainComponent->SetNumberOfIterations(lNrOfIterations);
00111   pMainComponent->SetGradientMagnitudeTolerance(dGradMagTolerance);
00112   pMainComponent->SetMinimumStepLength(dMinStepLength);
00113         pMainComponent->SetRelaxationFactor(dRelaxationFactor);
00114   pMainComponent->SetMaximumStepLength(dMaxStepLength); 
00115 };
00116 
00117 template <class TOptimizer>
00118 void
00119 RegStepGradDescOptimizerControllerBase<TOptimizer>::
00120 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00121                                              ComponentType* pMainComponent,
00122                                              SessionComponentCache* pMainComponentCache,
00123                                              SessionInfo* pSessionInfo,
00124                                              StatisticDictionary& rDictionary) const
00125 {
00126   Superclass::SetStatisticEntryMainComponent(rStatisticEntry,pMainComponent,
00127                                             pMainComponentCache,pSessionInfo,
00128                                             rDictionary);
00129   
00130   std::string sName = "OptimizerValue";
00131   std::string sIDPath = pMainComponentCache->GetIDPath();
00132   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00133     
00134   if (!pEntry) //Entry is not recorded yet, so do so.
00135   {
00136     pEntry = rDictionary.AddValueDefinition(sIDPath, sName, "Value of the Optimizer");
00137   }
00138 
00139   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetValue()),pEntry->GetRefID());
00140 };
00141 
00142 } //end of namespace free
00143 
00144 #endif

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