29#ifndef ROOT_TMVA_RuleEnsemble
30#define ROOT_TMVA_RuleEnsemble
84 void MakeRules(
const std::vector< const TMVA::DecisionTree *>& forest );
99 void SetRules(
const std::vector< TMVA::Rule *> & rules );
159 const std::vector<Double_t> & coefs,
160 const std::vector<Double_t> & lincoefs)
const;
163 const std::vector<Double_t> & coefs,
164 const std::vector<Double_t> & lincoefs);
171 const std::vector<Double_t> & coefs,
172 const std::vector<Double_t> & lincoefs)
const;
308 void PrintRaw ( std::ostream& os )
const;
309 void*
AddXMLTo (
void* parent )
const;
312 void ReadRaw ( std::istream& istr );
416 Int_t nrules = fRules.size();
424 for (
Int_t i=0; i<nrules; i++ ) {
425 if (fEventRuleVal[i])
426 rval += fRules[i]->GetCoefficient();
432 if (DoLinear()) linear = EvalLinEvent();
440 const std::vector<Double_t> & coefs,
441 const std::vector<Double_t> & lincoefs )
const
445 Int_t nrules = fRules.size();
452 for (
Int_t i=0; i<nrules; i++ ) {
453 if (fEventRuleVal[i])
460 if (DoLinear()) linear = EvalLinEvent(lincoefs);
478 const std::vector<Double_t> & coefs,
479 const std::vector<Double_t> & lincoefs )
484 return EvalEvent(ofs,coefs,lincoefs);
491 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
495 UInt_t nrules = fRuleMap[evtidx].size();
497 for (
UInt_t ir = 0; ir<nrules; ir++) {
498 rind = fRuleMap[evtidx][ir];
499 rval += fRules[rind]->GetCoefficient();
503 UInt_t nlin = fLinTermOK.size();
506 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
516 const std::vector<Double_t> & coefs,
517 const std::vector<Double_t> & lincoefs )
const
521 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
524 UInt_t nrules = fRuleMap[evtidx].size();
526 for (
UInt_t ir = 0; ir<nrules; ir++) {
527 rind = fRuleMap[evtidx][ir];
532 rval += EvalLinEvent( evtidx, lincoefs );
544 if (norm) rval *= fLinNorm[vind];
553 Double_t val = (*fRuleMapEvents)[evtidx]->GetValue(vind);
555 if (norm) rval *= fLinNorm[vind];
565 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
567 rval += fLinCoefficients[
v]*fEventLinearVal[
v]*fLinNorm[
v];
578 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
580 rval += coefs[
v]*fEventLinearVal[
v]*fLinNorm[
v];
592 return EvalLinEvent();
602 return GetEventLinearValNorm(vind);
612 return EvalLinEvent(coefs);
619 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
621 UInt_t nlin = fLinTermOK.size();
624 rval += coefs[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
634 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
636 UInt_t nlin = fLinTermOK.size();
639 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
649 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
651 rval = fLinCoefficients[vind] * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
659 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
661 rval = coefs * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
TBuffer & operator<<(TBuffer &buf, const Tmpl *obj)
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 r
1-D histogram with a float per channel (see TH1 documentation)
Implementation of a Decision Tree.
Virtual base Class for all MVA method.
J Friedman's RuleFit method.
ostringstream derivative to redirect and format output
Node for the BinarySearch or Decision Trees.
std::vector< Double_t > fRulePBB
p(tag as B|B)
Bool_t IsRuleMapOK() const
void SetLinCoefficients(const std::vector< Double_t > &v)
Double_t GetLinDP(int i) const
virtual ~RuleEnsemble()
destructor
Double_t EvalEvent() const
const std::vector< UInt_t > & GetEventRuleMap(UInt_t evtidx) const
Double_t GetRulePBB(int i) const
void CalcVarImportance()
Calculates variable importance using eq (35) in RuleFit paper by Friedman et.al.
std::vector< Double_t > fLinImportance
linear term importance
void SetLinCoefficient(UInt_t i, Double_t v)
Double_t GetLinDM(int i) const
void SetOffset(Double_t v=0.0)
void SetImportanceRef(Double_t impref)
set reference importance
void CalcImportance()
calculate the importance of each rule
void PrintRuleGen() const
print rule generation info
Int_t CalcNRules(const TMVA::DecisionTree *dtree)
calculate the number of rules
std::vector< Double_t > fLinCoefficients
linear coefficients, one per variable
UInt_t fNRulesGenerated
number of rules generated, before cleanup
void ResetCoefficients()
reset all rule coefficients
std::vector< Double_t > fRulePBS
p(tag as B|S)
void SetMsgType(EMsgType t)
std::vector< TMVA::Rule * > fRules
vector of rules
Bool_t DoOnlyLinear() const
void SetLinQuantile(Double_t q)
Double_t CalcLinNorm(Double_t stdev)
Double_t fOffset
offset in discriminator function
Double_t GetLinQuantile() const
Double_t GetVarImportance(int i) const
void ReadRaw(std::istream &istr)
read rule ensemble from stream
std::vector< Double_t > fRulePSS
p(tag as S|S) - tagged as S if rule is SIG and the event is accepted
std::vector< Double_t > fLinDP
delta+ in eq 24, ref 2
Double_t EvalLinEventRaw(UInt_t vind, const Event &e, Bool_t norm) const
const Event * fEvent
current event.
void AddRule(const Node *node)
add a new rule to the tree
Double_t GetRulePTag(int i) const
void ReadFromXML(void *wghtnode)
read rules from XML
void SetLinDP(const std::vector< Double_t > &xmax)
void SetRuleFit(const RuleFit *rf)
Double_t GetImportanceCut() const
const Event * GetTrainingEvent(UInt_t i) const
get the training event from the rule fitter
const std::vector< const TMVA::Event * > * GetTrainingEvents() const
get list of training events from the rule fitter
Double_t GetRuleMinDist() const
void SetLinNorm(const std::vector< Double_t > &norm)
void SetRules(const std::vector< TMVA::Rule * > &rules)
set rules
void MakeRules(const std::vector< const TMVA::DecisionTree * > &forest)
Makes rules from the given decision tree.
void RemoveSimilarRules()
remove rules that behave similar
std::vector< Double_t > fRulePTag
p(tag)
std::vector< TH1F * > fLinPDFB
pdfs for each variable, background
std::vector< Char_t > fEventRuleVal
the rule respons of current event <--— stores boolean
Double_t fRuleFSig
N(sig)/N(sig)+N(bkg)
ELearningModel fLearningModel
can be full (rules+linear), rules, linear
Double_t fRuleMinDist
minimum rule distance
void FindNEndNodes(const TMVA::Node *node, Int_t &nendnodes)
find the number of leaf nodes
Double_t GetRulePBS(int i) const
Bool_t fRuleMapOK
true if MakeRuleMap() has been called
RuleEnsemble()
constructor
Double_t GetEventRuleVal(UInt_t i) const
const std::vector< Double_t > & GetLinCoefficients() const
Double_t GetImportanceRef() const
const RuleFit * fRuleFit
pointer to rule fit object
std::vector< TMVA::Rule * > & GetRules()
UInt_t fRuleMapInd1
last index
const std::vector< Double_t > & GetVarImportance() const
void CleanupRules()
cleanup rules
void Initialize(const RuleFit *rf)
Initializes all member variables with default values.
const std::vector< Double_t > & GetLinNorm() const
std::vector< Double_t > fLinDM
delta-
void CleanupLinear()
cleanup linear model
void RuleResponseStats()
calculate various statistics for this rule
std::vector< Double_t > fVarImportance
one importance per input variable
UInt_t GetNLinear() const
UInt_t GetRulesNCuts(int i) const
Double_t GetRulePSS(int i) const
Double_t GetRulePSB(int i) const
void ClearLinCoefficients(Double_t val=0)
const RuleFit * GetRuleFit() const
Double_t EvalLinEvent() const
void SetLinDM(const std::vector< Double_t > &xmin)
void * AddXMLTo(void *parent) const
write rules to XML
std::vector< Double_t > fLinNorm
norm of ditto, see after eq 26 in ref 2
void SetCoefficient(UInt_t i, Double_t v)
const std::vector< TMVA::Rule * > & GetRulesConst() const
Double_t fLinQuantile
quantile cut to remove outliers
Double_t GetLinNorm(int i) const
void ClearLinNorm(Double_t val=1.0)
const Event * GetEvent() const
const MethodRuleFit * GetMethodRuleFit() const
Get a pointer to the original MethodRuleFit.
void ClearCoefficients(Double_t val=0)
Double_t GetAverageRuleSigma() const
std::vector< Double_t > fEventLinearVal
linear respons
void SetRuleMinDist(Double_t d)
void MakeModel()
create model
void RuleStatistics()
calculate various statistics for this rule
void SetCoefficients(const std::vector< Double_t > &v)
set all rule coefficients
void Print() const
print function
const std::vector< Double_t > & GetLinImportance() const
Double_t PdfRule(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for rules.
void MakeRuleMap(const std::vector< const TMVA::Event * > *events=nullptr, UInt_t ifirst=0, UInt_t ilast=0)
Makes rule map for all events.
Double_t GetLinCoefficients(int i) const
const MethodBase * GetMethodBase() const
Get a pointer to the original MethodRuleFit.
Double_t fAverageSupport
average support (over all rules)
friend std::ostream & operator<<(std::ostream &os, const RuleEnsemble &rules)
Double_t GetOffset() const
Bool_t DoOnlyRules() const
Double_t fRuleNCave
N(cuts) average.
Double_t GetLinImportance(int i) const
std::vector< Char_t > fLinTermOK
flags linear terms with sufficient strong importance <– stores boolean
Double_t GetAverageSupport() const
void Copy(RuleEnsemble const &other)
copy function
MsgLogger * fLogger
! message logger
std::vector< std::vector< UInt_t > > fRuleMap
map of rule responses
Double_t CalcLinImportance()
calculate the linear importance for each rule
const std::vector< const TMVA::Event * > * fRuleMapEvents
pointer to vector of events used
void SetAverageRuleSigma(Double_t v)
Double_t CalcRuleImportance()
calculate importance of each rule
Bool_t IsLinTermOK(int i) const
std::vector< TH1F * > fLinPDFS
pdfs for each variable, signal
Double_t fImportanceRef
reference importance (max)
void PrintRaw(std::ostream &os) const
write rules to stream
std::vector< Double_t > fRulePSB
p(tag as S|B)
Double_t fAverageRuleSigma
average rule sigma
Bool_t fEventCacheOK
true if rule/linear respons are updated
void CalcRuleSupport()
calculate the support for all rules
Double_t fImportanceCut
minimum importance accepted
void AddOffset(Double_t v)
Double_t GetEventLinearVal(UInt_t i) const
ELearningModel GetLearningModel() const
Double_t PdfLinear(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for the linear terms.
Double_t CoefficientRadius()
Calculates sqrt(Sum(a_i^2)), i=1..N (NOTE do not include a0)
void SetEvent(const Event &e)
Double_t GetEventLinearValNorm(UInt_t i) const
UInt_t fRuleMapInd0
start index
void MakeRulesFromTree(const DecisionTree *dtree)
create rules from the decision tree structure
void SetImportanceCut(Double_t minimp=0)
const TMVA::Event * GetRuleMapEvent(UInt_t evtidx) const
Double_t fRuleNCsig
idem sigma
void MakeLinearTerms()
Make the linear terms as in eq 25, ref 2 For this the b and (1-b) quantiles are needed.
void operator=(const RuleEnsemble &other)
const Rule * GetRulesConst(int i) const
Rule * MakeTheRule(const Node *node)
Make a Rule from a given Node.
std::vector< Double_t > fRuleVarFrac
fraction of rules using a given variable - size of vector = n(variables)
void GetCoefficients(std::vector< Double_t > &v)
Retrieve all rule coefficients.
Double_t FStar() const
We want to estimate F* = argmin Eyx( L(y,F(x) ), min wrt F(x) F(x) = FL(x) + FR(x) ,...
A class implementing various fits of rule ensembles.
Implementation of a rule.
create variable transformations
Short_t Max(Short_t a, Short_t b)
Returns the largest of a and b.
Double_t Sqrt(Double_t x)
Returns the square root of x.
Short_t Min(Short_t a, Short_t b)
Returns the smallest of a and b.