freAmoebaOptimizerController.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: freAmoebaOptimizerController.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 "freAmoebaOptimizerController.h"
00024 #include "freExceptions.h"
00025 #include "freTransformSetupAdaptor.h"
00026 
00027 namespace FREE
00028 {
00029 
00033 
00034 
00035 
00036 DefineParameterMacro(AmoebaOptimizerController,AutoInitialSimplex,"AutoInitialSimplex","Determines if the optimizer uses a small default simplex, SimplexDelta will be ignored.");
00037 DefineParameterMacro(AmoebaOptimizerController,SimplexDelta,"SimplexDelta","Starting size of the simplex");
00038 DefineParameterMacro(AmoebaOptimizerController,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.");
00039 DefineParameterMacro(AmoebaOptimizerController,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.");
00040 
00041 
00042 AmoebaOptimizerController::
00043 AmoebaOptimizerController()
00044 {
00045   //Profile settings
00046   this->UpdateControllerID(ControllerID::AmoebaOptimizerController);
00047   this->m_Description = "Optimizes by an amoeba optimizer approach.";
00048 };
00049 
00050 void
00051 AmoebaOptimizerController::
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_AutoInitialSimplex,CtrlProfile::Parameter::PVTBool,cParamDsc_AutoInitialSimplex,1,"true",-1,true);
00060   profile.Parameters().AddParameter(cParam_SimplexDelta,CtrlProfile::Parameter::PVTDouble,cParamDsc_SimplexDelta,1,"5",-1,true);
00061   profile.Parameters().AddParameter(cParam_ParamConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_ParamConvTolerance,1,"1e-8",-1,true);
00062   profile.Parameters().AddParameter(cParam_FunctConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_FunctConvTolerance,1,"1e-4",-1,true);
00063   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"500",-1,true);
00064 };
00065 
00066 void
00067 AmoebaOptimizerController::
00068 ActualizeMainComponent(ComponentType* pMainComponent,
00069                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00070                                                                                          const unsigned int& iActLevel) const
00071 {
00072   ComponentSetup* pTransformSetup = pComponentCache->Setup()->GetComponentByIDPath("../"+ComponentID(cComp_MainTransform));
00073   if (!pTransformSetup) throwCtrlExceptionMacro("","No main transform setup found to gather parameter scales");
00074   TransformSetupAdaptor adaptor(pTransformSetup);
00075 
00076         bool bAutoSimplex;
00077         double dSimplexDelta;
00078   double dParamConvTolerance;
00079   double dFunctConvTolerance;
00080   int iNrOfIterations;
00081 
00082   try
00083   {
00084     SessionAccessor::GetParameterValue(pComponentCache,cParam_AutoInitialSimplex,bAutoSimplex,0,iActLevel,true);
00085     SessionAccessor::GetParameterValue(pComponentCache,cParam_SimplexDelta,dSimplexDelta,0,iActLevel,true);
00086     SessionAccessor::GetParameterValue(pComponentCache,cParam_ParamConvTolerance,dParamConvTolerance,0,iActLevel,true);
00087     SessionAccessor::GetParameterValue(pComponentCache,cParam_FunctConvTolerance,dFunctConvTolerance,0,iActLevel,true);
00088     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations,0,iActLevel,true);
00089   }
00090   catchAllNPassMacro("Error while retrieving parameter values.");
00091 
00092         pMainComponent->SetAutomaticInitialSimplex(bAutoSimplex);
00093 
00094   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00095         ComponentType::ParametersType simplexDelta( scales.size() );
00096 
00097   simplexDelta.Fill( dSimplexDelta );
00098         pMainComponent->SetInitialSimplexDelta( simplexDelta );
00099 
00100   pMainComponent->SetScales(scales);
00101   pMainComponent->SetParametersConvergenceTolerance(dParamConvTolerance);
00102   pMainComponent->SetFunctionConvergenceTolerance(dFunctConvTolerance);
00103   pMainComponent->SetMaximumNumberOfIterations(iNrOfIterations);
00104 
00105   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00106   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00107   bool bMinimize;
00108   smpDirection->GetParameterValue(bMinimize);
00109   pMainComponent->SetMaximize( !bMinimize);
00110 };
00111 
00112 void
00113 AmoebaOptimizerController::
00114 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00115                                              ComponentType* pMainComponent,
00116                                              SessionComponentCache* pMainComponentCache,
00117                                              SessionInfo* pSessionInfo,
00118                                              StatisticDictionary& rDictionary) const
00119 {
00120   ParameterArrayType parameters = pMainComponent->GetCachedCurrentPosition();
00121   std::string sName = "Position #";
00122   std::string sIDPath = pMainComponentCache->GetIDPath();
00123   std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00124   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00125     
00126   if (!pEntry) //Entry is not recorded yet, so do so.
00127   {
00128     pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00129     for (unsigned int i = 1; i<parameters.Size(); i++)
00130     {
00131       rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00132     }
00133                 rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Value of the optimizer");
00134   }
00135   
00136   for (unsigned int i = 0; i<parameters.Size(); i++)
00137   {
00138     rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00139   }
00140 
00141   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCachedValue()),pEntry->GetRefID()+parameters.Size());
00142 };
00143 
00144 } //end of namespace free

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