frePrecisionSOMetricController.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: frePrecisionSOMetricController.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 "frePrecisionSOMetricController.h"
00024 #include "freExceptions.h"
00025 
00026 namespace FREE
00027 {
00028 
00029 DefineParameterMacro(PrecisionSOMetricController,SampleSize,"SampleSize","Number of metric evaluations that will be used to compute the precision.");
00030 
00034 PrecisionSOMetricController::
00035 PrecisionSOMetricController()
00036 {
00037         //Profile settings
00038         this->UpdateControllerID(ControllerID::PrecisionSOMetricController);
00039         this->m_Description = "Controller for a precision metric.";
00040 };
00041 
00042 void
00043 PrecisionSOMetricController::
00044 GenerateProfile(CtrlProfile::ControllerProfile& profile,
00045                 const SessionComponentCache* pComponentCache,
00046                 bool bRegardOldSetup) const
00047 {
00048   Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00049 
00050         //Parameters
00051   unsigned int iCount = 0;
00052   if (bRegardOldSetup)
00053   {
00054     IDPath paramPath = pComponentCache->GetIDPath();
00055     paramPath = paramPath+IDPath("./EvaluationMetric/@MetricScales");
00056     Parameter::Pointer metricScales = SessionAccessor::GetParameterByIDPath(pComponentCache,paramPath);
00057 
00058     if ( metricScales.IsNotNull()) iCount = metricScales->ParameterSize();
00059   }
00060   profile.Parameters().AddParameter(Superclass::cParam_MetricScales,CtrlProfile::Parameter::PVTDouble,Superclass::cParamDsc_MetricScales,iCount,"1.0");
00061         profile.Parameters().AddParameter(cParam_SampleSize,CtrlProfile::Parameter::PVTULong,cParamDsc_SampleSize,1,"10");
00062 
00063   //Subcomponents
00064   profile.SubComponents().AddSubComponent("EvaluationMetric");
00065 
00066   //Requirements
00067         CtrlProfile::ProfileOption* pOption;
00068     //metric
00069         pOption = profile.Requirements().AddRequirement("EvaluationMetric")->AddProfileOption();
00070         pOption->Inheritance().AddAncestor(ControllerID::SetupOptimizationMetricControllerBase);
00071         pOption->CheckForInheritance();
00072 };
00073 
00074 PrecisionSOMetricController::GenericComponentType* 
00075 PrecisionSOMetricController::
00076 GetSubComponentCasted(ComponentType* pMainComponent, const ComponentID& compID,
00077                       SessionComponentCache* pMainComponentCache) const
00078 {
00079         if (compID == "EvaluationMetric") return pMainComponent->GetEvaluationMetric();
00080 
00081         return ComponentControllerBase<ComponentType>::GetSubComponentCasted(pMainComponent, compID, pMainComponentCache);
00082 }; 
00083 
00084 void
00085 PrecisionSOMetricController::
00086 SetSubComponentCasted(GenericComponentType* pSubComponent, ComponentType* pMainComponent,
00087                       const ComponentID compID, SessionComponentCache* pMainComponentCache) const
00088 {
00089   if (compID == "EvaluationMetric") pMainComponent->SetEvaluationMetric(static_cast<SetupOptimizationMetric*>(pSubComponent));
00090   else ComponentControllerBase<ComponentType>::SetSubComponentCasted(pSubComponent, pMainComponent, compID, pMainComponentCache);
00091 }; 
00092 
00093 void
00094 PrecisionSOMetricController::
00095 ActualizeMainComponent(ComponentType* pMainComponent,
00096                        SessionComponentCache* pComponentCache,
00097                        SessionInfo* pSessionInfo,
00098                                                                                  const unsigned int& iActLevel) const
00099 {
00100         Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00101                                                                                                                                                  pSessionInfo, iActLevel);
00102 
00103   unsigned long lSampleSize;
00104 
00105         if (!pComponentCache->Setup()->Parameters().GetParameterValue(cParam_SampleSize,lSampleSize)) throwExceptionMacro("Missing parameter: " << cParam_SampleSize);
00106 
00107         pMainComponent->SetSampleSize(lSampleSize);
00108 };
00109 
00110 void
00111 PrecisionSOMetricController::
00112 SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00113                               ComponentType* pMainComponent,
00114                               SessionComponentCache* pMainComponentCache,
00115                               SessionInfo* pSessionInfo,
00116                               StatisticDictionary& rDictionary) const
00117 {
00118         ComponentType::DecomposedMeasureType values = pMainComponent->GetCurrentDecomposedValue();
00119 
00120   std::string sIDPath = pMainComponentCache->GetIDPath();
00121   StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"mean #1");
00122     
00123         if (!pEntry && values.Size()!=0) //Entry is not recorded yet, so do so.
00124         {
00125     unsigned int iValueNr = 1;
00126     for (unsigned int i = 0; i<values.Size(); i=i+4)
00127     {
00128       rDictionary.AddValueDefinition(sIDPath,"mean #"+Convert::ToStr(iValueNr), "mean of evaluation metric value #"+Convert::ToStr(iValueNr));
00129       rDictionary.AddValueDefinition(sIDPath,"std dev #"+Convert::ToStr(iValueNr), "standard deviation of evaluation metric value #"+Convert::ToStr(iValueNr));
00130       rDictionary.AddValueDefinition(sIDPath,"min #"+Convert::ToStr(iValueNr), "minimum of evaluation metric value #"+Convert::ToStr(iValueNr));
00131       rDictionary.AddValueDefinition(sIDPath,"max #"+Convert::ToStr(iValueNr), "maximum of evaluation metric value #"+Convert::ToStr(iValueNr));
00132       iValueNr++;
00133     }
00134         }
00135 
00136   pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"mean #1");
00137 
00138         for (unsigned int i = 0; i<values.Size(); i++)
00139         {
00140                 rStatisticEntry.AddValue(Convert::ToStr(values[i]),pEntry->GetRefID()+i);
00141         }
00142 };
00143 
00144 
00145 
00146 } //end of namespace free

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