29#ifndef ROOT_TMVA_RuleEnsemble
30#define ROOT_TMVA_RuleEnsemble
82 void MakeRules(
const std::vector< const TMVA::DecisionTree *>& forest );
97 void SetRules(
const std::vector< TMVA::Rule *> & rules );
157 const std::vector<Double_t> & coefs,
158 const std::vector<Double_t> & lincoefs)
const;
161 const std::vector<Double_t> & coefs,
162 const std::vector<Double_t> & lincoefs);
169 const std::vector<Double_t> & coefs,
170 const std::vector<Double_t> & lincoefs)
const;
306 void PrintRaw ( std::ostream& os )
const;
307 void*
AddXMLTo (
void* parent )
const;
310 void ReadRaw ( std::istream& istr );
414 Int_t nrules = fRules.size();
422 for (
Int_t i=0; i<nrules; i++ ) {
423 if (fEventRuleVal[i])
424 rval += fRules[i]->GetCoefficient();
430 if (DoLinear()) linear = EvalLinEvent();
438 const std::vector<Double_t> & coefs,
439 const std::vector<Double_t> & lincoefs )
const
443 Int_t nrules = fRules.size();
450 for (
Int_t i=0; i<nrules; i++ ) {
451 if (fEventRuleVal[i])
458 if (DoLinear()) linear = EvalLinEvent(lincoefs);
476 const std::vector<Double_t> & coefs,
477 const std::vector<Double_t> & lincoefs )
482 return EvalEvent(ofs,coefs,lincoefs);
489 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
493 UInt_t nrules = fRuleMap[evtidx].size();
495 for (
UInt_t ir = 0; ir<nrules; ir++) {
496 rind = fRuleMap[evtidx][ir];
497 rval += fRules[rind]->GetCoefficient();
501 UInt_t nlin = fLinTermOK.size();
504 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
514 const std::vector<Double_t> & coefs,
515 const std::vector<Double_t> & lincoefs )
const
519 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
522 UInt_t nrules = fRuleMap[evtidx].size();
524 for (
UInt_t ir = 0; ir<nrules; ir++) {
525 rind = fRuleMap[evtidx][ir];
530 rval += EvalLinEvent( evtidx, lincoefs );
542 if (norm) rval *= fLinNorm[vind];
551 Double_t val = (*fRuleMapEvents)[evtidx]->GetValue(vind);
553 if (norm) rval *= fLinNorm[vind];
563 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
565 rval += fLinCoefficients[
v]*fEventLinearVal[
v]*fLinNorm[
v];
576 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
578 rval += coefs[
v]*fEventLinearVal[
v]*fLinNorm[
v];
590 return EvalLinEvent();
600 return GetEventLinearValNorm(vind);
610 return EvalLinEvent(coefs);
617 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
619 UInt_t nlin = fLinTermOK.size();
622 rval += coefs[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
632 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
634 UInt_t nlin = fLinTermOK.size();
637 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
647 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
649 rval = fLinCoefficients[vind] * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
657 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
659 rval = coefs * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
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
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
Short_t Max(Short_t a, Short_t b)
Double_t Sqrt(Double_t x)
Short_t Min(Short_t a, Short_t b)