ROOT logo
// @(#)root/tmva $Id: MethodFDA.h 29122 2009-06-22 06:51:30Z brun $    
// Author: Andreas Hoecker, Peter Speckmayer

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : MethodFDA                                                             *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Function discriminant analysis (FDA). This simple classifier              *
 *      fits any user-defined TFormula (via option configuration string) to       *
 *      the training data by requiring a formula response of 1 (0) to signal      *
 *      (background) events. The parameter fitting is done via the abstract       *
 *      class FitterBase, featuring Monte Carlo sampling, Genetic                 *
 *      Algorithm, Simulated Annealing, MINUIT and combinations of these.         *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Andreas Hoecker  <Andreas.Hocker@cern.ch> - CERN, Switzerland             *
 *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
 *                                                                                *
 * Copyright (c) 2005-2006:                                                       *
 *      CERN, Switzerland                                                         *
 *      MPI-K Heidelberg, Germany                                                 *
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_MethodFDA
#define ROOT_TMVA_MethodFDA

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// MethodFDA                                                            //
//                                                                      //
// Function discriminant analysis (FDA). This simple classifier         //
// fits any user-defined TFormula (via option configuration string) to  //
// the training data by requiring a formula response of 1 (0) to signal //
// (background) events. The parameter fitting is done via the abstract  //
// class FitterBase, featuring Monte Carlo sampling, Genetic            //
// Algorithm, Simulated Annealing, MINUIT and combinations of these.    //
//																								//
// Can compute one-dimensional regression											//
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TMVA_MethodBase
#include "TMVA/MethodBase.h"
#endif
#ifndef ROOT_TMVA_IFitterTarget
#include "TMVA/IFitterTarget.h"
#endif

class TFormula;

namespace TMVA {

   class Interval;
   class Event;
   class FitterBase;

   class MethodFDA : public MethodBase, public IFitterTarget {

   public:

      MethodFDA( const TString& jobName, 
                 const TString& methodTitle, 
                 DataSetInfo& theData,
                 const TString& theOption = "",
                 TDirectory* theTargetDir = 0 );
      
      MethodFDA( DataSetInfo& theData, 
                 const TString& theWeightFile,  
                 TDirectory* theTargetDir = NULL );
      
      virtual ~MethodFDA( void );

      Bool_t HasAnalysisType( Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets );
    
      // training method
      void Train( void );

      using MethodBase::WriteWeightsToStream;
      using MethodBase::ReadWeightsFromStream;

      void WriteWeightsToStream ( std::ostream & o ) const;
      void AddWeightsXMLTo      ( void* parent     ) const;

      void ReadWeightsFromStream( std::istream & i );
      void ReadWeightsFromXML   ( void* wghtnode );

      // calculate the MVA value
      Double_t GetMvaValue( Double_t* err = 0 );

		std::vector<Float_t>& GetRegressionValues();	

      void Init( void );

      // ranking of input variables
      const Ranking* CreateRanking() { return 0; }

      Double_t EstimatorFunction( std::vector<Double_t>& );

      // no check of options at this place
      void CheckSetup() {}

   protected:

      // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
      void MakeClassSpecific( std::ostream&, const TString& ) const;

      // get help message text
      void GetHelpMessage() const;

   private:
		
      // create and interpret formula expression and compute estimator
      void     CreateFormula   ();
      Double_t InterpretFormula( const Event*, std::vector<Double_t>& pars );

      // clean up 
      void ClearAll();      

      // print fit results
      void PrintResults( const TString&, std::vector<Double_t>&, const Double_t ) const;

      // the option handling methods
      void DeclareOptions();
      void ProcessOptions();

      TString                fFormulaStringP;     // string with function
      TString                fParRangeStringP;    // string with ranges of parameters      
      TString                fFormulaStringT;     // string with function
      TString                fParRangeStringT;    // string with ranges of parameters      

      TFormula*              fFormula;            // the discrimination function
      Int_t                  fNPars;              // number of parameters
      std::vector<Interval*> fParRange;           // ranges of parameters
      std::vector<Double_t>  fBestPars;           // the pars that optimise (minimise) the estimator
      TString                fFitMethod;          // estimator optimisation method
      TString                fConverger;          // fitmethod uses fConverger as intermediate step to converge into local minimas
      FitterBase*            fFitter;             // the fitter used in the training
      IFitterTarget*         fConvergerFitter;    // intermediate fitter


      // sum of weights (this should become centrally available through the dataset)
      Double_t               fSumOfWeightsSig;    // sum of weights (signal)
      Double_t               fSumOfWeightsBkg;    // sum of weights (background)
      Double_t               fSumOfWeights;		  // sum of weights 

      ClassDef(MethodFDA,0)  // Function Discriminant Analysis
   };

} // namespace TMVA

#endif // MethodFDA_H
 MethodFDA.h:1
 MethodFDA.h:2
 MethodFDA.h:3
 MethodFDA.h:4
 MethodFDA.h:5
 MethodFDA.h:6
 MethodFDA.h:7
 MethodFDA.h:8
 MethodFDA.h:9
 MethodFDA.h:10
 MethodFDA.h:11
 MethodFDA.h:12
 MethodFDA.h:13
 MethodFDA.h:14
 MethodFDA.h:15
 MethodFDA.h:16
 MethodFDA.h:17
 MethodFDA.h:18
 MethodFDA.h:19
 MethodFDA.h:20
 MethodFDA.h:21
 MethodFDA.h:22
 MethodFDA.h:23
 MethodFDA.h:24
 MethodFDA.h:25
 MethodFDA.h:26
 MethodFDA.h:27
 MethodFDA.h:28
 MethodFDA.h:29
 MethodFDA.h:30
 MethodFDA.h:31
 MethodFDA.h:32
 MethodFDA.h:33
 MethodFDA.h:34
 MethodFDA.h:35
 MethodFDA.h:36
 MethodFDA.h:37
 MethodFDA.h:38
 MethodFDA.h:39
 MethodFDA.h:40
 MethodFDA.h:41
 MethodFDA.h:42
 MethodFDA.h:43
 MethodFDA.h:44
 MethodFDA.h:45
 MethodFDA.h:46
 MethodFDA.h:47
 MethodFDA.h:48
 MethodFDA.h:49
 MethodFDA.h:50
 MethodFDA.h:51
 MethodFDA.h:52
 MethodFDA.h:53
 MethodFDA.h:54
 MethodFDA.h:55
 MethodFDA.h:56
 MethodFDA.h:57
 MethodFDA.h:58
 MethodFDA.h:59
 MethodFDA.h:60
 MethodFDA.h:61
 MethodFDA.h:62
 MethodFDA.h:63
 MethodFDA.h:64
 MethodFDA.h:65
 MethodFDA.h:66
 MethodFDA.h:67
 MethodFDA.h:68
 MethodFDA.h:69
 MethodFDA.h:70
 MethodFDA.h:71
 MethodFDA.h:72
 MethodFDA.h:73
 MethodFDA.h:74
 MethodFDA.h:75
 MethodFDA.h:76
 MethodFDA.h:77
 MethodFDA.h:78
 MethodFDA.h:79
 MethodFDA.h:80
 MethodFDA.h:81
 MethodFDA.h:82
 MethodFDA.h:83
 MethodFDA.h:84
 MethodFDA.h:85
 MethodFDA.h:86
 MethodFDA.h:87
 MethodFDA.h:88
 MethodFDA.h:89
 MethodFDA.h:90
 MethodFDA.h:91
 MethodFDA.h:92
 MethodFDA.h:93
 MethodFDA.h:94
 MethodFDA.h:95
 MethodFDA.h:96
 MethodFDA.h:97
 MethodFDA.h:98
 MethodFDA.h:99
 MethodFDA.h:100
 MethodFDA.h:101
 MethodFDA.h:102
 MethodFDA.h:103
 MethodFDA.h:104
 MethodFDA.h:105
 MethodFDA.h:106
 MethodFDA.h:107
 MethodFDA.h:108
 MethodFDA.h:109
 MethodFDA.h:110
 MethodFDA.h:111
 MethodFDA.h:112
 MethodFDA.h:113
 MethodFDA.h:114
 MethodFDA.h:115
 MethodFDA.h:116
 MethodFDA.h:117
 MethodFDA.h:118
 MethodFDA.h:119
 MethodFDA.h:120
 MethodFDA.h:121
 MethodFDA.h:122
 MethodFDA.h:123
 MethodFDA.h:124
 MethodFDA.h:125
 MethodFDA.h:126
 MethodFDA.h:127
 MethodFDA.h:128
 MethodFDA.h:129
 MethodFDA.h:130
 MethodFDA.h:131
 MethodFDA.h:132
 MethodFDA.h:133
 MethodFDA.h:134
 MethodFDA.h:135
 MethodFDA.h:136
 MethodFDA.h:137
 MethodFDA.h:138
 MethodFDA.h:139
 MethodFDA.h:140
 MethodFDA.h:141
 MethodFDA.h:142
 MethodFDA.h:143
 MethodFDA.h:144
 MethodFDA.h:145
 MethodFDA.h:146
 MethodFDA.h:147
 MethodFDA.h:148
 MethodFDA.h:149
 MethodFDA.h:150
 MethodFDA.h:151
 MethodFDA.h:152
 MethodFDA.h:153
 MethodFDA.h:154
 MethodFDA.h:155
 MethodFDA.h:156
 MethodFDA.h:157
 MethodFDA.h:158