freConstrainedImageClassificationSOMetricController.h

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: freConstrainedImageClassificationSOMetricController.h,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 #ifndef __freConstrainedImageClassificationSOMetricController_h
00023 #define __freConstrainedImageClassificationSOMetricController_h
00024 
00025 #include "freImageClassificationSOMetricController.h"
00026 
00027 #include "freConstrainedImageClassificationSOMetric.h"
00028 
00029 namespace FREE
00030 {
00031 
00040         freControllerIDMacro(ConstrainedImageClassificationSOMetricControllerBase, "ConstrainedImageClassificationSOMetricBase");
00041 template <class TControlledMetric>
00042 class ConstrainedImageClassificationSOMetricControllerBase : public ImageClassificationSOMetricControllerBase<TControlledMetric>
00043 {
00044 public:  
00045   DeclareParameterMacro(MaxConstraintPenalty);
00046   DeclareParameterMacro(FailureThreshold);
00047   DeclareParameterMacro(Constraints);
00048 
00049         typedef TControlledMetric ComponentType;
00050   typedef ImageClassificationSOMetricControllerBase<ComponentType> Superclass;
00051 
00052         itkTypeMacro(ConstrainedImageClassificationSOMetricControllerBase, ImageClassificationSOMetricControllerBase);
00053 
00054 protected:
00055         ConstrainedImageClassificationSOMetricControllerBase()
00056         {
00057                 //Profile settings
00058                 this->UpdateControllerID(ControllerID::ConstrainedSetupOptimizationMetricControllerBase);
00059                 this->UpdateControllerID(ControllerID::ImageClassificationSOMetricControllerBase);
00060                 this->UpdateControllerID(ControllerID::ConstrainedImageClassificationSOMetricControllerBase);
00061                 this->m_Description = "Base class for image difference setup optimization metric which supports constraints.";
00062         };
00063 
00064   virtual void GenerateProfile(CtrlProfile::ControllerProfile& profile,
00065                   const SessionComponentCache* pComponentCache,
00066                   bool bRegardOldSetup) const
00067   {
00068     Superclass::GenerateProfile(profile,pComponentCache,bRegardOldSetup);
00069 
00070                 //Parameters
00071                 profile.Parameters().AddParameter(cParam_Constraints,CtrlProfile::Parameter::PVTString,cParamDsc_Constraints,4,"",-1);
00072                 profile.Parameters().AddParameter(cParam_MaxConstraintPenalty,CtrlProfile::Parameter::PVTDouble,cParamDsc_MaxConstraintPenalty,1,"0");
00073                 profile.Parameters().AddParameter(cParam_FailureThreshold,CtrlProfile::Parameter::PVTDouble,cParamDsc_FailureThreshold,1,"0.0");
00074   };
00075 
00076         virtual void ActualizeMainComponent(ComponentType* pMainComponent,
00077                                       SessionComponentCache* pComponentCache,
00078                                       SessionInfo* pSessionInfo,
00079                                                                                                                                                         const unsigned int& iActLevel) const
00080         {
00081                 Superclass::ActualizeMainComponent(pMainComponent, pComponentCache,
00082                                                                                                                                                          pSessionInfo, iActLevel);
00083 
00084                 double dMaxPenalty;
00085                 double dThreshold;
00086 
00087     Parameter::Pointer smpConstraints = SessionAccessor::GetParameter(pComponentCache,cParam_Constraints);
00088                 if (smpConstraints.IsNull()) throwExceptionMacro("Missing parameter: " << cParam_Constraints);
00089 
00090                 for (unsigned int index = 0; index < smpConstraints->LayerCount(); index++)
00091                 {
00092                         int iParamID;
00093                         std::string sRelationType;
00094                         std::string sTerm;
00095                         double dBarrierSize;
00096 
00097                         if (!smpConstraints->GetParameterValue(iParamID,0,index)) throwExceptionMacro("Faulty parameter; cannot retrieve parameter id. constraint #: " << index);
00098                         if (!smpConstraints->GetParameterValue(sRelationType,1,index)) throwExceptionMacro("Faulty parameter; cannot retrieve relation type. constraint #: " << index);
00099                         if (!smpConstraints->GetParameterValue(sTerm,2,index)) throwExceptionMacro("Faulty parameter; cannot retrieve constraint term. constraint #: " << index);
00100                         if (!smpConstraints->GetParameterValue(dBarrierSize,3,index)) throwExceptionMacro("Faulty parameter; cannot retrieve barrier size. constraint #: " << index);
00101 
00102       SetupParameterConstraint::Pointer smpNewCnstr = SetupParameterConstraint::New(iParamID,Convert::ToRelationType(sRelationType),sTerm);
00103                         pMainComponent->AddConstraint(*(smpNewCnstr.GetPointer()),dBarrierSize);
00104                 }
00105 
00106     try
00107     {
00108       SessionAccessor::GetParameterValue(pComponentCache,cParam_MaxConstraintPenalty,dMaxPenalty);
00109       SessionAccessor::GetParameterValue(pComponentCache,cParam_FailureThreshold,dThreshold);
00110     }
00111     catchAllNPassMacro("Error while retrieving parameter values.");    
00112 
00113                 pMainComponent->SetMaxConstraintPenalty(dMaxPenalty);
00114                 pMainComponent->SetFailureThreshold(dThreshold);
00115         };
00116 
00117         void
00118         SetStatisticEntryMainComponent(StatisticEntry& rStatisticEntry,
00119                                              ComponentType* pMainComponent,
00120                                              SessionComponentCache* pMainComponentCache,
00121                                              SessionInfo* pSessionInfo,
00122                                              StatisticDictionary& rDictionary) const
00123         {
00124                 typename ComponentType::DecomposedMeasureType values = pMainComponent->GetCurrentDecomposedValue();
00125 
00126                 std::string sIDPath = pMainComponentCache->GetIDPath();
00127                 StatisticValueDefinition* pEntry = rDictionary.GetValueDefinitionByName(sIDPath,"mean sensitivity");
00128             
00129                 if (!pEntry) //Entry is not recorded yet, so do so.
00130                 {
00131                         pEntry = rDictionary.AddValueDefinition(sIDPath,"mean sensitivity", "mean sensitivity");
00132                         rDictionary.AddValueDefinition(sIDPath,"std sensitivity", "standard deviation of sensitivity.");
00133                         rDictionary.AddValueDefinition(sIDPath,"min sensitivity", "minimum sensitivity");
00134                         rDictionary.AddValueDefinition(sIDPath,"max sensitivity", "maximum sensitivity");
00135                   rDictionary.AddValueDefinition(sIDPath,"mean specificity", "mean specificity");
00136                         rDictionary.AddValueDefinition(sIDPath,"std specificity", "standard deviation of specificity.");
00137                         rDictionary.AddValueDefinition(sIDPath,"min specificity", "minimum specificity");
00138                         rDictionary.AddValueDefinition(sIDPath,"max specificity", "maximum specificity");
00139                   rDictionary.AddValueDefinition(sIDPath,"mean ppv", "mean ppv (positive predictive value)");
00140                         rDictionary.AddValueDefinition(sIDPath,"std ppv", "standard deviation of ppv.");
00141                         rDictionary.AddValueDefinition(sIDPath,"min ppv", "minimum ppv");
00142                         rDictionary.AddValueDefinition(sIDPath,"max ppv", "maximum ppv");
00143                   rDictionary.AddValueDefinition(sIDPath,"mean npv", "mean npv (negative predictive value)");
00144                         rDictionary.AddValueDefinition(sIDPath,"std npv", "standard deviation of npv.");
00145                         rDictionary.AddValueDefinition(sIDPath,"min npv", "minimum npv");
00146                         rDictionary.AddValueDefinition(sIDPath,"max npv", "maximum npv");
00147                   rDictionary.AddValueDefinition(sIDPath,"mean fm", "mean f-measure (negative predictive value)");
00148                         rDictionary.AddValueDefinition(sIDPath,"std fm", "standard deviation of fm.");
00149                         rDictionary.AddValueDefinition(sIDPath,"min fm", "minimum fm");
00150                         rDictionary.AddValueDefinition(sIDPath,"max fm", "maximum fm");
00151                         rDictionary.AddValueDefinition(sIDPath,"failure", "number of failed evaluations");
00152                         rDictionary.AddValueDefinition(sIDPath,"mean duration", "mean duration of an evaluation (tenth of a second).");
00153                         rDictionary.AddValueDefinition(sIDPath,"std duration", "standard deviation of an evaluation (tenth of a second).");
00154                         rDictionary.AddValueDefinition(sIDPath,"min duration", "minimum duration of an evaluation (tenth of a second).");
00155                         rDictionary.AddValueDefinition(sIDPath,"max duration", "maximum duration of an evaluation (tenth of a second).");
00156  
00157                         for (unsigned int i = 0; i<values.Size()-25; i++)
00158                         {
00159                                 rDictionary.AddValueDefinition(sIDPath,"constraint penalty #"+Convert::ToStr(i), "penalty of the constraint #"+Convert::ToStr(i));
00160                         }
00161                 }
00162           
00163                 for (unsigned int i = 0; i<values.Size(); i++)
00164                 {
00165                         rStatisticEntry.AddValue(Convert::ToStr(values[i]),pEntry->GetRefID()+i);
00166                 }
00167         };
00168 
00169 };
00170 
00171 template <class TControlledMetric>
00172 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParam_Constraints = "Constraints";
00173 template <class TControlledMetric>
00174 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParamDsc_Constraints = "The constraints of the metric. First element is the ID of the constrained parameter, second value indicates the type of relation (0: equal; 1: lesser or equal; 2: greater or equal). The third value is the constraint term. The fourth value is the barrier size.\nParameter IDs, if used in the term have an underscore as prefix.\nExample: 1 | 2 | (_2 * 4) + _3\nBy this constrained parameter 1 should be greater or equal four times parameter 2 + parameter 3.";
00175 
00176 template <class TControlledMetric>
00177 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParam_MaxConstraintPenalty = "MaxConstraintPenalty";
00178 template <class TControlledMetric>
00179 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParamDsc_MaxConstraintPenalty = "Maximum penalty the barrier function of a constraint can return. This value will be scaled be metric scales, if there is any defined for a constrained.";
00180 
00181 template <class TControlledMetric>
00182 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParam_FailureThreshold = "FailureThreshold";
00183 template <class TControlledMetric>
00184 const char* const ConstrainedImageClassificationSOMetricControllerBase<TControlledMetric>::cParamDsc_FailureThreshold = "Threshold for the penalty computation, if the penalty is equal or above this threshold, the computation will be accounted as a failure. No evaluations of the adaptations will be done. A value of 0.0 or less deactivates the threshold.";
00185 
00194         freControllerIDMacro(ConstrainedImageClassification2DSOMetricController, "Constrained Image Classification 2D SO Metric");
00195 class ConstrainedImageClassification2DSOMetricController : public ConstrainedImageClassificationSOMetricControllerBase< ConstrainedImageClassificationSOMetric<2> >
00196 {
00197 public:  
00198   typedef ConstrainedImageClassificationSOMetric<2> ComponentType;
00199   typedef ConstrainedImageClassificationSOMetricControllerBase<ComponentType> Superclass;
00200 
00201         itkTypeMacro(ConstrainedConstrainedImageClassification2DSOMetricController, ConstrainedImageClassificationSOMetricControllerBase);
00202 
00203   ConstrainedImageClassification2DSOMetricController();
00204 
00205 };
00206 
00215         freControllerIDMacro(ConstrainedImageClassification3DSOMetricController, "Constrained Image Classification 3D SO Metric");
00216 class ConstrainedImageClassification3DSOMetricController : public ConstrainedImageClassificationSOMetricControllerBase< ConstrainedImageClassificationSOMetric<3> >
00217 {
00218 public:  
00219   typedef ConstrainedImageClassificationSOMetric<3> ComponentType;
00220   typedef ConstrainedImageClassificationSOMetricControllerBase<ComponentType> Superclass;
00221 
00222         itkTypeMacro(ConstrainedConstrainedImageClassification3DSOMetricController, ConstrainedImageClassificationSOMetricControllerBase);
00223 
00224   ConstrainedImageClassification3DSOMetricController();
00225 
00226 };
00227 
00228 } //end of namespace free
00229 
00230 #endif

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