freOnePlusOneEvolutionarySOOptimizerController.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: freOnePlusOneEvolutionarySOOptimizerController.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 "freOnePlusOneEvolutionarySOOptimizerController.h"
00024 
00025 #include "freExceptions.h"
00026 #include "freNormalVariateGeneratorController.h"
00027 
00028 namespace FREE
00029 {
00030 
00034 
00035 
00036 
00037 OnePlusOneEvolutionarySOOptimizerController::
00038 OnePlusOneEvolutionarySOOptimizerController()
00039 {
00040   //Profile settings
00041   this->UpdateControllerID(ControllerID::OnePlusOneEvolutionarySOOptimizerController);
00042   this->m_Description = "Optimizes registration setups by a 1+1-evolutionary approach.";
00043 };
00044 
00045 void
00046 OnePlusOneEvolutionarySOOptimizerController::
00047 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00048                   const SessionComponentCache* pComponentCache,
00049                   bool bRegardOldSetup) const
00050 {
00051   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00052 
00053         //Parameters
00054   profile.Parameters().AddParameter("GrowthFactor",CtrlProfile::Parameter::PVTDouble,"Growth factor for the search radius.",1,"1.05",-1,true);
00055   profile.Parameters().AddParameter("ShrinkFactor",CtrlProfile::Parameter::PVTDouble,"Shrink factor for the search radius.",1,"0.98",-1,true);
00056   profile.Parameters().AddParameter("InitialRadius",CtrlProfile::Parameter::PVTDouble,"Search radius in parameter space.",1,"1.01",-1,true);
00057   profile.Parameters().AddParameter("Epsilon",CtrlProfile::Parameter::PVTDouble,"Treshold of the frobenius_norm for stopping optimization before hitting the maximum iterations.",1,"0.0001",-1,true);
00058   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"500",-1,true);
00059 
00060   //Subcomponents
00061   profile.SubComponents().AddSubComponent("VariateGenerator",1,"Normal Variate Generator");
00062 
00063   //Requirements
00064         CtrlProfile::ProfileOption* pOption;
00065     //metric
00066         pOption = profile.Requirements().AddRequirement("VariateGenerator")->AddProfileOption();
00067         pOption->Inheritance().AddAncestor(ControllerID::VariateGeneratorControllerBase);
00068         pOption->CheckForInheritance();
00069 };
00070 
00071 GenericComponentType*
00072 OnePlusOneEvolutionarySOOptimizerController::
00073 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00074                       SessionComponentCache* pMainComponentCache) const
00075 {
00076         if (compID == "VariateGenerator") throwCtrlExceptionMacro("","1+1 evolutionary optimizer has no getter function for variate generator. Use session to retrieve component.");
00077         return Superclass::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00078 }; 
00079 
00080 void
00081 OnePlusOneEvolutionarySOOptimizerController::
00082 SetSubComponentCasted(GenericComponentType* pSubComponent,
00083                                                                                                                                                  ComponentType* pMainComponent,
00084                                                                                                                                                  const ComponentID compID,
00085                                      SessionComponentCache* pMainComponentCache) const
00086 {
00087         if (compID == "VariateGenerator") pMainComponent->SetNormalVariateGenerator(dynamic_cast<OnePlusOneEvolutionarySOOptimizer::NormalVariateGeneratorType*>(pSubComponent));
00088   else Superclass::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00089 };
00090 
00091 long
00092 OnePlusOneEvolutionarySOOptimizerController::
00093 GetMaxIterationCount(const SessionComponentCache* pComponentCache, unsigned int iResolutionLevel) const
00094 {
00095         if (!pComponentCache) throwCtrlExceptionMacro("","Passed pComponentCache is NULL.");
00096         if (!pComponentCache->SetupIsAssigned()) throwCtrlExceptionMacro("","Cache has no setup assigned.");
00097 
00098   long lResult = 1;
00099   try
00100   {
00101     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lResult);
00102   }
00103   catchAllNPassMacro("Unknown error while retrieving max interation count.")
00104 
00105   return lResult;
00106 };
00107 
00108 void
00109 OnePlusOneEvolutionarySOOptimizerController::
00110 ActualizeMainComponent(ComponentType* pMainComponent,
00111                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00112                                                                                          const unsigned int& iActLevel) const
00113 {
00114         Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00115                                                                                                                                                  pSessionInfo, iActLevel);
00116 
00117   double dGrowthFactor;
00118   double dShrinkFactor;
00119   double dInitialRadius;
00120   double dEpsilon;
00121   int iNrOfIterations;
00122 
00123   try
00124   {
00125     SessionAccessor::GetParameterValue(pComponentCache,"GrowthFactor",dGrowthFactor);
00126     SessionAccessor::GetParameterValue(pComponentCache,"ShrinkFactor",dShrinkFactor);
00127     SessionAccessor::GetParameterValue(pComponentCache,"InitialRadius",dInitialRadius);
00128     SessionAccessor::GetParameterValue(pComponentCache,"Epsilon",dEpsilon);
00129     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations);
00130   }
00131   catchAllNPassMacro("Error while retrieving parameter values.");    
00132 
00133   pMainComponent->SetMaximumIteration(iNrOfIterations);
00134   pMainComponent->SetEpsilon(dEpsilon);
00135   pMainComponent->Initialize (dInitialRadius, dGrowthFactor, dShrinkFactor);
00136 
00137         //get metric "orientation"
00138    Parameter::Pointer param = SessionAccessor::GetParameterByIDPath(pComponentCache,cIDPParent+IDPath(cComp_MainMetric+std::string("/@")+std::string(cParam_MetricMinimize)));
00139         bool bMin = true;
00140         if (param.IsNotNull())
00141         {
00142                 param->GetParameterValue(bMin);
00143         }
00144         pMainComponent->SetMaximize(!bMin);
00145 
00146 };
00147 
00148 void
00149 OnePlusOneEvolutionarySOOptimizerController::
00150 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00151                                              ComponentType* pMainComponent,
00152                                              SessionComponentCache* pMainComponentCache,
00153                                              SessionInfo* pSessionInfo,
00154                                              StatisticDictionary& rDictionary) const
00155 {
00156         ParameterArrayType parameters = pMainComponent->GetCurrentChildPosition();
00157 
00158   std::string sName = "Position #";
00159   std::string sIDPath = pMainComponentCache->GetIDPath();
00160   std::string sCommment = "Optimizer position of the current child. Meaning depends on chosen transformation";
00161   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00162     
00163   if (!pEntry) //Entry is not recorded yet, so do so.
00164   {
00165     std::string sName = "Position #";
00166     pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00167     for (unsigned int i = 1; i<parameters.Size(); i++)
00168     {
00169       rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00170     }
00171 
00172     rDictionary.AddValueDefinition(sIDPath,"Frobius Norm", "Indicates the current search radius of the optimizer");
00173     rDictionary.AddValueDefinition(sIDPath,"OptimizerChildValue", "Composed value of the current child position");
00174     rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Composed value of the current optimizer position");
00175   }
00176   
00177   for (unsigned int i = 0; i<parameters.Size(); i++)
00178   {
00179     rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00180   }
00181 
00182   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetFrobeniusNorm()),pEntry->GetRefID()+parameters.Size());
00183   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentChildValue()),pEntry->GetRefID()+parameters.Size()+1);
00184   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentValue()),pEntry->GetRefID()+parameters.Size()+2);
00185 };
00186 
00187 void
00188 OnePlusOneEvolutionarySOOptimizerController::
00189 SetStatisticEntrySubComponents(StatisticEntry& rStatisticEntry, SessionComponentCache* pComponentCache,
00190                               SessionInfo* pSessionInfo, StatisticDictionary& rDictionary) const
00191 {
00192         //there are no subcomponents that should set statistics and function behaviour
00193         //of superclass raises an exception, because it tries to receive the variate generator
00194         //as a subcomponent.
00195 };
00196 
00197 } //end of namespace free

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