Logo ROOT  
Reference Guide
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 * (http://tmva.sourceforge.net/LICENSE) *
29 **********************************************************************************/
30
31#ifndef ROOT_TMVA_Rule
32#define ROOT_TMVA_Rule
33
34#include "TMath.h"
35
36#include "TMVA/DecisionTree.h"
37#include "TMVA/Event.h"
38#include "TMVA/RuleCut.h"
39
40namespace TMVA {
41
42 class RuleEnsemble;
43 class MsgLogger;
44 class Rule;
45
46 std::ostream& operator<<( std::ostream& os, const Rule & rule );
47
48 class Rule {
49
50 // output operator for a Rule
51 friend std::ostream& operator<< ( std::ostream& os, const Rule & rule );
52
53 public:
54
55 // main constructor
56 Rule( RuleEnsemble *re, const std::vector< const TMVA::Node * > & nodes );
57
58 // main constructor
59 Rule( RuleEnsemble *re );
60
61 // copy constructor
62 Rule( const Rule & other ) { Copy( other ); }
63
64 // empty constructor
65 Rule();
66
67 virtual ~Rule();
68
69 // set message type
70 void SetMsgType( EMsgType t );
71
72 // set RuleEnsemble ptr
73 void SetRuleEnsemble( const RuleEnsemble *re ) { fRuleEnsemble = re; }
74
75 // set RuleCut ptr
76 void SetRuleCut( RuleCut *rc ) { fCut = rc; }
77
78 // set Rule norm
79 void SetNorm(Double_t norm) { fNorm = (norm>0 ? 1.0/norm:1.0); }
80
81 // set coefficient
83
84 // set support
86
87 // set s/(s+b)
88 void SetSSB(Double_t v) { fSSB=v; }
89
90 // set N(eve) accepted by rule
92
93 // set reference importance
95
96 // calculate importance
98
99 // get the relative importance
101
102 // evaluate the Rule for the given Event using the coefficient
103 // inline Double_t EvalEvent( const Event& e, Bool_t norm ) const;
104
105 // evaluate the Rule for the given Event, not using normalization or the coefficient
106 inline Bool_t EvalEvent( const Event& e ) const;
107
108 // test if two rules are equal
109 Bool_t Equal( const Rule & other, Bool_t useCutValue, Double_t maxdist ) const;
110
111 // get distance between two equal (ie apart from the cut values) rules
112 Double_t RuleDist( const Rule & other, Bool_t useCutValue ) const;
113
114 // returns true if the trained S/(S+B) of the last node is > 0.5
115 Double_t GetSSB() const { return fSSB; }
116 Double_t GetSSBNeve() const { return fSSBNeve; }
117 Bool_t IsSignalRule() const { return (fSSB>0.5); }
118
119 // copy operator
120 void operator=( const Rule & other ) { Copy( other ); }
121
122 // identical operator
123 Bool_t operator==( const Rule & other ) const;
124
125 Bool_t operator<( const Rule & other ) const;
126
127 // get number of variables used in Rule
128 UInt_t GetNumVarsUsed() const { return fCut->GetNvars(); }
129
130 // get number of cuts in Rule
131 UInt_t GetNcuts() const { return fCut->GetNcuts(); }
132
133 // check if variable is used by the rule
135
136 // accessors
137 const RuleCut* GetRuleCut() const { return fCut; }
138 const RuleEnsemble* GetRuleEnsemble() const { return fRuleEnsemble; }
140 Double_t GetSupport() const { return fSupport; }
141 Double_t GetSigma() const { return fSigma; }
142 Double_t GetNorm() const { return fNorm; }
145
146 // print the rule using flogger
147 void PrintLogger( const char *title=0 ) const;
148
149 // print just the raw info, used for weight file generation
150 void PrintRaw ( std::ostream& os ) const; // obsolete
151 void* AddXMLTo ( void* parent ) const;
152
153 void ReadRaw ( std::istream& os ); // obsolete
154 void ReadFromXML( void* wghtnode );
155
156 private:
157
158 // set sigma - don't use this as non private!
160
161 // print info about the Rule
162 void Print( std::ostream& os ) const;
163
164 // copy from another rule
165 void Copy( const Rule & other );
166
167 // get the name of variable with index i
168 const TString & GetVarName( Int_t i) const;
169
170 RuleCut* fCut; // all cuts associated with the rule
171 Double_t fNorm; // normalization - usually 1.0/t(k)
173 Double_t fSigma; // t(k) = sqrt(s*(1-s))
174 Double_t fCoefficient; // rule coeff. a(k)
175 Double_t fImportance; // importance of rule
176 Double_t fImportanceRef; // importance ref
177 const RuleEnsemble* fRuleEnsemble; // pointer to parent RuleEnsemble
178 Double_t fSSB; // S/(S+B) for rule
179 Double_t fSSBNeve; // N(events) reaching the last node in reevaluation
180
181 mutable MsgLogger* fLogger; //! message logger
182 MsgLogger& Log() const { return *fLogger; }
183
184 };
185
186} // end of TMVA namespace
187
188//_______________________________________________________________________
190{
191 // Checks if event is accepted by rule.
192 // Return true if yes and false if not.
193 //
194 return fCut->EvalEvent(e);
195}
196
197#endif
#define e(i)
Definition: RSha256.hxx:103
unsigned int UInt_t
Definition: RtypesCore.h:44
bool Bool_t
Definition: RtypesCore.h:61
double Double_t
Definition: RtypesCore.h:57
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
A class describing a 'rule cut'.
Definition: RuleCut.h:34
UInt_t GetNvars() const
Definition: RuleCut.h:70
UInt_t GetNcuts() const
get number of cuts
Definition: RuleCut.cxx:164
Bool_t EvalEvent(const Event &eve)
Definition: RuleCut.h:118
Implementation of a rule.
Definition: Rule.h:48
Double_t fImportance
Definition: Rule.h:175
friend std::ostream & operator<<(std::ostream &os, const Rule &rule)
void SetImportanceRef(Double_t v)
Definition: Rule.h:94
void SetMsgType(EMsgType t)
Definition: Rule.cxx:154
void Copy(const Rule &other)
copy function
Definition: Rule.cxx:282
Double_t GetImportanceRef() const
Definition: Rule.h:144
Double_t GetSSBNeve() const
Definition: Rule.h:116
MsgLogger & Log() const
message logger
Definition: Rule.h:182
Double_t GetSupport() const
Definition: Rule.h:140
Double_t fSigma
Definition: Rule.h:173
MsgLogger * fLogger
Definition: Rule.h:181
void SetSigma(Double_t v)
Definition: Rule.h:159
Bool_t Equal(const Rule &other, Bool_t useCutValue, Double_t maxdist) const
Compare two rules.
Definition: Rule.cxx:170
void ReadRaw(std::istream &os)
read function (format is the same as written by PrintRaw)
Definition: Rule.cxx:475
UInt_t GetNcuts() const
Definition: Rule.h:131
UInt_t GetNumVarsUsed() const
Definition: Rule.h:128
void operator=(const Rule &other)
Definition: Rule.h:120
void * AddXMLTo(void *parent) const
Definition: Rule.cxx:396
void PrintLogger(const char *title=0) const
print function
Definition: Rule.cxx:333
Bool_t operator==(const Rule &other) const
comparison operator ==
Definition: Rule.cxx:249
const RuleCut * GetRuleCut() const
Definition: Rule.h:137
Bool_t IsSignalRule() const
Definition: Rule.h:117
Double_t GetCoefficient() const
Definition: Rule.h:139
void SetCoefficient(Double_t v)
Definition: Rule.h:82
void Print(std::ostream &os) const
print function
Definition: Rule.cxx:301
void SetNorm(Double_t norm)
Definition: Rule.h:79
const RuleEnsemble * GetRuleEnsemble() const
Definition: Rule.h:138
virtual ~Rule()
destructor
Definition: Rule.cxx:128
Double_t GetSSB() const
Definition: Rule.h:115
Double_t fNorm
Definition: Rule.h:171
Double_t GetNorm() const
Definition: Rule.h:142
void ReadFromXML(void *wghtnode)
read rule from XML
Definition: Rule.cxx:426
Double_t GetImportance() const
Definition: Rule.h:143
void PrintRaw(std::ostream &os) const
extensive print function used to print info for the weight file
Definition: Rule.cxx:365
Double_t GetSigma() const
Definition: Rule.h:141
void SetRuleEnsemble(const RuleEnsemble *re)
Definition: Rule.h:73
void SetSSBNeve(Double_t v)
Definition: Rule.h:91
void SetRuleCut(RuleCut *rc)
Definition: Rule.h:76
const TString & GetVarName(Int_t i) const
returns the name of a rule
Definition: Rule.cxx:274
Bool_t operator<(const Rule &other) const
comparison operator <
Definition: Rule.cxx:257
void CalcImportance()
Definition: Rule.h:97
Double_t RuleDist(const Rule &other, Bool_t useCutValue) const
Returns:
Definition: Rule.cxx:190
Double_t fSSB
Definition: Rule.h:178
Double_t GetRelImportance() const
Definition: Rule.h:100
RuleCut * fCut
Definition: Rule.h:170
Bool_t ContainsVariable(UInt_t iv) const
check if variable in node
Definition: Rule.cxx:137
Double_t fCoefficient
Definition: Rule.h:174
void SetSupport(Double_t v)
Definition: Rule.h:85
const RuleEnsemble * fRuleEnsemble
Definition: Rule.h:177
Bool_t EvalEvent(const Event &e) const
Definition: Rule.h:189
Rule()
the simple constructor
Definition: Rule.cxx:110
Double_t fSSBNeve
Definition: Rule.h:179
Double_t fSupport
Definition: Rule.h:172
Rule(const Rule &other)
Definition: Rule.h:62
Double_t fImportanceRef
Definition: Rule.h:176
void SetSSB(Double_t v)
Definition: Rule.h:88
Basic string class.
Definition: TString.h:131
create variable transformations
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
Double_t Sqrt(Double_t x)
Definition: TMath.h:681
Short_t Abs(Short_t d)
Definition: TMathBase.h:120