MethodPDERS.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: MethodPDERS.h 36966 2010-11-26 09:50:13Z evt $
00002 // Author: Andreas Hoecker, Yair Mahalalel, Joerg Stelzer, Helge Voss, Kai Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : MethodPDERS                                                           *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Multidimensional Likelihood using the "Probability density estimator      *
00012  *      range search" (PDERS) method suggested in                                 *
00013  *      T. Carli and B. Koblitz, NIM A 501, 576 (2003)                            *
00014  *                                                                                *
00015  *      The multidimensional PDFs for signal and background are modeled           *
00016  *      by counting the events in the "vicinity" of a test point. The volume      *
00017  *      that describes "vicinity" is user-defined through the option string.      *
00018  *      A search method based on binary-trees is used to improve the selection    *
00019  *      efficiency of the volume search.                                          *
00020  *                                                                                *
00021  * Authors (alphabetical):                                                        *
00022  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00023  *      Yair Mahalalel  <Yair.Mahalalel@cern.ch> - CERN, Switzerland              *
00024  *      Peter Speckmayer <peter.speckmayer@cern.ch>  - CERN, Switzerland          *
00025  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00026  *      Kai Voss        <Kai.Voss@cern.ch>       - U. of Victoria, Canada         *
00027  *                                                                                *
00028  * Copyright (c) 2005:                                                            *
00029  *      CERN, Switzerland                                                         *
00030  *      U. of Victoria, Canada                                                    *
00031  *      MPI-K Heidelberg, Germany                                                 *
00032  *                                                                                *
00033  * Redistribution and use in source and binary forms, with or without             *
00034  * modification, are permitted according to the terms listed in LICENSE           *
00035  * (http://tmva.sourceforge.net/LICENSE)                                          *
00036  **********************************************************************************/
00037 
00038 #ifndef ROOT_TMVA_MethodPDERS
00039 #define ROOT_TMVA_MethodPDERS
00040 
00041 //////////////////////////////////////////////////////////////////////////
00042 //                                                                      //
00043 // MethodPDERS                                                          //
00044 //                                                                      //
00045 // Multidimensional Likelihood using the "Probability density           //
00046 // estimator range search" (PDERS) method                               //
00047 //                                                                      //
00048 //////////////////////////////////////////////////////////////////////////
00049 
00050 #ifndef ROOT_TMVA_MethodBase
00051 #include "TMVA/MethodBase.h"
00052 #endif
00053 #ifndef ROOT_TMVA_BinarySearchTree
00054 #include "TMVA/BinarySearchTree.h"
00055 #endif
00056 #ifndef ROOT_TMVA_TVector
00057 #ifndef ROOT_TVector
00058 #include "TVector.h"
00059 #endif
00060 #endif
00061 
00062 namespace TMVA {
00063 
00064    class Volume;
00065    class Event;
00066 
00067    class MethodPDERS : public MethodBase {
00068 
00069    public:
00070 
00071       MethodPDERS( const TString& jobName,
00072                    const TString& methodTitle, 
00073                    DataSetInfo& theData,
00074                    const TString& theOption,
00075                    TDirectory* theTargetDir = 0 );
00076 
00077       MethodPDERS( DataSetInfo& theData,
00078                    const TString& theWeightFile,
00079                    TDirectory* theTargetDir = NULL );
00080 
00081       virtual ~MethodPDERS( void );
00082 
00083       virtual Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
00084 
00085 
00086       // training method
00087       void Train( void );
00088 
00089       // write weights to file
00090       void WriteWeightsToStream( TFile& rf ) const;
00091       void AddWeightsXMLTo( void* parent ) const;
00092 
00093       // read weights from file
00094       void ReadWeightsFromStream( istream& istr );
00095       void ReadWeightsFromStream( TFile& istr );
00096       void ReadWeightsFromXML( void* wghtnode );
00097 
00098       // calculate the MVA value
00099       Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
00100 
00101       // calculate the MVA value
00102       const std::vector<Float_t>& GetRegressionValues();
00103    public:
00104 
00105       // for root finder
00106       static Double_t IGetVolumeContentForRoot( Double_t );
00107       Double_t         GetVolumeContentForRoot( Double_t );
00108 
00109       // static pointer to this object
00110       static MethodPDERS* ThisPDERS( void );
00111 
00112    protected:
00113 
00114       // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
00115       void MakeClassSpecific( std::ostream&, const TString& ) const;
00116 
00117       // get help message text
00118       void GetHelpMessage() const;
00119 
00120       Volume*      fHelpVolume; // auxiliary variable
00121       Int_t        fFcnCall;    // number of external function calls (RootFinder)
00122 
00123       // accessors
00124       BinarySearchTree* GetBinaryTree( void ) const { return fBinaryTree; }
00125 
00126       Double_t             CKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume& );
00127       void                 RKernelEstimate( const Event&, std::vector<const BinarySearchTreeNode*>&, Volume&, std::vector<Float_t> *pdfSum );
00128 
00129       Double_t ApplyKernelFunction( Double_t normalized_distance );
00130       Double_t KernelNormalization( Double_t pdf );
00131       Double_t GetNormalizedDistance( const TMVA::Event &base_event, 
00132                                       const BinarySearchTreeNode &sample_event, 
00133                                       Double_t *dim_normalization);
00134       Double_t NormSinc( Double_t x );
00135       Double_t LanczosFilter( Int_t level, Double_t x );
00136 
00137       // ranking of input variables
00138       const Ranking* CreateRanking() { return 0; }
00139 
00140    private:
00141 
00142       // the option handling methods
00143       void DeclareOptions();
00144       void ProcessOptions();
00145 
00146       // calculate the averages of the input variables needed for adaptive training
00147       void CalcAverages();
00148 
00149       // create binary search trees for signal and background
00150       void CreateBinarySearchTree( Types::ETreeType type );
00151       
00152       // get sample of training events
00153       void GetSample( const Event &e, std::vector<const BinarySearchTreeNode*>& events, Volume *volume);
00154 
00155       // option
00156       TString fVolumeRange;    // option volume range
00157       TString fKernelString;   // option kernel estimator
00158 
00159       enum EVolumeRangeMode {
00160          kUnsupported = 0,
00161          kMinMax,
00162          kRMS,
00163          kAdaptive,
00164          kUnscaled,
00165          kkNN
00166       } fVRangeMode;
00167 
00168       enum EKernelEstimator {
00169          kBox = 0,
00170          kSphere,
00171          kTeepee,
00172          kGauss,
00173          kSinc3,     // the sinc enumerators must be consecutive and in order!
00174          kSinc5,
00175          kSinc7,
00176          kSinc9,
00177          kSinc11,
00178          kLanczos2,
00179          kLanczos3,
00180          kLanczos5,
00181          kLanczos8,
00182          kTrim
00183       } fKernelEstimator;
00184 
00185       BinarySearchTree*  fBinaryTree;   // binary tree
00186 
00187       std::vector<Float_t>*   fDelta;         // size of volume
00188       std::vector<Float_t>*   fShift;         // volume center
00189       std::vector<Float_t>    fAverageRMS;    // average RMS of signal and background
00190 
00191       Float_t            fScaleS;        // weight for signal events
00192       Float_t            fScaleB;        // weight for background events
00193       Float_t            fDeltaFrac;     // fraction of RMS
00194       Double_t           fGaussSigma;    // size of Gauss in adaptive volume 
00195       Double_t           fGaussSigmaNorm;// size of Gauss in adaptive volume (normalised to dimensions)
00196 
00197       Double_t           fNRegOut;       // number of output dimensions for regression
00198 
00199       // input for adaptive volume adjustment
00200       Float_t            fNEventsMin;    // minimum number of events in adaptive volume
00201       Float_t            fNEventsMax;    // maximum number of events in adaptive volume
00202       Float_t            fMaxVIterations;// maximum number of iterations to adapt volume size
00203       Float_t            fInitialScale;  // initial scale for adaptive volume
00204 
00205       Bool_t             fInitializedVolumeEle; // is volume element initialized ?
00206       
00207       Int_t              fkNNMin;        // min number of events in kNN tree
00208       Int_t              fkNNMax;        // max number of events in kNN tree
00209       
00210       Double_t           fMax_distance;  // maximum distance
00211       Bool_t             fPrinted;       // print
00212       Bool_t             fNormTree;      // binary-search tree is normalised
00213 
00214       void    SetVolumeElement ( void );
00215 
00216       Double_t              CRScalc           ( const Event& );
00217       void                  RRScalc           ( const Event&, std::vector<Float_t>* count );
00218 
00219       Float_t GetError         ( Float_t countS, Float_t countB,
00220                                  Float_t sumW2S, Float_t sumW2B ) const;
00221 
00222       // this carrier
00223       static MethodPDERS* fgThisPDERS; // this pointer (required by root finder)
00224       void UpdateThis();
00225 
00226       void Init( void );
00227 
00228       ClassDef(MethodPDERS,0) // Multi-dimensional probability density estimator range search (PDERS) method
00229    };
00230 
00231 } // namespace TMVA
00232 
00233 #endif // MethodPDERS_H

Generated on Tue Jul 5 14:27:32 2011 for ROOT_528-00b_version by  doxygen 1.5.1