MethodFDA.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: MethodFDA.h 36966 2010-11-26 09:50:13Z evt $
00002 // Author: Andreas Hoecker, Peter Speckmayer
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : MethodFDA                                                             *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Function discriminant analysis (FDA). This simple classifier              *
00012  *      fits any user-defined TFormula (via option configuration string) to       *
00013  *      the training data by requiring a formula response of 1 (0) to signal      *
00014  *      (background) events. The parameter fitting is done via the abstract       *
00015  *      class FitterBase, featuring Monte Carlo sampling, Genetic                 *
00016  *      Algorithm, Simulated Annealing, MINUIT and combinations of these.         *
00017  *                                                                                *
00018  * Authors (alphabetical):                                                        *
00019  *      Andreas Hoecker  <Andreas.Hocker@cern.ch> - CERN, Switzerland             *
00020  *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
00021  *                                                                                *
00022  * Copyright (c) 2005-2010:                                                       *
00023  *      CERN, Switzerland                                                         *
00024  *      MPI-K Heidelberg, Germany                                                 *
00025  *                                                                                *
00026  * Redistribution and use in source and binary forms, with or without             *
00027  * modification, are permitted according to the terms listed in LICENSE           *
00028  * (http://tmva.sourceforge.net/LICENSE)                                          *
00029  **********************************************************************************/
00030 
00031 #ifndef ROOT_TMVA_MethodFDA
00032 #define ROOT_TMVA_MethodFDA
00033 
00034 //////////////////////////////////////////////////////////////////////////
00035 //                                                                      //
00036 // MethodFDA                                                            //
00037 //                                                                      //
00038 // Function discriminant analysis (FDA). This simple classifier         //
00039 // fits any user-defined TFormula (via option configuration string) to  //
00040 // the training data by requiring a formula response of 1 (0) to signal //
00041 // (background) events. The parameter fitting is done via the abstract  //
00042 // class FitterBase, featuring Monte Carlo sampling, Genetic            //
00043 // Algorithm, Simulated Annealing, MINUIT and combinations of these.    //
00044 //                                                                      //
00045 // Can compute one-dimensional regression                               //
00046 //                                                                      //
00047 //////////////////////////////////////////////////////////////////////////
00048 
00049 #ifndef ROOT_TMVA_MethodBase
00050 #include "TMVA/MethodBase.h"
00051 #endif
00052 #ifndef ROOT_TMVA_IFitterTarget
00053 #include "TMVA/IFitterTarget.h"
00054 #endif
00055 
00056 class TFormula;
00057 
00058 namespace TMVA {
00059 
00060    class Interval;
00061    class Event;
00062    class FitterBase;
00063 
00064    class MethodFDA : public MethodBase, public IFitterTarget {
00065 
00066    public:
00067 
00068       MethodFDA( const TString& jobName,
00069                  const TString& methodTitle,
00070                  DataSetInfo& theData,
00071                  const TString& theOption = "",
00072                  TDirectory* theTargetDir = 0 );
00073 
00074       MethodFDA( DataSetInfo& theData,
00075                  const TString& theWeightFile,
00076                  TDirectory* theTargetDir = NULL );
00077 
00078       virtual ~MethodFDA( void );
00079 
00080       Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
00081 
00082       // training method
00083       void Train( void );
00084 
00085       using MethodBase::ReadWeightsFromStream;
00086 
00087       void AddWeightsXMLTo      ( void* parent     ) const;
00088 
00089       void ReadWeightsFromStream( std::istream & i );
00090       void ReadWeightsFromXML   ( void* wghtnode );
00091 
00092       // calculate the MVA value
00093       Double_t GetMvaValue( Double_t* err = 0, Double_t* errUpper = 0 );
00094 
00095       virtual const std::vector<Float_t>& GetRegressionValues();
00096       virtual const std::vector<Float_t>& GetMulticlassValues();
00097 
00098       void Init( void );
00099 
00100       // ranking of input variables
00101       const Ranking* CreateRanking() { return 0; }
00102 
00103       Double_t EstimatorFunction( std::vector<Double_t>& );
00104 
00105       // no check of options at this place
00106       void CheckSetup() {}
00107 
00108    protected:
00109 
00110       // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
00111       void MakeClassSpecific( std::ostream&, const TString& ) const;
00112 
00113       // get help message text
00114       void GetHelpMessage() const;
00115 
00116    private:
00117 
00118       // compute multiclass values
00119       void CalculateMulticlassValues( const TMVA::Event*& evt, std::vector<Double_t>& parameters, std::vector<Float_t>& values);
00120 
00121 
00122       // create and interpret formula expression and compute estimator
00123       void     CreateFormula   ();
00124       Double_t InterpretFormula( const Event*, std::vector<Double_t>::iterator begin, std::vector<Double_t>::iterator end );
00125 
00126       // clean up
00127       void ClearAll();
00128 
00129       // print fit results
00130       void PrintResults( const TString&, std::vector<Double_t>&, const Double_t ) const;
00131 
00132       // the option handling methods
00133       void DeclareOptions();
00134       void ProcessOptions();
00135 
00136       TString                fFormulaStringP;     // string with function
00137       TString                fParRangeStringP;    // string with ranges of parameters
00138       TString                fFormulaStringT;     // string with function
00139       TString                fParRangeStringT;    // string with ranges of parameters
00140 
00141       TFormula*              fFormula;            // the discrimination function
00142       UInt_t                 fNPars;              // number of parameters
00143       std::vector<Interval*> fParRange;           // ranges of parameters
00144       std::vector<Double_t>  fBestPars;           // the pars that optimise (minimise) the estimator
00145       TString                fFitMethod;          // estimator optimisation method
00146       TString                fConverger;          // fitmethod uses fConverger as intermediate step to converge into local minimas
00147       FitterBase*            fFitter;             // the fitter used in the training
00148       IFitterTarget*         fConvergerFitter;    // intermediate fitter
00149 
00150 
00151       // sum of weights (this should become centrally available through the dataset)
00152       Double_t               fSumOfWeightsSig;    // sum of weights (signal)
00153       Double_t               fSumOfWeightsBkg;    // sum of weights (background)
00154       Double_t               fSumOfWeights;       // sum of weights
00155 
00156       //
00157       Int_t                  fOutputDimensions;   // number of output values
00158 
00159       ClassDef(MethodFDA,0)  // Function Discriminant Analysis
00160    };
00161 
00162 } // namespace TMVA
00163 
00164 #endif // MethodFDA_H

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