Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MethodFDA.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Peter Speckmayer
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : MethodFDA *
8 * *
9 * *
10 * Description: *
11 * Function discriminant analysis (FDA). This simple classifier *
12 * fits any user-defined TFormula (via option configuration string) to *
13 * the training data by requiring a formula response of 1 (0) to signal *
14 * (background) events. The parameter fitting is done via the abstract *
15 * class FitterBase, featuring Monte Carlo sampling, Genetic *
16 * Algorithm, Simulated Annealing, MINUIT and combinations of these. *
17 * *
18 * Authors (alphabetical): *
19 * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
20 * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
21 * *
22 * Copyright (c) 2005-2010: *
23 * CERN, Switzerland *
24 * MPI-K Heidelberg, Germany *
25 * *
26 * Redistribution and use in source and binary forms, with or without *
27 * modification, are permitted according to the terms listed in LICENSE *
28 * (see tmva/doc/LICENSE) *
29 **********************************************************************************/
30
31#ifndef ROOT_TMVA_MethodFDA
32#define ROOT_TMVA_MethodFDA
33
34//////////////////////////////////////////////////////////////////////////
35// //
36// MethodFDA //
37// //
38// Function discriminant analysis (FDA). This simple classifier //
39// fits any user-defined TFormula (via option configuration string) to //
40// the training data by requiring a formula response of 1 (0) to signal //
41// (background) events. The parameter fitting is done via the abstract //
42// class FitterBase, featuring Monte Carlo sampling, Genetic //
43// Algorithm, Simulated Annealing, MINUIT and combinations of these. //
44// //
45// Can compute one-dimensional regression //
46// //
47//////////////////////////////////////////////////////////////////////////
48
49#include "TMVA/MethodBase.h"
50#include "TMVA/IFitterTarget.h"
51#include <vector>
52
53class TFormula;
54
55namespace TMVA {
56
57 class Interval;
58 class Event;
59 class FitterBase;
60
61 class MethodFDA : public MethodBase, public IFitterTarget {
62
63 public:
64
66 const TString& methodTitle,
68 const TString& theOption = "");
69
71 const TString& theWeightFile);
72
73 virtual ~MethodFDA( void );
74
76
77 // training method
78 void Train( void ) override;
79
81
82 void AddWeightsXMLTo ( void* parent ) const override;
83
84 void ReadWeightsFromStream( std::istream & i ) override;
85 void ReadWeightsFromXML ( void* wghtnode ) override;
86
87 // calculate the MVA value
88 Double_t GetMvaValue( Double_t* err = nullptr, Double_t* errUpper = nullptr ) override;
89
90 const std::vector<Float_t>& GetRegressionValues() override;
91 const std::vector<Float_t>& GetMulticlassValues() override;
92
93 void Init( void ) override;
94
95 // ranking of input variables
96 const Ranking* CreateRanking() override { return nullptr; }
97
98 Double_t EstimatorFunction( std::vector<Double_t>& ) override;
99
100 // no check of options at this place
101 void CheckSetup() override {}
102
103 protected:
104
105 // make ROOT-independent C++ class for classifier response (classifier-specific implementation)
106 void MakeClassSpecific( std::ostream&, const TString& ) const override;
107
108 // get help message text
109 void GetHelpMessage() const override;
110
111 private:
112
113 // compute multiclass values
114 void CalculateMulticlassValues( const TMVA::Event*& evt, std::vector<Double_t>& parameters, std::vector<Float_t>& values);
115
116
117 // create and interpret formula expression and compute estimator
118 void CreateFormula ();
119 Double_t InterpretFormula( const Event*, std::vector<Double_t>::iterator begin, std::vector<Double_t>::iterator end );
120
121 // clean up
122 void ClearAll();
123
124 // print fit results
125 void PrintResults( const TString&, std::vector<Double_t>&, const Double_t ) const;
126
127 // the option handling methods
128 void DeclareOptions() override;
129 void ProcessOptions() override;
130
131 TString fFormulaStringP; ///< string with function
132 TString fParRangeStringP; ///< string with ranges of parameters
133 TString fFormulaStringT; ///< string with function
134 TString fParRangeStringT; ///< string with ranges of parameters
135
136 TFormula* fFormula; ///< the discrimination function
137 UInt_t fNPars; ///< number of parameters
138 std::vector<Interval*> fParRange; ///< ranges of parameters
139 std::vector<Double_t> fBestPars; ///< the pars that optimise (minimise) the estimator
140 TString fFitMethod; ///< estimator optimisation method
141 TString fConverger; ///< fit method uses fConverger as intermediate step to converge into local minimas
142 FitterBase* fFitter; ///< the fitter used in the training
143 IFitterTarget* fConvergerFitter; ///< intermediate fitter
144
145
146 // sum of weights (this should become centrally available through the dataset)
147 Double_t fSumOfWeightsSig; ///< sum of weights (signal)
148 Double_t fSumOfWeightsBkg; ///< sum of weights (background)
149 Double_t fSumOfWeights; ///< sum of weights
150
151 //
152 Int_t fOutputDimensions; ///< number of output values
153
154 ClassDefOverride(MethodFDA,0); // Function Discriminant Analysis
155 };
156
157} // namespace TMVA
158
159#endif // MethodFDA_H
double Double_t
Definition RtypesCore.h:59
#define ClassDefOverride(name, id)
Definition Rtypes.h:346
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
The Formula class.
Definition TFormula.h:89
Class that contains all the data information.
Definition DataSetInfo.h:62
Base class for TMVA fitters.
Definition FitterBase.h:51
Interface for a fitter 'target'.
Virtual base Class for all MVA method.
Definition MethodBase.h:111
void ReadWeightsFromStream(std::istream &) override=0
Function discriminant analysis (FDA).
Definition MethodFDA.h:61
Bool_t HasAnalysisType(Types::EAnalysisType type, UInt_t numberClasses, UInt_t numberTargets) override
FDA can handle classification with 2 classes and regression with one regression-target.
TString fFormulaStringT
string with function
Definition MethodFDA.h:133
const std::vector< Float_t > & GetRegressionValues() override
const Ranking * CreateRanking() override
Definition MethodFDA.h:96
virtual ~MethodFDA(void)
destructor
Double_t InterpretFormula(const Event *, std::vector< Double_t >::iterator begin, std::vector< Double_t >::iterator end)
formula interpretation
void Train(void) override
FDA training.
void CalculateMulticlassValues(const TMVA::Event *&evt, std::vector< Double_t > &parameters, std::vector< Float_t > &values)
calculate the values for multiclass
void CheckSetup() override
check may be overridden by derived class (sometimes, eg, fitters are used which can only be implement...
Definition MethodFDA.h:101
void ReadWeightsFromStream(std::istream &i) override
read back the training results from a file (stream)
Double_t fSumOfWeightsBkg
sum of weights (background)
Definition MethodFDA.h:148
Int_t fOutputDimensions
number of output values
Definition MethodFDA.h:152
MethodFDA(const TString &jobName, const TString &methodTitle, DataSetInfo &theData, const TString &theOption="")
standard constructor
Definition MethodFDA.cxx:86
void ClearAll()
delete and clear all class members
std::vector< Interval * > fParRange
ranges of parameters
Definition MethodFDA.h:138
void PrintResults(const TString &, std::vector< Double_t > &, const Double_t) const
display fit parameters check maximum length of variable name
Double_t GetMvaValue(Double_t *err=nullptr, Double_t *errUpper=nullptr) override
returns MVA value for given event
Double_t fSumOfWeightsSig
sum of weights (signal)
Definition MethodFDA.h:147
TString fParRangeStringP
string with ranges of parameters
Definition MethodFDA.h:132
void MakeClassSpecific(std::ostream &, const TString &) const override
write FDA-specific classifier response
TFormula * fFormula
the discrimination function
Definition MethodFDA.h:136
std::vector< Double_t > fBestPars
the pars that optimise (minimise) the estimator
Definition MethodFDA.h:139
void AddWeightsXMLTo(void *parent) const override
create XML description for LD classification and regression (for arbitrary number of output classes/t...
IFitterTarget * fConvergerFitter
intermediate fitter
Definition MethodFDA.h:143
void ProcessOptions() override
the option string is decoded, for available options see "DeclareOptions"
FitterBase * fFitter
the fitter used in the training
Definition MethodFDA.h:142
void ReadWeightsFromXML(void *wghtnode) override
read coefficients from xml weight file
Double_t EstimatorFunction(std::vector< Double_t > &) override
compute estimator for given parameter set (to be minimised)
Double_t fSumOfWeights
sum of weights
Definition MethodFDA.h:149
TString fParRangeStringT
string with ranges of parameters
Definition MethodFDA.h:134
void DeclareOptions() override
define the options (their key words) that can be set in the option string
const std::vector< Float_t > & GetMulticlassValues() override
TString fFitMethod
estimator optimisation method
Definition MethodFDA.h:140
void CreateFormula()
translate formula string into TFormula, and parameter string into par ranges
UInt_t fNPars
number of parameters
Definition MethodFDA.h:137
TString fConverger
fit method uses fConverger as intermediate step to converge into local minimas
Definition MethodFDA.h:141
TString fFormulaStringP
string with function
Definition MethodFDA.h:131
void Init(void) override
default initialisation
void GetHelpMessage() const override
get help message text
Ranking for variables in method (implementation)
Definition Ranking.h:48
Basic string class.
Definition TString.h:139
create variable transformations