Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Rule.h
Go to the documentation of this file.
1// @(#)root/tmva $Id$
2// Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss
3
4/**********************************************************************************
5 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6 * Package: TMVA *
7 * Class : Rule *
8 * *
9 * Description: *
10 * A class describing a 'rule' *
11 * Each internal node of a tree defines a rule from all the parental nodes. *
12 * A rule consists of at least 2 nodes. *
13 * Input: a decision tree (in the constructor) *
14 * its coefficient *
15 * *
16 * *
17 * Authors (alphabetical): *
18 * Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA *
19 * Helge Voss <Helge.Voss@cern.ch> - MPI-KP Heidelberg, Ger. *
20 * *
21 * Copyright (c) 2005: *
22 * CERN, Switzerland *
23 * Iowa State U. *
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_Rule
32#define ROOT_TMVA_Rule
33
34#include "TMath.h"
35#include <vector>
36#include <iostream>
37
38#include "TMVA/DecisionTree.h"
39#include "TMVA/Event.h"
40#include "TMVA/RuleCut.h"
41
42namespace TMVA {
43
44 class RuleEnsemble;
45 class MsgLogger;
46 class Rule;
47
48 std::ostream& operator<<( std::ostream& os, const Rule & rule );
49
50 class Rule {
51
52 // output operator for a Rule
53 friend std::ostream& operator<< ( std::ostream& os, const Rule & rule );
54
55 public:
56
57 // main constructor
58 Rule( RuleEnsemble *re, const std::vector< const TMVA::Node * > & nodes );
59
60 // main constructor
61 Rule( RuleEnsemble *re );
62
63 // copy constructor
64 Rule( const Rule & other ) { Copy( other ); }
65
66 // empty constructor
67 Rule();
68
69 virtual ~Rule();
70
71 // set message type
72 void SetMsgType( EMsgType t );
73
74 // set RuleEnsemble ptr
75 void SetRuleEnsemble( const RuleEnsemble *re ) { fRuleEnsemble = re; }
76
77 // set RuleCut ptr
78 void SetRuleCut( RuleCut *rc ) { fCut = rc; }
79
80 // set Rule norm
81 void SetNorm(Double_t norm) { fNorm = (norm>0 ? 1.0/norm:1.0); }
82
83 // set coefficient
85
86 // set support
88
89 // set s/(s+b)
90 void SetSSB(Double_t v) { fSSB=v; }
91
92 // set N(eve) accepted by rule
94
95 // set reference importance
97
98 // calculate importance
100
101 // get the relative importance
103
104 // evaluate the Rule for the given Event using the coefficient
105 // inline Double_t EvalEvent( const Event& e, Bool_t norm ) const;
106
107 // evaluate the Rule for the given Event, not using normalization or the coefficient
108 inline Bool_t EvalEvent( const Event& e ) const;
109
110 // test if two rules are equal
111 Bool_t Equal( const Rule & other, Bool_t useCutValue, Double_t maxdist ) const;
112
113 // get distance between two equal (ie apart from the cut values) rules
114 Double_t RuleDist( const Rule & other, Bool_t useCutValue ) const;
115
116 // returns true if the trained S/(S+B) of the last node is > 0.5
117 Double_t GetSSB() const { return fSSB; }
118 Double_t GetSSBNeve() const { return fSSBNeve; }
119 Bool_t IsSignalRule() const { return (fSSB>0.5); }
120
121 // copy operator
122 void operator=( const Rule & other ) { Copy( other ); }
123
124 // identical operator
125 Bool_t operator==( const Rule & other ) const;
126
127 Bool_t operator<( const Rule & other ) const;
128
129 // get number of variables used in Rule
130 UInt_t GetNumVarsUsed() const { return fCut->GetNvars(); }
131
132 // get number of cuts in Rule
133 UInt_t GetNcuts() const { return fCut->GetNcuts(); }
134
135 // check if variable is used by the rule
137
138 // accessors
139 const RuleCut* GetRuleCut() const { return fCut; }
140 const RuleEnsemble* GetRuleEnsemble() const { return fRuleEnsemble; }
142 Double_t GetSupport() const { return fSupport; }
143 Double_t GetSigma() const { return fSigma; }
144 Double_t GetNorm() const { return fNorm; }
147
148 // print the rule using flogger
149 void PrintLogger( const char *title=nullptr ) const;
150
151 // print just the raw info, used for weight file generation
152 void PrintRaw ( std::ostream& os ) const; // obsolete
153 void* AddXMLTo ( void* parent ) const;
154
155 void ReadRaw ( std::istream& os ); // obsolete
156 void ReadFromXML( void* wghtnode );
157
158 private:
159
160 // set sigma - don't use this as non private!
162
163 // print info about the Rule
164 void Print( std::ostream& os ) const;
165
166 // copy from another rule
167 void Copy( const Rule & other );
168
169 // get the name of variable with index i
170 const TString & GetVarName( Int_t i) const;
171
172 RuleCut* fCut; ///< all cuts associated with the rule
173 Double_t fNorm; ///< normalization - usually 1.0/t(k)
175 Double_t fSigma; ///< t(k) = sqrt(s*(1-s))
176 Double_t fCoefficient; ///< rule coeff. a(k)
177 Double_t fImportance; ///< importance of rule
178 Double_t fImportanceRef; ///< importance ref
179 const RuleEnsemble* fRuleEnsemble; ///< pointer to parent RuleEnsemble
180 Double_t fSSB; ///< S/(S+B) for rule
181 Double_t fSSBNeve; ///< N(events) reaching the last node in reevaluation
182
183 mutable MsgLogger* fLogger; ///<! message logger
184 MsgLogger& Log() const { return *fLogger; }
185
186 };
187
188} // end of TMVA namespace
189
190//_______________________________________________________________________
192{
193 // Checks if event is accepted by rule.
194 // Return true if yes and false if not.
195 //
196 return fCut->EvalEvent(e);
197}
198
199#endif
#define e(i)
Definition RSha256.hxx:103
bool Bool_t
Definition RtypesCore.h:63
unsigned int UInt_t
Definition RtypesCore.h:46
double Double_t
Definition RtypesCore.h:59
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
Definition TBuffer.h:397
ostringstream derivative to redirect and format output
Definition MsgLogger.h:57
A class describing a 'rule cut'.
Definition RuleCut.h:36
UInt_t GetNvars() const
Definition RuleCut.h:72
UInt_t GetNcuts() const
get number of cuts
Definition RuleCut.cxx:164
Bool_t EvalEvent(const Event &eve)
Definition RuleCut.h:120
Implementation of a rule.
Definition Rule.h:50
Double_t fImportance
importance of rule
Definition Rule.h:177
friend std::ostream & operator<<(std::ostream &os, const Rule &rule)
void SetImportanceRef(Double_t v)
Definition Rule.h:96
void SetMsgType(EMsgType t)
Definition Rule.cxx:156
void Copy(const Rule &other)
copy function
Definition Rule.cxx:284
Double_t GetImportanceRef() const
Definition Rule.h:146
Double_t GetSSBNeve() const
Definition Rule.h:118
MsgLogger & Log() const
Definition Rule.h:184
void PrintLogger(const char *title=nullptr) const
print function
Definition Rule.cxx:335
Double_t GetSupport() const
Definition Rule.h:142
Double_t fSigma
t(k) = sqrt(s*(1-s))
Definition Rule.h:175
MsgLogger * fLogger
! message logger
Definition Rule.h:183
void SetSigma(Double_t v)
Definition Rule.h:161
Bool_t Equal(const Rule &other, Bool_t useCutValue, Double_t maxdist) const
Compare two rules.
Definition Rule.cxx:172
void ReadRaw(std::istream &os)
read function (format is the same as written by PrintRaw)
Definition Rule.cxx:477
UInt_t GetNcuts() const
Definition Rule.h:133
UInt_t GetNumVarsUsed() const
Definition Rule.h:130
void operator=(const Rule &other)
Definition Rule.h:122
void * AddXMLTo(void *parent) const
Definition Rule.cxx:398
Bool_t operator==(const Rule &other) const
comparison operator ==
Definition Rule.cxx:251
const RuleCut * GetRuleCut() const
Definition Rule.h:139
Bool_t IsSignalRule() const
Definition Rule.h:119
Double_t GetCoefficient() const
Definition Rule.h:141
void SetCoefficient(Double_t v)
Definition Rule.h:84
void Print(std::ostream &os) const
print function
Definition Rule.cxx:303
void SetNorm(Double_t norm)
Definition Rule.h:81
const RuleEnsemble * GetRuleEnsemble() const
Definition Rule.h:140
virtual ~Rule()
destructor
Definition Rule.cxx:130
Double_t GetSSB() const
Definition Rule.h:117
Double_t fNorm
normalization - usually 1.0/t(k)
Definition Rule.h:173
Double_t GetNorm() const
Definition Rule.h:144
void ReadFromXML(void *wghtnode)
read rule from XML
Definition Rule.cxx:428
Double_t GetImportance() const
Definition Rule.h:145
void PrintRaw(std::ostream &os) const
extensive print function used to print info for the weight file
Definition Rule.cxx:367
Double_t GetSigma() const
Definition Rule.h:143
void SetRuleEnsemble(const RuleEnsemble *re)
Definition Rule.h:75
void SetSSBNeve(Double_t v)
Definition Rule.h:93
void SetRuleCut(RuleCut *rc)
Definition Rule.h:78
const TString & GetVarName(Int_t i) const
returns the name of a rule
Definition Rule.cxx:276
Bool_t operator<(const Rule &other) const
comparison operator <
Definition Rule.cxx:259
void CalcImportance()
Definition Rule.h:99
Double_t RuleDist(const Rule &other, Bool_t useCutValue) const
Returns:
Definition Rule.cxx:192
Double_t fSSB
S/(S+B) for rule.
Definition Rule.h:180
Double_t GetRelImportance() const
Definition Rule.h:102
RuleCut * fCut
all cuts associated with the rule
Definition Rule.h:172
Bool_t ContainsVariable(UInt_t iv) const
check if variable in node
Definition Rule.cxx:139
Double_t fCoefficient
rule coeff. a(k)
Definition Rule.h:176
void SetSupport(Double_t v)
Definition Rule.h:87
const RuleEnsemble * fRuleEnsemble
pointer to parent RuleEnsemble
Definition Rule.h:179
Bool_t EvalEvent(const Event &e) const
Definition Rule.h:191
Rule()
the simple constructor
Definition Rule.cxx:112
Double_t fSSBNeve
N(events) reaching the last node in reevaluation.
Definition Rule.h:181
Double_t fSupport
s(k)
Definition Rule.h:174
Rule(const Rule &other)
Definition Rule.h:64
Double_t fImportanceRef
importance ref
Definition Rule.h:178
void SetSSB(Double_t v)
Definition Rule.h:90
EMsgType
Definition Types.h:55
Basic string class.
Definition TString.h:139
create variable transformations
Double_t Sqrt(Double_t x)
Returns the square root of x.
Definition TMath.h:662
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123