freContinuousLBFGSOptimizerController.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: freContinuousLBFGSOptimizerController.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 "freContinuousLBFGSOptimizerController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00032 
00033 DefineParameterMacro(ContinuousLBFGSOptimizerController,GradConvTolerance,"GradConvTolerance","Treshold for the accuracy with which the solution is to be found.");
00034 DefineParameterMacro(ContinuousLBFGSOptimizerController,LineSearchAccuracy,"LineSearchAccuracy","Accuracy of the line search.");
00035 DefineParameterMacro(ContinuousLBFGSOptimizerController,DefaultStepLength,"DefaultStepLength","Step size for the line search.");
00036 DefineParameterMacro(ContinuousLBFGSOptimizerController,TraceOn,"TraceOn","Optimizer should print his progress.");
00037 
00038 ContinuousLBFGSOptimizerController::
00039 ContinuousLBFGSOptimizerController()
00040 {
00041   //Profile settings
00042   this->UpdateControllerID(ControllerID::ContinuousLBFGSOptimizerController);
00043   this->m_Description = "Optimizes by an amoeba optimizer approach.";
00044 };
00045 
00046 void
00047 ContinuousLBFGSOptimizerController::
00048 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00049                 const SessionComponentCache* pComponentCache,
00050                 bool bRegardOldSetup) const
00051 {
00052   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00053 
00054         //Parameters
00055   profile.Parameters().AddParameter(cParam_GradConvTolerance,CtrlProfile::Parameter::PVTDouble,cParamDsc_GradConvTolerance,1,"1.0",-1,true);
00056   profile.Parameters().AddParameter(cParam_LineSearchAccuracy,CtrlProfile::Parameter::PVTDouble,cParamDsc_LineSearchAccuracy,1,"0.9",-1,true);
00057   profile.Parameters().AddParameter(cParam_DefaultStepLength,CtrlProfile::Parameter::PVTDouble,cParamDsc_DefaultStepLength,1,"1.0",-1,true);
00058   profile.Parameters().AddParameter(cParam_TraceOn,CtrlProfile::Parameter::PVTBool,cParamDsc_TraceOn,1,"true");
00059   profile.Parameters().AddParameter(cParam_Iterations,Parameter::PVTInteger,cParamDsc_Iterations,1,"100",-1,true);
00060 };
00061 
00062 void
00063 ContinuousLBFGSOptimizerController::
00064 ActualizeMainComponent(ComponentType* pMainComponent,
00065                        SessionComponentCache* pComponentCache, SessionInfo* pSessionInfo,
00066                                                                                          const unsigned int& iActLevel) const
00067 {
00068   double dGradConvTolerance;
00069   double dLineSearchAcc;
00070   double dDefStepLength;
00071   int iNrOfIterations;
00072   bool bTraceOn;
00073 
00074   try
00075   {
00076     SessionAccessor::GetParameterValue(pComponentCache,cParam_GradConvTolerance,dGradConvTolerance,0,iActLevel,true);
00077     SessionAccessor::GetParameterValue(pComponentCache,cParam_LineSearchAccuracy,dLineSearchAcc,0,iActLevel,true);
00078     SessionAccessor::GetParameterValue(pComponentCache,cParam_DefaultStepLength,dDefStepLength,0,iActLevel,true);
00079     SessionAccessor::GetParameterValue(pComponentCache,cParam_TraceOn,bTraceOn);
00080     SessionAccessor::GetParameterValue(pComponentCache,cParam_Iterations,iNrOfIterations,0,iActLevel,true);
00081   }
00082   catchAllNPassMacro("Error while retrieving parameter values.");
00083 
00084   ParameterArrayType scales = this->GetTransformScales(pComponentCache,iActLevel);
00085   pMainComponent->SetScales(scales);
00086 
00087   pMainComponent->SetDefaultStepLength(dDefStepLength);
00088   pMainComponent->SetGradientConvergenceTolerance(dGradConvTolerance);
00089   pMainComponent->SetLineSearchAccuracy (dLineSearchAcc);
00090   pMainComponent->SetMaximumNumberOfFunctionEvaluations(iNrOfIterations);
00091   pMainComponent->SetTrace(bTraceOn);
00092 
00093   Parameter::Pointer smpDirection = pComponentCache->GetParentCache()->Controller()->GetParameter(pComponentCache->GetParentCache(),OptimizerOwnerControllerInterface::cParam_MinimizeToOptimize);
00094   if (smpDirection.IsNull()) throwCtrlExceptionMacro("","Cannot retrieve optimization direction via optimizer owner. Parameter \"MinimizeToOptimize\" is unknown. Please ensure valid session and setup");
00095   bool bMinimize;
00096   smpDirection->GetParameterValue(bMinimize);
00097   pMainComponent->SetMaximize( !bMinimize);
00098 };
00099 
00100 void
00101 ContinuousLBFGSOptimizerController::
00102 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00103                                              ComponentType* pMainComponent,
00104                                              SessionComponentCache* pMainComponentCache,
00105                                              SessionInfo* pSessionInfo,
00106                                              StatisticDictionary& rDictionary) const
00107 {
00108   StatisticValueDefinition* pEntry = 0;
00109   std::string sIDPath = pMainComponentCache->GetIDPath();
00110 
00111   if (pMainComponent->GetTrace())
00112   {
00113     ParameterArrayType parameters = pMainComponent->GetCachedCurrentPosition();
00114     std::string sName = "Position #";
00115     std::string sCommment = "Optimizer position. Meaning depends on chosen transformation";
00116     
00117     pEntry = rDictionary.GetValueDefinitionByName(sIDPath,sName+"0");
00118 
00119     if (!pEntry)
00120     {
00121       pEntry = rDictionary.AddValueDefinition(sIDPath,sName+"0", sCommment);
00122       for (unsigned int i = 1; i<parameters.Size(); i++)
00123       {
00124         rDictionary.AddValueDefinition(sIDPath,sName+Convert::ToStr(i),sCommment);
00125       }
00126     }
00127 
00128     for (unsigned int i = 0; i<parameters.Size(); i++)
00129     {
00130       rStatisticEntry.AddValue(Convert::ToStr(parameters.GetElement(i)),pEntry->GetRefID()+i);
00131     }
00132   }
00133 
00134   pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"OptimizerValue");
00135   if (!pEntry) //Entry is not recorded yet, so do so.
00136   {
00137     pEntry = rDictionary.AddValueDefinition(sIDPath,"OptimizerValue", "Value of the optimizer");
00138   }
00139   rStatisticEntry.AddValue(Convert::ToStr(pMainComponent->GetCachedValue()),pEntry->GetRefID());
00140 };
00141 
00142 } //end of namespace free

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