29 #ifndef ROOT_TMVA_RuleEnsemble
30 #define ROOT_TMVA_RuleEnsemble
42 #ifndef ROOT_TMVA_DecisionTree
45 #ifndef ROOT_TMVA_Event
48 #ifndef ROOT_TMVA_Rule
51 #ifndef ROOT_TMVA_Types
65 std::ostream&
operator<<( std::ostream& os,
const RuleEnsemble& event );
98 void MakeRules(
const std::vector< const TMVA::DecisionTree *>& forest );
113 void SetRules(
const std::vector< TMVA::Rule *> & rules );
173 const std::vector<Double_t> & coefs,
174 const std::vector<Double_t> & lincoefs)
const;
177 const std::vector<Double_t> & coefs,
178 const std::vector<Double_t> & lincoefs);
185 const std::vector<Double_t> & coefs,
186 const std::vector<Double_t> & lincoefs)
const;
322 void PrintRaw ( std::ostream& os )
const;
323 void*
AddXMLTo (
void* parent )
const;
326 void ReadRaw ( std::istream& istr );
430 Int_t nrules = fRules.size();
438 for (
Int_t i=0; i<nrules; i++ ) {
439 if (fEventRuleVal[i])
440 rval += fRules[i]->GetCoefficient();
446 if (DoLinear()) linear = EvalLinEvent();
454 const std::vector<Double_t> & coefs,
455 const std::vector<Double_t> & lincoefs )
const
459 Int_t nrules = fRules.size();
466 for (
Int_t i=0; i<nrules; i++ ) {
467 if (fEventRuleVal[i])
474 if (DoLinear()) linear = EvalLinEvent(lincoefs);
492 const std::vector<Double_t> & coefs,
493 const std::vector<Double_t> & lincoefs )
498 return EvalEvent(ofs,coefs,lincoefs);
505 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
509 UInt_t nrules = fRuleMap[evtidx].size();
511 for (
UInt_t ir = 0; ir<nrules; ir++) {
512 rind = fRuleMap[evtidx][ir];
513 rval += fRules[rind]->GetCoefficient();
517 UInt_t nlin = fLinTermOK.size();
520 rval += fLinCoefficients[
r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],
kTRUE);
530 const std::vector<Double_t> & coefs,
531 const std::vector<Double_t> & lincoefs )
const
535 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
538 UInt_t nrules = fRuleMap[evtidx].size();
540 for (
UInt_t ir = 0; ir<nrules; ir++) {
541 rind = fRuleMap[evtidx][ir];
546 rval += EvalLinEvent( evtidx, lincoefs );
558 if (norm) rval *= fLinNorm[vind];
567 Double_t val = (*fRuleMapEvents)[evtidx]->GetValue(vind);
569 if (norm) rval *= fLinNorm[vind];
579 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
581 rval += fLinCoefficients[
v]*fEventLinearVal[
v]*fLinNorm[
v];
592 for (
UInt_t v=0;
v<fLinTermOK.size();
v++) {
594 rval += coefs[
v]*fEventLinearVal[
v]*fLinNorm[
v];
606 return EvalLinEvent();
616 return GetEventLinearValNorm(vind);
626 return EvalLinEvent(coefs);
633 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
635 UInt_t nlin = fLinTermOK.size();
638 rval += coefs[
r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],
kTRUE);
648 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
650 UInt_t nlin = fLinTermOK.size();
653 rval += fLinCoefficients[
r] * EvalLinEventRaw(r,*(*fRuleMapEvents)[evtidx],
kTRUE);
663 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
665 rval = fLinCoefficients[vind] * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
673 if ((evtidx<fRuleMapInd0) || (evtidx>fRuleMapInd1))
return 0;
675 rval = coefs * EvalLinEventRaw(vind,*(*fRuleMapEvents)[evtidx],
kTRUE);
const std::vector< const TMVA::Event * > * GetTrainingEvents() const
get list of training events from the rule fitter
Bool_t DoOnlyRules() const
Double_t GetImportanceCut() const
Double_t PdfLinear(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for the linear terms.
Bool_t IsRuleMapOK() const
Double_t GetLinCoefficients(int i) const
void SetLinDP(const std::vector< Double_t > &xmax)
ELearningModel GetLearningModel() const
const std::vector< Double_t > & GetVarImportance() const
Double_t EvalLinEventRaw(UInt_t vind, const Event &e, Bool_t norm) const
void SetEvent(const Event &e)
void SetLinDM(const std::vector< Double_t > &xmin)
void ClearLinNorm(Double_t val=1.0)
std::vector< TH1F * > fLinPDFS
Double_t GetRulePBS(int i) const
const std::vector< Double_t > & GetLinCoefficients() const
RuleEnsemble()
constructor
Rule * MakeTheRule(const Node *node)
Make a Rule from a given Node.
Double_t GetLinDP(int i) const
Int_t CalcNRules(const TMVA::DecisionTree *dtree)
calculate the number of rules
Double_t CalcLinNorm(Double_t stdev)
Bool_t DoOnlyLinear() const
Double_t GetEventRuleVal(UInt_t i) const
virtual ~RuleEnsemble()
destructor
Double_t GetAverageSupport() const
const Event * GetEvent() const
1-D histogram with a float per channel (see TH1 documentation)}
std::vector< Double_t > fLinDP
Short_t Min(Short_t a, Short_t b)
Double_t GetLinQuantile() const
std::vector< Double_t > fRulePBB
void Print() const
print function
void PrintRuleGen() const
print rule generation info
Double_t GetImportanceRef() const
void CleanupLinear()
cleanup linear model
const std::vector< UInt_t > & GetEventRuleMap(UInt_t evtidx) const
void MakeRuleMap(const std::vector< const TMVA::Event * > *events=0, UInt_t ifirst=0, UInt_t ilast=0)
Makes rule map for all events.
MsgLogger & Log() const
message logger
std::vector< TMVA::Rule * > fRules
Double_t GetAverageRuleSigma() const
std::vector< Char_t > fLinTermOK
void SetAverageRuleSigma(Double_t v)
Double_t GetRulePSS(int i) const
const std::vector< Double_t > & GetLinImportance() const
void SetLinCoefficients(const std::vector< Double_t > &v)
void SetMsgType(EMsgType t)
const Event * GetTrainingEvent(UInt_t i) const
get the training event from the rule fitter
void SetImportanceRef(Double_t impref)
set reference importance
void RuleResponseStats()
calculate various statistics for this rule
friend std::ostream & operator<<(std::ostream &os, const RuleEnsemble &rules)
Double_t GetEventLinearValNorm(UInt_t i) const
std::vector< Double_t > fLinNorm
Double_t PdfRule(Double_t &nsig, Double_t &ntot) const
This function returns Pr( y = 1 | x ) for rules.
void RemoveSimilarRules()
remove rules that behave similar
void Copy(RuleEnsemble const &other)
copy function
void PrintRaw(std::ostream &os) const
write rules to stream
Bool_t IsLinTermOK(int i) const
Double_t GetLinNorm(int i) const
const MethodRuleFit * GetMethodRuleFit() const
Get a pointer to the original MethodRuleFit.
std::vector< TH1F * > fLinPDFB
void SetRuleFit(const RuleFit *rf)
std::vector< Double_t > fRulePSB
void CalcImportance()
calculate the importance of each rule
const TMVA::Event * GetRuleMapEvent(UInt_t evtidx) const
std::vector< Double_t > fLinCoefficients
Double_t GetLinDM(int i) const
void CleanupRules()
cleanup rules
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) ...
Double_t GetRulePSB(int i) const
void CalcVarImportance()
Calculates variable importance using eq (35) in RuleFit paper by Friedman et.al.
Double_t EvalLinEvent() const
const RuleFit * GetRuleFit() const
ELearningModel fLearningModel
Double_t CalcRuleImportance()
calculate importance of each rule
std::vector< Double_t > fLinDM
void MakeRulesFromTree(const DecisionTree *dtree)
create rules from the decsision tree structure
Double_t CoefficientRadius()
Calculates sqrt(Sum(a_i^2)), i=1..N (NOTE do not include a0)
void SetOffset(Double_t v=0.0)
void ClearCoefficients(Double_t val=0)
void AddRule(const Node *node)
add a new rule to the tree
void SetImportanceCut(Double_t minimp=0)
Double_t GetRulePTag(int i) const
void RuleStatistics()
calculate various statistics for this rule
void MakeRules(const std::vector< const TMVA::DecisionTree * > &forest)
Makes rules from the given decision tree.
const std::vector< TMVA::Rule * > & GetRulesConst() const
void ClearLinCoefficients(Double_t val=0)
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
print the tree recursinvely using the << operator
Double_t GetVarImportance(int i) const
void ReadFromXML(void *wghtnode)
read rules from XML
void SetLinCoefficient(UInt_t i, Double_t v)
const Rule * GetRulesConst(int i) const
std::vector< Char_t > fEventRuleVal
void FindNEndNodes(const TMVA::Node *node, Int_t &nendnodes)
find the number of leaf nodes
void Initialize(const RuleFit *rf)
Initializes all member variables with default values.
void SetCoefficients(const std::vector< Double_t > &v)
set all rule coefficients
UInt_t GetNLinear() const
std::vector< Double_t > fVarImportance
Double_t GetRulePBB(int i) const
std::vector< Double_t > fEventLinearVal
Float_t GetValue(UInt_t ivar) const
return value of i'th variable
void MakeLinearTerms()
Make the linear terms as in eq 25, ref 2 For this the b and (1-b) quatiles are needed.
std::vector< Double_t > fLinImportance
Double_t fAverageRuleSigma
std::vector< Double_t > fRulePBS
void CalcRuleSupport()
calculate the support for all rules
const std::vector< const TMVA::Event * > * fRuleMapEvents
std::vector< Double_t > fRulePSS
Double_t GetRuleMinDist() const
void operator=(const RuleEnsemble &other)
void MakeModel()
create model
void SetRules(const std::vector< TMVA::Rule * > &rules)
set rules
Double_t GetEventLinearVal(UInt_t i) const
Short_t Max(Short_t a, Short_t b)
Double_t GetLinImportance(int i) const
void SetLinNorm(const std::vector< Double_t > &norm)
void ResetCoefficients()
reset all rule coefficients
std::vector< TMVA::Rule * > & GetRules()
void * AddXMLTo(void *parent) const
write rules to XML
void GetCoefficients(std::vector< Double_t > &v)
Retrieve all rule coefficients.
void AddOffset(Double_t v)
const std::vector< Double_t > & GetLinNorm() const
Double_t Sqrt(Double_t x)
Double_t CalcLinImportance()
calculate the linear importance for each rule
Double_t EvalEvent() const
void SetCoefficient(UInt_t i, Double_t v)
const MethodBase * GetMethodBase() const
Get a pointer to the original MethodRuleFit.
Double_t GetOffset() const
double norm(double *x, double *p)
std::vector< Double_t > fRulePTag
void SetRuleMinDist(Double_t d)
std::vector< Double_t > fRuleVarFrac
void SetLinQuantile(Double_t q)
std::vector< std::vector< UInt_t > > fRuleMap
UInt_t GetRulesNCuts(int i) const
void ReadRaw(std::istream &istr)
read rule ensemble from stream