29#ifndef ROOT_TMVA_RuleEnsemble
30#define ROOT_TMVA_RuleEnsemble
88 void MakeRules(
const std::vector< const TMVA::DecisionTree *>& forest );
103 void SetRules(
const std::vector< TMVA::Rule *> & rules );
163 const std::vector<Double_t> & coefs,
164 const std::vector<Double_t> & lincoefs)
const;
167 const std::vector<Double_t> & coefs,
168 const std::vector<Double_t> & lincoefs);
175 const std::vector<Double_t> & coefs,
176 const std::vector<Double_t> & lincoefs)
const;
312 void PrintRaw ( std::ostream& os )
const;
313 void*
AddXMLTo (
void* parent )
const;
316 void ReadRaw ( std::istream& istr );
420 Int_t nrules = fRules.size();
428 for (
Int_t i=0; i<nrules; i++ ) {
429 if (fEventRuleVal[i])
430 rval += fRules[i]->GetCoefficient();
436 if (DoLinear()) linear = EvalLinEvent();
444 const std::vector<Double_t> & coefs,
445 const std::vector<Double_t> & lincoefs )
const
449 Int_t nrules = fRules.size();
456 for (
Int_t i=0; i<nrules; i++ ) {
457 if (fEventRuleVal[i])
464 if (DoLinear()) linear = EvalLinEvent(lincoefs);
482 const std::vector<Double_t> & coefs,
483 const std::vector<Double_t> & lincoefs )
488 return EvalEvent(ofs,coefs,lincoefs);
495 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
499 UInt_t nrules = fRuleMap[evtidx].size();
501 for (
UInt_t ir = 0; ir<nrules; ir++) {
502 rind = fRuleMap[evtidx][ir];
503 rval += fRules[rind]->GetCoefficient();
507 UInt_t nlin = fLinTermOK.size();
510 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
520 const std::vector<Double_t> & coefs,
521 const std::vector<Double_t> & lincoefs )
const
525 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
528 UInt_t nrules = fRuleMap[evtidx].size();
530 for (
UInt_t ir = 0; ir<nrules; ir++) {
531 rind = fRuleMap[evtidx][ir];
536 rval += EvalLinEvent( evtidx, lincoefs );
548 if (norm) rval *= fLinNorm[vind];
557 Double_t val = (*fRuleMapEvents)[evtidx]->GetValue(vind);
559 if (norm) rval *= fLinNorm[vind];
569 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
571 rval += fLinCoefficients[
v]*fEventLinearVal[
v]*fLinNorm[
v];
582 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
584 rval += coefs[
v]*fEventLinearVal[
v]*fLinNorm[
v];
596 return EvalLinEvent();
606 return GetEventLinearValNorm(vind);
616 return EvalLinEvent(coefs);
623 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
625 UInt_t nlin = fLinTermOK.size();
628 rval += coefs[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
638 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
640 UInt_t nlin = fLinTermOK.size();
643 rval += fLinCoefficients[
r] * EvalLinEventRaw(
r,*(*fRuleMapEvents)[evtidx],
kTRUE);
653 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
655 rval = fLinCoefficients[vind] * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
663 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
665 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.
Abstract ClassifierFactory template that handles arbitrary types.
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)