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)
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
Bool_t IsRuleMapOK() const
MsgLogger & Log() const
message logger
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
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
void MakeRuleMap(const std::vector< const TMVA::Event * > *events=0, UInt_t ifirst=0, UInt_t ilast=0)
Makes rule map for all events.
Int_t CalcNRules(const TMVA::DecisionTree *dtree)
calculate the number of rules
std::vector< Double_t > fLinCoefficients
void ResetCoefficients()
reset all rule coefficients
std::vector< Double_t > fRulePBS
void SetMsgType(EMsgType t)
std::vector< TMVA::Rule * > fRules
Bool_t DoOnlyLinear() const
void SetLinQuantile(Double_t q)
Double_t CalcLinNorm(Double_t stdev)
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
std::vector< Double_t > fLinDP
Double_t EvalLinEventRaw(UInt_t vind, const Event &e, Bool_t norm) const
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
std::vector< TH1F * > fLinPDFB
std::vector< Char_t > fEventRuleVal
ELearningModel fLearningModel
void FindNEndNodes(const TMVA::Node *node, Int_t &nendnodes)
find the number of leaf nodes
Double_t GetRulePBS(int i) const
RuleEnsemble()
constructor
Double_t GetEventRuleVal(UInt_t i) const
const std::vector< Double_t > & GetLinCoefficients() const
Double_t GetImportanceRef() const
std::vector< TMVA::Rule * > & GetRules()
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
void CleanupLinear()
cleanup linear model
void RuleResponseStats()
calculate various statistics for this rule
std::vector< Double_t > fVarImportance
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
void SetCoefficient(UInt_t i, Double_t v)
const std::vector< TMVA::Rule * > & GetRulesConst() const
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
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.
Double_t GetLinCoefficients(int i) const
const MethodBase * GetMethodBase() const
Get a pointer to the original MethodRuleFit.
friend std::ostream & operator<<(std::ostream &os, const RuleEnsemble &rules)
Double_t GetOffset() const
Bool_t DoOnlyRules() const
Double_t GetLinImportance(int i) const
std::vector< Char_t > fLinTermOK
Double_t GetAverageSupport() const
void Copy(RuleEnsemble const &other)
copy function
std::vector< std::vector< UInt_t > > fRuleMap
Double_t CalcLinImportance()
calculate the linear importance for each rule
const std::vector< const TMVA::Event * > * fRuleMapEvents
void SetAverageRuleSigma(Double_t v)
Double_t CalcRuleImportance()
calculate importance of each rule
Bool_t IsLinTermOK(int i) const
std::vector< TH1F * > fLinPDFS
void PrintRaw(std::ostream &os) const
write rules to stream
std::vector< Double_t > fRulePSB
Double_t fAverageRuleSigma
void CalcRuleSupport()
calculate the support for all rules
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
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
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
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)
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)