frePowellOptimizerController.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: frePowellOptimizerController.cxx,v $
00007   Language:  C++
00008 
00009 
00010   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00011   Institute for Medical Biometry and Informatics, University of Heidelberg,
00012   Germany). All rights reserved.
00013   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00014   for details.
00015 
00016      This software is distributed WITHOUT ANY WARRANTY; without even 
00017      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00018      PURPOSE.  See the above copyright notices for more information.
00019 
00020 =========================================================================*/
00021 
00022 #include "frePowellOptimizerController.h"
00023 #include "freExceptions.h"
00024 
00025 namespace FREE
00026 {
00027 
00031 
00032 
00033 
00034 DefineParameterMacro(PowellOptimizerController,MaximumLineIteration,"MaximumLineIteration","Maximum number of line search iterations.");
00035 DefineParameterMacro(PowellOptimizerController,StepLength,"StepLength","StepLength for the (scaled) spacing of the sampling of parameter space while bracketing the extremum");
00036 DefineParameterMacro(PowellOptimizerController,StepTolerance,"StepTolerance","Once the local extreme is known to be within this distance of the current parameter values, optimization terminates.");
00037 DefineParameterMacro(PowellOptimizerController,ValueTolerance,"ValueTolerance","Once this current cost function value is known to be within this tolerance of the cost function value at the local extreme, optimization terminates.");
00038 
00039 PowellOptimizerController::
00040 PowellOptimizerController()
00041 {
00042   //Profile settings
00043   this->UpdateControllerID(ControllerID::PowellOptimizerController);
00044   this->m_Description = "Optimizes by using a Powell optimizer with Brent line search.";
00045 };
00046 
00047 void
00048 PowellOptimizerController::
00049 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00050                 const SessionComponentCache* pComponentCache,
00051                 bool bRegardOldSetup) const
00052 {
00053   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00054 
00055         //Parameters
00056   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"100",-1,true);
00057   profile.Parameters().AddParameter(cParam_MaximumLineIteration,Parameter::PVTInteger,cParamDsc_MaximumLineIteration,1,"100",-1,true);
00058   profile.Parameters().AddParameter(cParam_StepLength,Parameter::PVTDouble,cParamDsc_StepLength,1,"1.0",-1,true);
00059   profile.Parameters().AddParameter(cParam_StepTolerance,Parameter::PVTDouble,cParamDsc_StepTolerance,1,"0.00001",-1,true);
00060   profile.Parameters().AddParameter(cParam_ValueTolerance,Parameter::PVTDouble,cParamDsc_ValueTolerance,1,"0.00001",-1,true);
00061 };
00062 
00063 void
00064 PowellOptimizerController::
00065 ActualizeMainComponent(ComponentType* pMainComponent,
00066                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00067                                                                                          const unsigned int& iActLevel) const
00068 {
00069   double dValueTolerance;
00070   double dStepTolerance;
00071   double dStepLength;
00072   int iNrOfIterations;
00073   int iLineIteration;
00074 
00075   try
00076   {
00077     SessionAccessor::GetParameterValue(pComponentCache,cParam_MaximumLineIteration,iLineIteration,0,iActLevel,true);
00078     SessionAccessor::GetParameterValue(pComponentCache,cParam_StepLength,dStepLength,0,iActLevel,true);
00079     SessionAccessor::GetParameterValue(pComponentCache,cParam_StepTolerance,dStepTolerance,0,iActLevel,true);
00080     SessionAccessor::GetParameterValue(pComponentCache,cParam_ValueTolerance,dValueTolerance,0,iActLevel,true);
00081     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations,0,iActLevel,true);
00082   }
00083   catchAllNPassMacro("Error while retrieving parameter values.");
00084 
00085   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00086   pMainComponent->SetScales(scales);
00087 
00088   pMainComponent->SetMaximumIteration(iNrOfIterations);
00089   pMainComponent->SetMaximumLineIteration(iLineIteration);
00090   pMainComponent->SetStepLength(dStepLength);
00091   pMainComponent->SetStepTolerance(dStepTolerance);
00092   pMainComponent->SetValueTolerance(dValueTolerance);
00093 
00094   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00095   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00096   bool bMinimize;
00097   smpDirection->GetParameterValue(bMinimize);
00098   pMainComponent->SetMaximize( !bMinimize);
00099 };
00100 
00101 void
00102 PowellOptimizerController::
00103 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00104                                              ComponentType* pMainComponent,
00105                                              SessionComponentCache* pMainComponentCache,
00106                                              SessionInfo* pSessionInfo,
00107                                              StatisticDictionary& rDictionary) const
00108 {
00109   Superclass::SetStatisticEntryMainComponent(rStatisticEntry,pMainComponent,
00110                                             pMainComponentCache,pSessionInfo,
00111                                             rDictionary);
00112 
00113   std::string sName = "GlobalIterationID";
00114   std::string sIDPath = pMainComponentCache->GetIDPath();
00115   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName);
00116     
00117   if (!pEntry) //Entry is not recorded yet, so do so.
00118   {
00119     pEntry = rDictionary.AddValueDefinition(sIDPath,sName, "Nr / ID of the global search.");
00120     rDictionary.AddValueDefinition(sIDPath,"LineIterationID", "Nr / ID of the line search iteration.");
00121     rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Composed value of the current optimizer position");
00122   }
00123   
00124   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentIteration()),pEntry->GetRefID());
00125   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentLineIteration()),pEntry->GetRefID()+1);
00126   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCurrentCost()),pEntry->GetRefID()+2);
00127 };
00128 
00129 PowellOptimizerController::MeasuresType
00130 PowellOptimizerController::
00131 GetCurrentValue(ComponentType* pOptimizer) const
00132 {
00133         MeasuresType values(1);
00134         values.Fill(pOptimizer->GetValue());
00135         return values;
00136 };
00137 
00138 } //end of namespace free

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