00001 // @(#)root/tmva $Id: MethodPDEFoam.h 36966 2010-11-26 09:50:13Z evt $ 00002 // Author: Tancredi Carli, Dominik Dannheim, Alexander Voigt 00003 00004 /********************************************************************************** 00005 * Project: TMVA - a Root-integrated toolkit for multivariate Data analysis * 00006 * Package: TMVA * 00007 * Class : MethodPDEFoam * 00008 * Web : http://tmva.sourceforge.net * 00009 * * 00010 * Description: * 00011 * The PDEFoam method is an extension of the PDERS method, which divides * 00012 * the multi-dimensional phase space in a finite number of hyper-rectangles * 00013 * (cells) of constant event density. This "foam" of cells is filled with * 00014 * averaged probability-density information sampled from a training event * 00015 * sample. * 00016 * * 00017 * Authors (alphabetical): * 00018 * Tancredi Carli - CERN, Switzerland * 00019 * Dominik Dannheim - CERN, Switzerland * 00020 * Peter Speckmayer <peter.speckmayer@cern.ch> - CERN, Switzerland * 00021 * Alexander Voigt - CERN, Switzerland * 00022 * * 00023 * Original author of the TFoam implementation: * 00024 * S. Jadach - Institute of Nuclear Physics, Cracow, Poland * 00025 * * 00026 * Copyright (c) 2008: * 00027 * CERN, Switzerland * 00028 * MPI-K Heidelberg, Germany * 00029 * * 00030 * Redistribution and use in source and binary forms, with or without * 00031 * modification, are permitted according to the terms listed in LICENSE * 00032 * (http://tmva.sourceforge.net/LICENSE) * 00033 **********************************************************************************/ 00034 00035 #ifndef ROOT_TMVA_MethodPDEFoam 00036 #define ROOT_TMVA_MethodPDEFoam 00037 00038 ////////////////////////////////////////////////////////////////////////////// 00039 // // 00040 // MethodPDEFoam // 00041 // // 00042 // The PDEFoam method is an // 00043 // extension of the PDERS method, which divides the multi-dimensional // 00044 // phase space in a finite number of hyper-rectangles (cells) of constant // 00045 // event density. // 00046 // This "foam" of cells is filled with averaged probability-density // 00047 // information sampled from a training event sample. // 00048 // // 00049 // For a given number of cells, the binning algorithm adjusts the size // 00050 // and position of the cells inside the multidimensional phase space // 00051 // based on a binary-split algorithm, minimizing the variance of the // 00052 // event density in the cell. // 00053 // The binned event density information of the final foam is stored in // 00054 // binary trees, allowing for a fast and memory-efficient classification // 00055 // of events. // 00056 // // 00057 // The implementation of PDEFoam is based on the Monte-Carlo integration // 00058 // package TFoam included in the analysis package ROOT. // 00059 // // 00060 ////////////////////////////////////////////////////////////////////////////// 00061 00062 #ifndef ROOT_TRandom3 00063 #include "TRandom3.h" 00064 #endif 00065 00066 #ifndef ROOT_TMVA_MethodBase 00067 #include "TMVA/MethodBase.h" 00068 #endif 00069 00070 #ifndef ROOT_TMVA_PDEFoam 00071 #include "TMVA/PDEFoam.h" 00072 #endif 00073 00074 namespace TMVA { 00075 00076 class MethodPDEFoam : public MethodBase { 00077 00078 public: 00079 00080 MethodPDEFoam( const TString& jobName, 00081 const TString& methodTitle, 00082 DataSetInfo& dsi, 00083 const TString& theOption = "PDEFoam", 00084 TDirectory* theTargetDir = 0 ); 00085 00086 MethodPDEFoam( DataSetInfo& dsi, 00087 const TString& theWeightFile, 00088 TDirectory* theTargetDir = NULL ); 00089 00090 virtual ~MethodPDEFoam( void ); 00091 00092 virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets ); 00093 00094 // training methods 00095 void Train( void ); 00096 void TrainMonoTargetRegression( void ); // Regression output: one value 00097 void TrainMultiTargetRegression( void ); // Regression output: any number of values 00098 void TrainSeparatedClassification( void ); // Classification: one foam for Sig, one for Bg 00099 void TrainUnifiedClassification( void ); // Classification: one foam for Signal and Bg 00100 00101 using MethodBase::ReadWeightsFromStream; 00102 00103 // write weights to stream 00104 void AddWeightsXMLTo( void* parent ) const; 00105 00106 // read weights from stream 00107 void ReadWeightsFromStream( std::istream & i ); 00108 void ReadWeightsFromXML ( void* wghtnode ); 00109 00110 // write/read pure foams to/from file 00111 void WriteFoamsToFile() const; 00112 void ReadFoamsFromFile(); 00113 00114 // calculate the MVA value 00115 Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 ); 00116 00117 // regression procedure 00118 virtual const std::vector<Float_t>& GetRegressionValues(); 00119 00120 // ranking of input variables 00121 const Ranking* CreateRanking() { return 0; } 00122 00123 // helper functions to convert enum types to UInt_t and back 00124 EKernel GetKernel( void ) { return fKernel; } 00125 UInt_t KernelToUInt(EKernel ker) const { return UInt_t(ker); } 00126 EKernel UIntToKernel(UInt_t iker); 00127 UInt_t TargetSelectionToUInt(ETargetSelection ts) const { return UInt_t(ts); } 00128 ETargetSelection UIntToTargetSelection(UInt_t its); 00129 00130 protected: 00131 00132 // make ROOT-independent C++ class for classifier response (classifier-specific implementation) 00133 void MakeClassSpecific( std::ostream&, const TString& ) const; 00134 00135 // get help message text 00136 void GetHelpMessage() const; 00137 00138 // calculate Xmin and Xmax for Foam 00139 void CalcXminXmax(); 00140 00141 // Set Xmin, Xmax in foam with index 'foam_index' 00142 void SetXminXmax(TMVA::PDEFoam*); 00143 00144 // Set foam options 00145 void InitFoam(TMVA::PDEFoam*, EFoamType); 00146 00147 // fill variable names into foam 00148 void FillVariableNamesToFoam() const; 00149 00150 private: 00151 00152 // the option handling methods 00153 void DeclareOptions(); 00154 void DeclareCompatibilityOptions(); 00155 void ProcessOptions(); 00156 00157 // nice output 00158 void PrintCoefficients( void ); 00159 00160 // Square function (fastest implementation) 00161 template<typename T> T Sqr(T x) const { return x*x; } 00162 00163 // options to be used 00164 Bool_t fSigBgSeparated; // Separate Sig and Bg, or not 00165 Double_t fFrac; // Fraction used for calc of Xmin, Xmax 00166 Double_t fDiscrErrCut; // cut on discrimant error 00167 Float_t fVolFrac; // inverse volume fraction (used for density calculation during buildup) 00168 Float_t fVolFracInv; // volume fraction (used for density calculation during buildup) 00169 Int_t fnCells; // Number of Cells (1000) 00170 Int_t fnActiveCells; // Number of active cells 00171 Int_t fnSampl; // Number of MC events per cell in build-up (1000) 00172 Int_t fnBin; // Number of bins in build-up (100) 00173 Int_t fEvPerBin; // Maximum events (equiv.) per bin in buid-up (1000) 00174 00175 Bool_t fCompress; // compress foam output file 00176 Bool_t fMultiTargetRegression; // do regression on multible targets 00177 UInt_t fNmin; // minimal number of events in cell necessary to split cell" 00178 Bool_t fCutNmin; // Keep for bw compatibility: Grabbing cell with maximal RMS to split next (TFoam default) 00179 UInt_t fMaxDepth; // maximum depth of cell tree 00180 00181 TString fKernelStr; // Kernel for GetMvaValue() (option string) 00182 EKernel fKernel; // Kernel for GetMvaValue() 00183 TString fTargetSelectionStr; // method of selecting the target (only mulit target regr.) 00184 ETargetSelection fTargetSelection; // method of selecting the target (only mulit target regr.) 00185 Bool_t fFillFoamWithOrigWeights; // fill the foam with boost weights 00186 Bool_t fUseYesNoCell; // return -1 or 1 for bg or signal like event 00187 TString fDTLogic; // use DT algorithm to split cells 00188 EDTSeparation fDTSeparation; // enum which specifies the separation to use for the DT logic 00189 Bool_t fPeekMax; // peek up cell with max. driver integral for split 00190 00191 std::vector<Double_t> fXmin, fXmax; // range for histograms and foams 00192 00193 // foams and densities 00194 // foam[0]=signal, if Sig and BG are Seperated; else foam[0]=signal/bg 00195 // foam[1]=background, if Sig and BG are Seperated; else it is not used 00196 std::vector<PDEFoam*> fFoam; 00197 00198 // default initialisation called by all constructors 00199 void Init( void ); 00200 00201 ClassDef(MethodPDEFoam,0) // Analysis of PDEFoam discriminant (PDEFoam or Mahalanobis approach) 00202 }; 00203 00204 } // namespace TMVA 00205 00206 #endif // MethodPDEFoam_H