40 TMVA::RuleCut::RuleCut(
const std::vector<const Node*> & nodes )
43 fLogger(new MsgLogger(
"RuleFit"))
51 TMVA::RuleCut::RuleCut()
54 fLogger(new MsgLogger(
"RuleFit"))
61 TMVA::RuleCut::~RuleCut() {
69 void TMVA::RuleCut::MakeCuts(
const std::vector<const Node*> & nodes )
72 UInt_t nnodes = nodes.size();
74 Log() << kWARNING <<
"<MakeCuts()> Empty cut created." << Endl;
79 const DecisionTreeNode* dtn =
dynamic_cast<const DecisionTreeNode*
>(nodes.back());
81 fCutNeve = dtn->GetNEvents();
82 fPurity = dtn->GetPurity();
85 typedef std::pair<Double_t,Int_t> CutDir_t;
86 typedef std::pair<Int_t,CutDir_t> SelCut_t;
97 std::list<SelCut_t> allsel;
101 const Node *nextNode;
102 for ( UInt_t i=0; i<nnodes-1; i++) {
103 nextNode = nodes[i+1];
104 const DecisionTreeNode* dtn_ =
dynamic_cast<const DecisionTreeNode*
>(nodes[i]);
106 sel = dtn_->GetSelector();
107 val = dtn_->GetCutValue();
108 if (nodes[i]->GetRight() == nextNode) {
111 else if (nodes[i]->GetLeft() == nextNode) {
115 Log() << kFATAL <<
"<MakeTheRule> BUG! Should not be here - an end-node before the end!" << Endl;
118 allsel.push_back(SelCut_t(sel,CutDir_t(val,dir)));
124 Bool_t firstMin=kTRUE;
125 Bool_t firstMax=kTRUE;
126 for ( std::list<SelCut_t>::const_iterator it = allsel.begin(); it!=allsel.end(); ++it ) {
128 val = (*it).second.first;
129 dir = (*it).second.second;
134 fSelector.push_back(sel);
135 fCutMin.resize( fSelector.size(),0);
136 fCutMax.resize( fSelector.size(),0);
137 fCutDoMin.resize( fSelector.size(), kFALSE);
138 fCutDoMax.resize( fSelector.size(), kFALSE);
142 if ((val<fCutMin[nsel-1]) || firstMin) {
143 fCutMin[nsel-1] = val;
144 fCutDoMin[nsel-1] = kTRUE;
149 if ((val>fCutMax[nsel-1]) || firstMax) {
150 fCutMax[nsel-1] = val;
151 fCutDoMax[nsel-1] = kTRUE;
164 UInt_t TMVA::RuleCut::GetNcuts()
const
167 for (UInt_t i=0; i<fSelector.size(); i++) {
168 if (fCutDoMin[i]) rval += 1;
169 if (fCutDoMax[i]) rval += 1;
176 Bool_t TMVA::RuleCut::GetCutRange(Int_t sel,Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax)
const
181 Bool_t foundIt=kFALSE;
184 foundIt = (Int_t(fSelector[ind])==sel);
186 done = (foundIt || (ind==fSelector.size()));
188 if (!foundIt)
return kFALSE;
189 rmin = fCutMin[ind-1];
190 rmax = fCutMax[ind-1];
191 dormin = fCutDoMin[ind-1];
192 dormax = fCutDoMax[ind-1];