freLimitedAxisAmoebaSOOptimizerController.cxx

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: freLimitedAxisAmoebaSOOptimizerController.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 #include "freLimitedAxisAmoebaSOOptimizerController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 
00034 
00035 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,ParameterAxis,"ParameterAxis","Indicating the search axis a parameter belongs to.");
00036 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,NumberOfAxis,"NumberOfAxis","The number of axis (dimensionality of search space) that should be optimized.");
00037 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,AutoInitialSimplex,"AutoInitialSimplex","Determines if the optimizer uses a small default simplex, SimplexDelta will be ignored.");
00038 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,SimplexDelta,"SimplexDelta","Starting size of the simplex");
00039 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,ParamConvTolerance,"ParamConvTolerance","Parameter convergence tolerance is the simplex diameter treshold. Optimation stopps if when the simplex diameter and the function convergence falls below their tresholds.");
00040 DefineParameterMacro(LimitedAxisAmoebaSOOptimizerController,FunctConvTolerance,"FunctConvTolerance","Function convergence tolerance is the function convergence treshold. Optimation stopps if when the simplex diameter and the function convergence falls below their tresholds.");
00041 
00042 LimitedAxisAmoebaSOOptimizerController::
00043 LimitedAxisAmoebaSOOptimizerController()
00044 {
00045   //Profile settings
00046   this->UpdateControllerID(ControllerID::LimitedAxisAmoebaSOOptimizerController);
00047   this->m_Description = "Optimizes by an amoeba optimizer (simplex) approach that optimizes not the parameter directly, but the position on the search space axis grouping the parameters.";
00048 };
00049 
00050 void
00051 LimitedAxisAmoebaSOOptimizerController::
00052 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00053                   const SessionComponentCache* pComponentCache,
00054                   bool bRegardOldSetup) const
00055 {
00056   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00057 
00058         //Parameters
00059   profile.Parameters().AddParameter(cParam_ParameterAxis,CtrlProfile::Parameter::PVTInteger,cParamDsc_ParameterAxis,1,"-1");
00060   profile.Parameters().AddParameter(cParam_NumberOfAxis,CtrlProfile::Parameter::PVTLong,cParamDsc_NumberOfAxis,1,"1");
00061   profile.Parameters().AddParameter(cParam_AutoInitialSimplex,CtrlProfile::Parameter::PVTBool,cParamDsc_AutoInitialSimplex,1,"true",-1,true);
00062   profile.Parameters().AddParameter(cParam_SimplexDelta,CtrlProfile::Parameter::PVTDouble,cParamDsc_SimplexDelta,1,"5",-1,true);
00063   profile.Parameters().AddParameter(cParam_ParamConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_ParamConvTolerance,1,"1e-8",-1,true);
00064   profile.Parameters().AddParameter(cParam_FunctConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_FunctConvTolerance,1,"1e-4",-1,true);
00065   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"500",-1,true);
00066 };
00067 
00068 long
00069 LimitedAxisAmoebaSOOptimizerController::
00070 GetMaxIterationCount(const SessionComponentCache* pComponentCache, unsigned int iResolutionLevel) const
00071 {
00072         if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00073         if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00074 
00075   long lResult = 1;
00076   SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lResult);
00077 
00078   return lResult;
00079 };
00080 
00081 void
00082 LimitedAxisAmoebaSOOptimizerController::
00083 ActualizeMainComponent(ComponentType* pMainComponent,
00084                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00085                                                                                          const unsigned int& iActLevel) const
00086 {
00087         Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00088                                                                                                                                                  pSessionInfo, iActLevel);
00089 
00090         bool bAutoSimplex;
00091         ComponentType::ParametersType simplexDelta;
00092   double dParamConvTolerance;
00093   double dFunctConvTolerance;
00094   int iNrOfIterations;
00095   ComponentType::ParameterAxisType parameterAxis;
00096         long iAxisCount;
00097 
00098   try
00099   {
00100     SessionAccessor::GetParameterValue(pComponentCache,cParam_AutoInitialSimplex,bAutoSimplex);
00101     SessionAccessor::GetParameterValue(pComponentCache,cParam_ParamConvTolerance,dParamConvTolerance);
00102     SessionAccessor::GetParameterValue(pComponentCache,cParam_FunctConvTolerance,dFunctConvTolerance);
00103     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations);
00104     SessionAccessor::GetParameterValue(pComponentCache,cParam_NumberOfAxis,iAxisCount);
00105   }
00106   catchAllNPassMacro("Error while retrieving parameter values.");    
00107 
00108   Parameter::Pointer smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_SimplexDelta);
00109   if (!smpParameter) throwExceptionMacro("Missing parameter: " << cParam_SimplexDelta);
00110         simplexDelta = Convert::ParameterLayerToArray<ComponentType::ParametersType>(*(smpParameter->GetParameterLayer(0)));
00111 
00112   smpParameter = SessionAccessor::GetParameter(pComponentCache,cParam_ParameterAxis);
00113   if (!smpParameter) throwExceptionMacro("Missing parameter: " << cParam_ParameterAxis);
00114         parameterAxis = Convert::ParameterLayerToArray<ComponentType::ParameterAxisType>(*(smpParameter->GetParameterLayer(0)));
00115 
00116         pMainComponent->SetNumberOfAxis(iAxisCount);
00117         pMainComponent->SetParameterAxis( parameterAxis );
00118         pMainComponent->SetAutomaticInitialSimplex(bAutoSimplex);
00119         pMainComponent->SetInitialSimplexDelta( simplexDelta );
00120 
00121   pMainComponent->SetParametersConvergenceTolerance(dParamConvTolerance);
00122   pMainComponent->SetFunctionConvergenceTolerance(dFunctConvTolerance);
00123   pMainComponent->SetMaximumNumberOfIterations(iNrOfIterations);
00124 
00125 };
00126 
00127 void
00128 LimitedAxisAmoebaSOOptimizerController::
00129 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00130                                              ComponentType* pMainComponent,
00131                                              SessionComponentCache* pMainComponentCache,
00132                                              SessionInfo* pSessionInfo,
00133                                              StatisticDictionary& rDictionary) const
00134 {
00135   ParameterArrayType parameters = pMainComponent->GetCachedCurrentPosition();
00136 
00137   std::string sName = "Position #";
00138   std::string sIDPath = pMainComponentCache->GetIDPath();
00139   std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00140   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00141     
00142   if (!pEntry) //Entry is not recorded yet, so do so.
00143   {
00144     std::string sName = "Position #";
00145     pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00146     for (unsigned int i = 1; i<parameters.Size(); i++)
00147     {
00148       rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00149     }
00150 
00151     rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Composed value of the optimizer");
00152   }
00153   
00154   for (unsigned int i = 0; i<parameters.Size(); i++)
00155   {
00156     rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00157   }
00158 
00159   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID()+parameters.Size());
00160 };
00161 
00162 } //end of namespace free

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