freGradientDescentOptimizerController.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: freGradientDescentOptimizerController.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 "freGradientDescentOptimizerController.h"
00024 #include "freExceptions.h"
00025 
00026 
00027 namespace FREE
00028 {
00029 
00033 
00034 
00035 GradientDescentOptimizerController::
00036 GradientDescentOptimizerController()
00037 {
00038   //Profile settings
00039   this->UpdateControllerID(ControllerID::GradientDescentOptimizerController);
00040   this->m_Description = "Optimizes by a gradient descent approach.";
00041 };
00042 
00043 void
00044 GradientDescentOptimizerController::
00045 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00046                 const SessionComponentCache* pComponentCache,
00047                 bool bRegardOldSetup) const
00048 {
00049   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00050 
00051         //Parameters
00052   profile.Parameters().AddParameter(cParam_LearningRate,CtrlProfile::Parameter::PVTDouble,cParamDsc_LearningRate,1,"20",-1,true);
00053   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTULong,cParamDsc_Iterations,1,"100",-1,true);
00054 };
00055 
00056 void
00057 GradientDescentOptimizerController::
00058 ActualizeMainComponent(ComponentType* pMainComponent,
00059                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00060                                                                                          const unsigned int& iActLevel) const
00061 {
00062   unsigned long lNrOfIterations;
00063   double dLearningRate;
00064   try
00065   {
00066     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,lNrOfIterations,0,iActLevel,true);
00067     SessionAccessor::GetParameterValue(pComponentCache,cParam_LearningRate,dLearningRate,0,iActLevel,true);
00068   }
00069   catchAllNPassMacro("Error while retrieving parameter values.");
00070 
00071   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00072   pMainComponent->SetScales(scales);
00073 
00074   pMainComponent->SetNumberOfIterations(lNrOfIterations);
00075   pMainComponent->SetLearningRate(dLearningRate);
00076 
00077   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00078   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00079   bool bMinimize;
00080   smpDirection->GetParameterValue(bMinimize);
00081   pMainComponent->SetMaximize( !bMinimize);
00082 };
00083 
00084 void
00085 GradientDescentOptimizerController::
00086 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00087                                              ComponentType* pMainComponent,
00088                                              SessionComponentCache* pMainComponentCache,
00089                                              SessionInfo* pSessionInfo,
00090                                              StatisticDictionary& rDictionary) const
00091 {
00092   Superclass::SetStatisticEntryMainComponent(rStatisticEntry, pMainComponent, pMainComponentCache,
00093                                             pSessionInfo, rDictionary);
00094   std::string sName = "OptimizerValue";
00095   std::string sIDPath = pMainComponentCache->GetIDPath();
00096   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath, sName);
00097     
00098   if (!pEntry) //Entry is not recorded yet, so do so.
00099   {
00100     pEntry = rDictionary.AddValueDefinition(sName, sIDPath, "Value of the optimizer");
00101   }
00102 
00103   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetValue()),pEntry->GetRefID());
00104 };
00105 
00106 GradientDescentOptimizerController::MeasuresType
00107 GradientDescentOptimizerController::
00108 GetCurrentValue(ComponentType* pOptimizer) const
00109 {
00110         MeasuresType values(1);
00111         values.Fill(pOptimizer->GetValue());
00112         return values;
00113 };
00114 
00115 } //end of namespace free

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