Logo ROOT   6.08/07
Reference Guide
RuleFit.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Fredrik Tegenfeldt, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : Rule *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * A class describung a 'rule' *
12  * Each internal node of a tree defines a rule from all the parental nodes. *
13  * A rule with 0 or 1 nodes in the list is a root rule -> corresponds to a0. *
14  * Input: a decision tree (in the constructor) *
15  * its coefficient *
16  * *
17  * *
18  * Authors (alphabetical): *
19  * Fredrik Tegenfeldt <Fredrik.Tegenfeldt@cern.ch> - Iowa State U., USA *
20  * *
21  * Copyright (c) 2005: *
22  * CERN, Switzerland *
23  * Iowa State U. *
24  * MPI-K Heidelberg, Germany *
25  * *
26  * Redistribution and use in source and binary forms, with or without *
27  * modification, are permitted according to the terms listed in LICENSE *
28  * (http://tmva.sourceforge.net/LICENSE) *
29  **********************************************************************************/
30 
31 #include "TMVA/RuleFit.h"
32 
33 #include "TMVA/DataSet.h"
34 #include "TMVA/DecisionTree.h"
35 #include "TMVA/Event.h"
36 #include "TMVA/Factory.h" // for root base dir
37 #include "TMVA/GiniIndex.h"
38 #include "TMVA/MethodBase.h"
39 #include "TMVA/MethodRuleFit.h"
40 #include "TMVA/MsgLogger.h"
41 #include "TMVA/Timer.h"
42 #include "TMVA/Tools.h"
43 #include "TMVA/Types.h"
44 #include "TMVA/SeparationBase.h"
45 
46 #include "TDirectory.h"
47 #include "TH2F.h"
48 #include "TFile.h"
49 #include "TKey.h"
50 #include "TRandom3.h"
51 #include "TROOT.h" // for gROOT
52 
53 #include <algorithm>
54 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// constructor
59 
60 TMVA::RuleFit::RuleFit( const MethodBase *rfbase )
61 : fVisHistsUseImp( kTRUE ),
62  fLogger( new MsgLogger("RuleFit") )
63 {
64  Initialize( rfbase );
65  std::srand( randSEED ); // initialize random number generator used by std::random_shuffle
66 }
67 
68 ////////////////////////////////////////////////////////////////////////////////
69 /// default constructor
70 
72  : fNTreeSample(0)
73  , fNEveEffTrain(0)
74  , fMethodRuleFit(0)
75  , fMethodBase(0)
76  , fVisHistsUseImp( kTRUE )
77  , fLogger( new MsgLogger("RuleFit") )
78 {
79  std::srand( randSEED ); // initialize random number generator used by std::random_shuffle
80 }
81 
82 ////////////////////////////////////////////////////////////////////////////////
83 /// destructor
84 
86 {
87  delete fLogger;
88 }
89 
90 ////////////////////////////////////////////////////////////////////////////////
91 /// init effective number of events (using event weights)
92 
94 {
95  UInt_t neve = fTrainingEvents.size();
96  if (neve==0) return;
97  //
99  //
100 }
101 
102 ////////////////////////////////////////////////////////////////////////////////
103 /// initialize pointers
104 
105 void TMVA::RuleFit::InitPtrs( const MethodBase *rfbase )
106 {
107  this->SetMethodBase(rfbase);
108  fRuleEnsemble.Initialize( this );
109  fRuleFitParams.SetRuleFit( this );
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// initialize the parameters of the RuleFit method and make rules
114 
116 {
117  InitPtrs(rfbase);
118 
119  if (fMethodRuleFit){
122  std::vector<const TMVA::Event*> tmp;
123  for (Long64_t ievt=0; ievt<nevents; ievt++) {
124  const Event *event = fMethodRuleFit->GetEvent(ievt);
125  tmp.push_back(event);
126  }
127  SetTrainingEvents( tmp );
128  }
129  // SetTrainingEvents( fMethodRuleFit->GetTrainingEvents() );
130 
131  InitNEveEff();
132 
133  MakeForest();
134 
135  // Make the model - Rule + Linear (if fDoLinear is true)
137 
138  // init rulefit params
140 
141 }
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 /// set MethodBase
145 
147 {
148  fMethodBase = rfbase;
149  fMethodRuleFit = dynamic_cast<const MethodRuleFit *>(rfbase);
150 }
151 
152 ////////////////////////////////////////////////////////////////////////////////
153 /// copy method
154 
155 void TMVA::RuleFit::Copy( const RuleFit& other )
156 {
157  if(this != &other) {
159  fMethodBase = other.GetMethodBase();
161  // fSubsampleEvents = other.GetSubsampleEvents();
162 
163  fForest = other.GetForest();
164  fRuleEnsemble = other.GetRuleEnsemble();
165  }
166 }
167 
168 ////////////////////////////////////////////////////////////////////////////////
169 /// calculate the sum of weights
170 
171 Double_t TMVA::RuleFit::CalcWeightSum( const std::vector<const Event *> *events, UInt_t neve )
172 {
173  if (events==0) return 0.0;
174  if (neve==0) neve=events->size();
175  //
176  Double_t sumw=0;
177  for (UInt_t ie=0; ie<neve; ie++) {
178  sumw += ((*events)[ie])->GetWeight();
179  }
180  return sumw;
181 }
182 
183 ////////////////////////////////////////////////////////////////////////////////
184 /// set the current message type to that of mlog for this class and all other subtools
185 
187 {
188  fLogger->SetMinType(t);
191 }
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 /// build the decision tree using fNTreeSample events from fTrainingEventsRndm
195 
197 {
198  if (dt==0) return;
199  if (fMethodRuleFit==0) {
200  Log() << kFATAL << "RuleFit::BuildTree() - Attempting to build a tree NOT from a MethodRuleFit" << Endl;
201  }
202  std::vector<const Event *> evevec;
203  for (UInt_t ie=0; ie<fNTreeSample; ie++) {
204  evevec.push_back(fTrainingEventsRndm[ie]);
205  }
206  dt->BuildTree(evevec);
210  dt->PruneTree();
211  }
212 }
213 
214 ////////////////////////////////////////////////////////////////////////////////
215 /// make a forest of decisiontrees
216 
218 {
219  if (fMethodRuleFit==0) {
220  Log() << kFATAL << "RuleFit::BuildTree() - Attempting to build a tree NOT from a MethodRuleFit" << Endl;
221  }
222  Log() << kDEBUG << "Creating a forest with " << fMethodRuleFit->GetNTrees() << " decision trees" << Endl;
223  Log() << kDEBUG << "Each tree is built using a random subsample with " << fNTreeSample << " events" << Endl;
224  //
225  Timer timer( fMethodRuleFit->GetNTrees(), "RuleFit" );
226 
227  // Double_t fsig;
228  Int_t nsig,nbkg;
229  //
230  TRandom3 rndGen;
231  //
232  //
233  // First save all event weights.
234  // Weights are modifed by the boosting.
235  // Those weights we do not want for the later fitting.
236  //
237  Bool_t useBoost = fMethodRuleFit->UseBoost(); // (AdaBoost (True) or RandomForest/Tree (False)
238 
239  if (useBoost) SaveEventWeights();
240 
241  for (Int_t i=0; i<fMethodRuleFit->GetNTrees(); i++) {
242  // timer.DrawProgressBar(i);
243  if (!useBoost) ReshuffleEvents();
244  nsig=0;
245  nbkg=0;
246  for (UInt_t ie = 0; ie<fNTreeSample; ie++) {
247  if (fMethodBase->DataInfo().IsSignal(fTrainingEventsRndm[ie])) nsig++; // ignore weights here
248  else nbkg++;
249  }
250  // fsig = Double_t(nsig)/Double_t(nsig+nbkg);
251  // do not implement the above in this release...just set it to default
252 
253  DecisionTree *dt=nullptr;
254  Bool_t tryAgain=kTRUE;
255  Int_t ntries=0;
256  const Int_t ntriesMax=10;
257  Double_t frnd = 0.;
258  while (tryAgain) {
259  frnd = 100*rndGen.Uniform( fMethodRuleFit->GetMinFracNEve(), 0.5*fMethodRuleFit->GetMaxFracNEve() );
260  Int_t iclass = 0; // event class being treated as signal during training
261  Bool_t useRandomisedTree = !useBoost;
262  dt = new DecisionTree( fMethodRuleFit->GetSeparationBase(), frnd, fMethodRuleFit->GetNCuts(), &(fMethodRuleFit->DataInfo()), iclass, useRandomisedTree);
263  dt->SetNVars(fMethodBase->GetNvar());
264 
265  BuildTree(dt); // reads fNTreeSample events from fTrainingEventsRndm
266  if (dt->GetNNodes()<3) {
267  delete dt;
268  dt=0;
269  }
270  ntries++;
271  tryAgain = ((dt==0) && (ntries<ntriesMax));
272  }
273  if (dt) {
274  fForest.push_back(dt);
275  if (useBoost) Boost(dt);
276 
277  } else {
278 
279  Log() << kWARNING << "------------------------------------------------------------------" << Endl;
280  Log() << kWARNING << " Failed growing a tree even after " << ntriesMax << " trials" << Endl;
281  Log() << kWARNING << " Possible solutions: " << Endl;
282  Log() << kWARNING << " 1. increase the number of training events" << Endl;
283  Log() << kWARNING << " 2. set a lower min fraction cut (fEventsMin)" << Endl;
284  Log() << kWARNING << " 3. maybe also decrease the max fraction cut (fEventsMax)" << Endl;
285  Log() << kWARNING << " If the above warning occurs rarely only, it can be ignored" << Endl;
286  Log() << kWARNING << "------------------------------------------------------------------" << Endl;
287  }
288 
289  Log() << kDEBUG << "Built tree with minimum cut at N = " << frnd <<"% events"
290  << " => N(nodes) = " << fForest.back()->GetNNodes()
291  << " ; n(tries) = " << ntries
292  << Endl;
293  }
294 
295  // Now restore event weights
296  if (useBoost) RestoreEventWeights();
297 
298  // print statistics on the forest created
300 }
301 
302 ////////////////////////////////////////////////////////////////////////////////
303 /// save event weights - must be done before making the forest
304 
306 {
307  fEventWeights.clear();
308  for (std::vector<const Event*>::iterator e=fTrainingEvents.begin(); e!=fTrainingEvents.end(); e++) {
309  Double_t w = (*e)->GetBoostWeight();
310  fEventWeights.push_back(w);
311  }
312 }
313 
314 ////////////////////////////////////////////////////////////////////////////////
315 /// save event weights - must be done before making the forest
316 
318 {
319  UInt_t ie=0;
320  if (fEventWeights.size() != fTrainingEvents.size()) {
321  Log() << kERROR << "RuleFit::RestoreEventWeights() called without having called SaveEventWeights() before!" << Endl;
322  return;
323  }
324  for (std::vector<const Event*>::iterator e=fTrainingEvents.begin(); e!=fTrainingEvents.end(); e++) {
325  (*e)->SetBoostWeight(fEventWeights[ie]);
326  ie++;
327  }
328 }
329 
330 ////////////////////////////////////////////////////////////////////////////////
331 /// Boost the events. The algorithm below is the called AdaBoost.
332 /// See MethodBDT for details.
333 /// Actually, this is a more or less copy of MethodBDT::AdaBoost().
334 
336 {
337  Double_t sumw=0; // sum of initial weights - all events
338  Double_t sumwfalse=0; // idem, only missclassified events
339  //
340  std::vector<Char_t> correctSelected; // <--- boolean stored
341  //
342  for (std::vector<const Event*>::iterator e=fTrainingEvents.begin(); e!=fTrainingEvents.end(); e++) {
343  Bool_t isSignalType = (dt->CheckEvent(*e,kTRUE) > 0.5 );
344  Double_t w = (*e)->GetWeight();
345  sumw += w;
346  //
347  if (isSignalType == fMethodBase->DataInfo().IsSignal(*e)) { // correctly classified
348  correctSelected.push_back(kTRUE);
349  }
350  else { // missclassified
351  sumwfalse+= w;
352  correctSelected.push_back(kFALSE);
353  }
354  }
355  // missclassification error
356  Double_t err = sumwfalse/sumw;
357  // calculate boost weight for missclassified events
358  // use for now the exponent = 1.0
359  // one could have w = ((1-err)/err)^beta
360  Double_t boostWeight = (err>0 ? (1.0-err)/err : 1000.0);
361  Double_t newSumw=0.0;
362  UInt_t ie=0;
363  // set new weight to missclassified events
364  for (std::vector<const Event*>::iterator e=fTrainingEvents.begin(); e!=fTrainingEvents.end(); e++) {
365  if (!correctSelected[ie])
366  (*e)->SetBoostWeight( (*e)->GetBoostWeight() * boostWeight);
367  newSumw+=(*e)->GetWeight();
368  ie++;
369  }
370  // reweight all events
371  Double_t scale = sumw/newSumw;
372  for (std::vector<const Event*>::iterator e=fTrainingEvents.begin(); e!=fTrainingEvents.end(); e++) {
373  (*e)->SetBoostWeight( (*e)->GetBoostWeight() * scale);
374  }
375  Log() << kDEBUG << "boostWeight = " << boostWeight << " scale = " << scale << Endl;
376 }
377 
378 ////////////////////////////////////////////////////////////////////////////////
379 /// summary of statistics of all trees
380 /// * end-nodes: average and spread
381 
383 {
384  UInt_t ntrees = fForest.size();
385  if (ntrees==0) return;
386  const DecisionTree *tree;
387  Double_t sumn2 = 0;
388  Double_t sumn = 0;
389  Double_t nd;
390  for (UInt_t i=0; i<ntrees; i++) {
391  tree = fForest[i];
392  nd = Double_t(tree->GetNNodes());
393  sumn += nd;
394  sumn2 += nd*nd;
395  }
396  Double_t sig = TMath::Sqrt( gTools().ComputeVariance( sumn2, sumn, ntrees ));
397  Log() << kVERBOSE << "Nodes in trees: average & std dev = " << sumn/ntrees << " , " << sig << Endl;
398 }
399 
400 ////////////////////////////////////////////////////////////////////////////////
401 ///
402 /// Fit the coefficients for the rule ensemble
403 ///
404 
406 {
407  Log() << kVERBOSE << "Fitting rule/linear terms" << Endl;
409 }
410 
411 ////////////////////////////////////////////////////////////////////////////////
412 /// calculates the importance of each rule
413 
415 {
416  Log() << kVERBOSE << "Calculating importance" << Endl;
421  Log() << kVERBOSE << "Filling rule statistics" << Endl;
423 }
424 
425 ////////////////////////////////////////////////////////////////////////////////
426 /// evaluate single event
427 
429 {
430  return fRuleEnsemble.EvalEvent( e );
431 }
432 
433 ////////////////////////////////////////////////////////////////////////////////
434 /// set the training events randomly
435 
436 void TMVA::RuleFit::SetTrainingEvents( const std::vector<const Event *>& el )
437 {
438  if (fMethodRuleFit==0) Log() << kFATAL << "RuleFit::SetTrainingEvents - MethodRuleFit not initialized" << Endl;
439  UInt_t neve = el.size();
440  if (neve==0) Log() << kWARNING << "An empty sample of training events was given" << Endl;
441 
442  // copy vector
443  fTrainingEvents.clear();
444  fTrainingEventsRndm.clear();
445  for (UInt_t i=0; i<neve; i++) {
446  fTrainingEvents.push_back(static_cast< const Event *>(el[i]));
447  fTrainingEventsRndm.push_back(static_cast< const Event *>(el[i]));
448  }
449 
450  // Re-shuffle the vector, ie, recreate it in a random order
451  std::random_shuffle( fTrainingEventsRndm.begin(), fTrainingEventsRndm.end() );
452 
453  // fraction events per tree
454  fNTreeSample = static_cast<UInt_t>(neve*fMethodRuleFit->GetTreeEveFrac());
455  Log() << kDEBUG << "Number of events per tree : " << fNTreeSample
456  << " ( N(events) = " << neve << " )"
457  << " randomly drawn without replacement" << Endl;
458 }
459 
460 ////////////////////////////////////////////////////////////////////////////////
461 /// draw a random subsample of the training events without replacement
462 
463 void TMVA::RuleFit::GetRndmSampleEvents(std::vector< const Event * > & evevec, UInt_t nevents)
464 {
465  ReshuffleEvents();
466  if ((nevents<fTrainingEventsRndm.size()) && (nevents>0)) {
467  evevec.resize(nevents);
468  for (UInt_t ie=0; ie<nevents; ie++) {
469  evevec[ie] = fTrainingEventsRndm[ie];
470  }
471  }
472  else {
473  Log() << kWARNING << "GetRndmSampleEvents() : requested sub sample size larger than total size (BUG!).";
474  }
475 }
476 ////////////////////////////////////////////////////////////////////////////////
477 /// normalize rule importance hists
478 ///
479 /// if all weights are positive, the scale will be 1/maxweight
480 /// if minimum weight < 0, then the scale will be 1/max(maxweight,abs(minweight))
481 ///
482 
483 void TMVA::RuleFit::NormVisHists(std::vector<TH2F *> & hlist)
484 {
485  if (hlist.empty()) return;
486  //
487  Double_t wmin=0;
488  Double_t wmax=0;
489  Double_t w,wm;
490  Double_t awmin;
491  Double_t scale;
492  for (UInt_t i=0; i<hlist.size(); i++) {
493  TH2F *hs = hlist[i];
494  w = hs->GetMaximum();
495  wm = hs->GetMinimum();
496  if (i==0) {
497  wmin=wm;
498  wmax=w;
499  }
500  else {
501  if (w>wmax) wmax=w;
502  if (wm<wmin) wmin=wm;
503  }
504  }
505  awmin = TMath::Abs(wmin);
506  Double_t usemin,usemax;
507  if (awmin>wmax) {
508  scale = 1.0/awmin;
509  usemin = -1.0;
510  usemax = scale*wmax;
511  }
512  else {
513  scale = 1.0/wmax;
514  usemin = scale*wmin;
515  usemax = 1.0;
516  }
517 
518  //
519  for (UInt_t i=0; i<hlist.size(); i++) {
520  TH2F *hs = hlist[i];
521  hs->Scale(scale);
522  hs->SetMinimum(usemin);
523  hs->SetMaximum(usemax);
524  }
525 }
526 
527 ////////////////////////////////////////////////////////////////////////////////
528 /// Fill cut
529 
530 void TMVA::RuleFit::FillCut(TH2F* h2, const Rule *rule, Int_t vind)
531 {
532  if (rule==0) return;
533  if (h2==0) return;
534  //
535  Double_t rmin, rmax;
536  Bool_t dormin,dormax;
537  Bool_t ruleHasVar = rule->GetRuleCut()->GetCutRange(vind,rmin,rmax,dormin,dormax);
538  if (!ruleHasVar) return;
539  //
540  Int_t firstbin = h2->GetBin(1,1,1);
541  if(firstbin<0) firstbin=0;
542  Int_t lastbin = h2->GetBin(h2->GetNbinsX(),1,1);
543  Int_t binmin=(dormin ? h2->FindBin(rmin,0.5):firstbin);
544  Int_t binmax=(dormax ? h2->FindBin(rmax,0.5):lastbin);
545  Int_t fbin;
546  Double_t xbinw = h2->GetXaxis()->GetBinWidth(firstbin);
547  Double_t fbmin = h2->GetXaxis()->GetBinLowEdge(binmin-firstbin+1);
548  Double_t lbmax = h2->GetXaxis()->GetBinLowEdge(binmax-firstbin+1)+xbinw;
549  Double_t fbfrac = (dormin ? ((fbmin+xbinw-rmin)/xbinw):1.0);
550  Double_t lbfrac = (dormax ? ((rmax-lbmax+xbinw)/xbinw):1.0);
551  Double_t f;
552  Double_t xc;
553  Double_t val;
554 
555  for (Int_t bin = binmin; bin<binmax+1; bin++) {
556  fbin = bin-firstbin+1;
557  if (bin==binmin) {
558  f = fbfrac;
559  }
560  else if (bin==binmax) {
561  f = lbfrac;
562  }
563  else {
564  f = 1.0;
565  }
566  xc = h2->GetXaxis()->GetBinCenter(fbin);
567  //
568  if (fVisHistsUseImp) {
569  val = rule->GetImportance();
570  }
571  else {
572  val = rule->GetCoefficient()*rule->GetSupport();
573  }
574  h2->Fill(xc,0.5,val*f);
575  }
576 }
577 
578 ////////////////////////////////////////////////////////////////////////////////
579 /// fill lin
580 
582 {
583  if (h2==0) return;
584  if (!fRuleEnsemble.DoLinear()) return;
585  //
586  Int_t firstbin = 1;
587  Int_t lastbin = h2->GetNbinsX();
588  Double_t xc;
589  Double_t val;
590  if (fVisHistsUseImp) {
591  val = fRuleEnsemble.GetLinImportance(vind);
592  }
593  else {
594  val = fRuleEnsemble.GetLinCoefficients(vind);
595  }
596  for (Int_t bin = firstbin; bin<lastbin+1; bin++) {
597  xc = h2->GetXaxis()->GetBinCenter(bin);
598  h2->Fill(xc,0.5,val);
599  }
600 }
601 
602 ////////////////////////////////////////////////////////////////////////////////
603 /// fill rule correlation between vx and vy, weighted with either the importance or the coefficient
604 
605 void TMVA::RuleFit::FillCorr(TH2F* h2,const Rule *rule,Int_t vx, Int_t vy)
606 {
607  if (rule==0) return;
608  if (h2==0) return;
609  Double_t val;
610  if (fVisHistsUseImp) {
611  val = rule->GetImportance();
612  }
613  else {
614  val = rule->GetCoefficient()*rule->GetSupport();
615  }
616  //
617  Double_t rxmin, rxmax, rymin, rymax;
618  Bool_t dorxmin, dorxmax, dorymin, dorymax;
619  //
620  // Get range in rule for X and Y
621  //
622  Bool_t ruleHasVarX = rule->GetRuleCut()->GetCutRange(vx,rxmin,rxmax,dorxmin,dorxmax);
623  Bool_t ruleHasVarY = rule->GetRuleCut()->GetCutRange(vy,rymin,rymax,dorymin,dorymax);
624  if (!(ruleHasVarX || ruleHasVarY)) return;
625  // min max of varX and varY in hist
626  Double_t vxmin = (dorxmin ? rxmin:h2->GetXaxis()->GetXmin());
627  Double_t vxmax = (dorxmax ? rxmax:h2->GetXaxis()->GetXmax());
628  Double_t vymin = (dorymin ? rymin:h2->GetYaxis()->GetXmin());
629  Double_t vymax = (dorymax ? rymax:h2->GetYaxis()->GetXmax());
630  // min max bin in X and Y
631  Int_t binxmin = h2->GetXaxis()->FindBin(vxmin);
632  Int_t binxmax = h2->GetXaxis()->FindBin(vxmax);
633  Int_t binymin = h2->GetYaxis()->FindBin(vymin);
634  Int_t binymax = h2->GetYaxis()->FindBin(vymax);
635  // bin widths
636  Double_t xbinw = h2->GetXaxis()->GetBinWidth(binxmin);
637  Double_t ybinw = h2->GetYaxis()->GetBinWidth(binxmin);
638  Double_t xbinmin = h2->GetXaxis()->GetBinLowEdge(binxmin);
639  Double_t xbinmax = h2->GetXaxis()->GetBinLowEdge(binxmax)+xbinw;
640  Double_t ybinmin = h2->GetYaxis()->GetBinLowEdge(binymin);
641  Double_t ybinmax = h2->GetYaxis()->GetBinLowEdge(binymax)+ybinw;
642  // fraction of edges
643  Double_t fxbinmin = (dorxmin ? ((xbinmin+xbinw-vxmin)/xbinw):1.0);
644  Double_t fxbinmax = (dorxmax ? ((vxmax-xbinmax+xbinw)/xbinw):1.0);
645  Double_t fybinmin = (dorymin ? ((ybinmin+ybinw-vymin)/ybinw):1.0);
646  Double_t fybinmax = (dorymax ? ((vymax-ybinmax+ybinw)/ybinw):1.0);
647  //
648  Double_t fx,fy;
649  Double_t xc,yc;
650  // fill histo
651  for (Int_t binx = binxmin; binx<binxmax+1; binx++) {
652  if (binx==binxmin) {
653  fx = fxbinmin;
654  }
655  else if (binx==binxmax) {
656  fx = fxbinmax;
657  }
658  else {
659  fx = 1.0;
660  }
661  xc = h2->GetXaxis()->GetBinCenter(binx);
662  for (Int_t biny = binymin; biny<binymax+1; biny++) {
663  if (biny==binymin) {
664  fy = fybinmin;
665  }
666  else if (biny==binymax) {
667  fy = fybinmax;
668  }
669  else {
670  fy = 1.0;
671  }
672  yc = h2->GetYaxis()->GetBinCenter(biny);
673  h2->Fill(xc,yc,val*fx*fy);
674  }
675  }
676 }
677 
678 ////////////////////////////////////////////////////////////////////////////////
679 /// help routine to MakeVisHists() - fills for all variables
680 
681 void TMVA::RuleFit::FillVisHistCut(const Rule* rule, std::vector<TH2F *> & hlist)
682 {
683  Int_t nhists = hlist.size();
684  Int_t nvar = fMethodBase->GetNvar();
685  if (nhists!=nvar) Log() << kFATAL << "BUG TRAP: number of hists is not equal the number of variables!" << Endl;
686  //
687  std::vector<Int_t> vindex;
688  TString hstr;
689  // not a nice way to do a check...
690  for (Int_t ih=0; ih<nhists; ih++) {
691  hstr = hlist[ih]->GetTitle();
692  for (Int_t iv=0; iv<nvar; iv++) {
693  if (fMethodBase->GetInputTitle(iv) == hstr)
694  vindex.push_back(iv);
695  }
696  }
697  //
698  for (Int_t iv=0; iv<nvar; iv++) {
699  if (rule) {
700  if (rule->ContainsVariable(vindex[iv])) {
701  FillCut(hlist[iv],rule,vindex[iv]);
702  }
703  }
704  else {
705  FillLin(hlist[iv],vindex[iv]);
706  }
707  }
708 }
709 ////////////////////////////////////////////////////////////////////////////////
710 /// help routine to MakeVisHists() - fills for all correlation plots
711 
712 void TMVA::RuleFit::FillVisHistCorr(const Rule * rule, std::vector<TH2F *> & hlist)
713 {
714  if (rule==0) return;
715  Double_t ruleimp = rule->GetImportance();
716  if (!(ruleimp>0)) return;
717  if (ruleimp<fRuleEnsemble.GetImportanceCut()) return;
718  //
719  Int_t nhists = hlist.size();
720  Int_t nvar = fMethodBase->GetNvar();
721  Int_t ncorr = (nvar*(nvar+1)/2)-nvar;
722  if (nhists!=ncorr) Log() << kERROR << "BUG TRAP: number of corr hists is not correct! ncorr = "
723  << ncorr << " nvar = " << nvar << " nhists = " << nhists << Endl;
724  //
725  std::vector< std::pair<Int_t,Int_t> > vindex;
726  TString hstr, var1, var2;
727  Int_t iv1=0,iv2=0;
728  // not a nice way to do a check...
729  for (Int_t ih=0; ih<nhists; ih++) {
730  hstr = hlist[ih]->GetName();
731  if (GetCorrVars( hstr, var1, var2 )) {
732  iv1 = fMethodBase->DataInfo().FindVarIndex( var1 );
733  iv2 = fMethodBase->DataInfo().FindVarIndex( var2 );
734  vindex.push_back( std::pair<Int_t,Int_t>(iv2,iv1) ); // pair X, Y
735  }
736  else {
737  Log() << kERROR << "BUG TRAP: should not be here - failed getting var1 and var2" << Endl;
738  }
739  }
740  //
741  for (Int_t ih=0; ih<nhists; ih++) {
742  if ( (rule->ContainsVariable(vindex[ih].first)) ||
743  (rule->ContainsVariable(vindex[ih].second)) ) {
744  FillCorr(hlist[ih],rule,vindex[ih].first,vindex[ih].second);
745  }
746  }
747 }
748 ////////////////////////////////////////////////////////////////////////////////
749 /// get first and second variables from title
750 
752 {
753  var1="";
754  var2="";
755  if(!title.BeginsWith("scat_")) return kFALSE;
756 
757  TString titleCopy = title(5,title.Length());
758  if(titleCopy.Index("_RF2D")>=0) titleCopy.Remove(titleCopy.Index("_RF2D"));
759 
760  Int_t splitPos = titleCopy.Index("_vs_");
761  if(splitPos>=0) { // there is a _vs_ in the string
762  var1 = titleCopy(0,splitPos);
763  var2 = titleCopy(splitPos+4, titleCopy.Length());
764  return kTRUE;
765  }
766  else {
767  var1 = titleCopy;
768  return kFALSE;
769  }
770 }
771 ////////////////////////////////////////////////////////////////////////////////
772 /// this will create histograms visualizing the rule ensemble
773 
775 {
776  const TString directories[5] = { "InputVariables_Id",
777  "InputVariables_Deco",
778  "InputVariables_PCA",
779  "InputVariables_Gauss",
780  "InputVariables_Gauss_Deco" };
781 
782  const TString corrDirName = "CorrelationPlots";
783 
784  TDirectory* rootDir = fMethodBase->GetFile();
785  TDirectory* varDir = 0;
786  TDirectory* corrDir = 0;
787 
788  TDirectory* methodDir = fMethodBase->BaseDir();
789  TString varDirName;
790  //
791  Bool_t done=(rootDir==0);
792  Int_t type=0;
793  if (done) {
794  Log() << kWARNING << "No basedir - BUG??" << Endl;
795  return;
796  }
797  while (!done) {
798  varDir = (TDirectory*)rootDir->Get( directories[type] );
799  type++;
800  done = ((varDir!=0) || (type>4));
801  }
802  if (varDir==0) {
803  Log() << kWARNING << "No input variable directory found - BUG?" << Endl;
804  return;
805  }
806  corrDir = (TDirectory*)varDir->Get( corrDirName );
807  if (corrDir==0) {
808  Log() << kWARNING << "No correlation directory found" << Endl;
809  Log() << kWARNING << "Check for other warnings related to correlation histograms" << Endl;
810  return;
811  }
812  if (methodDir==0) {
813  Log() << kWARNING << "No rulefit method directory found - BUG?" << Endl;
814  return;
815  }
816 
817  varDirName = varDir->GetName();
818  varDir->cd();
819  //
820  // get correlation plot directory
821  corrDir = (TDirectory *)varDir->Get(corrDirName);
822  if (corrDir==0) {
823  Log() << kWARNING << "No correlation directory found : " << corrDirName << Endl;
824  return;
825  }
826 
827  // how many plots are in the var directory?
828  Int_t noPlots = ((varDir->GetListOfKeys())->GetEntries()) / 2;
829  Log() << kDEBUG << "Got number of plots = " << noPlots << Endl;
830 
831  // loop over all objects in directory
832  std::vector<TH2F *> h1Vector;
833  std::vector<TH2F *> h2CorrVector;
834  TIter next(varDir->GetListOfKeys());
835  TKey *key;
836  while ((key = (TKey*)next())) {
837  // make sure, that we only look at histograms
838  TClass *cl = gROOT->GetClass(key->GetClassName());
839  if (!cl->InheritsFrom(TH1F::Class())) continue;
840  TH1F *sig = (TH1F*)key->ReadObj();
841  TString hname= sig->GetName();
842  Log() << kDEBUG << "Got histogram : " << hname << Endl;
843 
844  // check for all signal histograms
845  if (hname.Contains("__S")){ // found a new signal plot
846  TString htitle = sig->GetTitle();
847  htitle.ReplaceAll("signal","");
848  TString newname = hname;
849  newname.ReplaceAll("__Signal","__RF");
850  newname.ReplaceAll("__S","__RF");
851 
852  methodDir->cd();
853  TH2F *newhist = new TH2F(newname,htitle,sig->GetNbinsX(),sig->GetXaxis()->GetXmin(),sig->GetXaxis()->GetXmax(),
854  1,sig->GetYaxis()->GetXmin(),sig->GetYaxis()->GetXmax());
855  varDir->cd();
856  h1Vector.push_back( newhist );
857  }
858  }
859  //
860  corrDir->cd();
861  TString var1,var2;
862  TIter nextCorr(corrDir->GetListOfKeys());
863  while ((key = (TKey*)nextCorr())) {
864  // make sure, that we only look at histograms
865  TClass *cl = gROOT->GetClass(key->GetClassName());
866  if (!cl->InheritsFrom(TH2F::Class())) continue;
867  TH2F *sig = (TH2F*)key->ReadObj();
868  TString hname= sig->GetName();
869 
870  // check for all signal histograms
871  if ((hname.Contains("scat_")) && (hname.Contains("_Signal"))) {
872  Log() << kDEBUG << "Got histogram (2D) : " << hname << Endl;
873  TString htitle = sig->GetTitle();
874  htitle.ReplaceAll("(Signal)","");
875  TString newname = hname;
876  newname.ReplaceAll("_Signal","_RF2D");
877 
878  methodDir->cd();
879  const Int_t rebin=2;
880  TH2F *newhist = new TH2F(newname,htitle,
881  sig->GetNbinsX()/rebin,sig->GetXaxis()->GetXmin(),sig->GetXaxis()->GetXmax(),
882  sig->GetNbinsY()/rebin,sig->GetYaxis()->GetXmin(),sig->GetYaxis()->GetXmax());
883  if (GetCorrVars( newname, var1, var2 )) {
884  Int_t iv1 = fMethodBase->DataInfo().FindVarIndex(var1);
885  Int_t iv2 = fMethodBase->DataInfo().FindVarIndex(var2);
886  if (iv1<0) {
887  sig->GetYaxis()->SetTitle(var1);
888  }
889  else {
891  }
892  if (iv2<0) {
893  sig->GetXaxis()->SetTitle(var2);
894  }
895  else {
897  }
898  }
899  corrDir->cd();
900  h2CorrVector.push_back( newhist );
901  }
902  }
903 
904 
905  varDir->cd();
906  // fill rules
907  UInt_t nrules = fRuleEnsemble.GetNRules();
908  const Rule *rule;
909  for (UInt_t i=0; i<nrules; i++) {
910  rule = fRuleEnsemble.GetRulesConst(i);
911  FillVisHistCut(rule, h1Vector);
912  }
913  // fill linear terms and normalise hists
914  FillVisHistCut(0, h1Vector);
915  NormVisHists(h1Vector);
916 
917  //
918  corrDir->cd();
919  // fill rules
920  for (UInt_t i=0; i<nrules; i++) {
921  rule = fRuleEnsemble.GetRulesConst(i);
922  FillVisHistCorr(rule, h2CorrVector);
923  }
924  NormVisHists(h2CorrVector);
925 
926  // write histograms to file
927  methodDir->cd();
928  for (UInt_t i=0; i<h1Vector.size(); i++) h1Vector[i]->Write();
929  for (UInt_t i=0; i<h2CorrVector.size(); i++) h2CorrVector[i]->Write();
930 }
931 
932 ////////////////////////////////////////////////////////////////////////////////
933 /// this will create a histograms intended rather for debugging or for the curious user
934 
936 {
937  TDirectory* methodDir = fMethodBase->BaseDir();
938  if (methodDir==0) {
939  Log() << kWARNING << "<MakeDebugHists> No rulefit method directory found - bug?" << Endl;
940  return;
941  }
942  //
943  methodDir->cd();
944  std::vector<Double_t> distances;
945  std::vector<Double_t> fncuts;
946  std::vector<Double_t> fnvars;
947  const Rule *ruleA;
948  const Rule *ruleB;
949  Double_t dABmin=1000000.0;
950  Double_t dABmax=-1.0;
951  UInt_t nrules = fRuleEnsemble.GetNRules();
952  for (UInt_t i=0; i<nrules; i++) {
953  ruleA = fRuleEnsemble.GetRulesConst(i);
954  for (UInt_t j=i+1; j<nrules; j++) {
955  ruleB = fRuleEnsemble.GetRulesConst(j);
956  Double_t dAB = ruleA->RuleDist( *ruleB, kTRUE );
957  if (dAB>-0.5) {
958  UInt_t nc = ruleA->GetNcuts();
959  UInt_t nv = ruleA->GetNumVarsUsed();
960  distances.push_back(dAB);
961  fncuts.push_back(static_cast<Double_t>(nc));
962  fnvars.push_back(static_cast<Double_t>(nv));
963  if (dAB<dABmin) dABmin=dAB;
964  if (dAB>dABmax) dABmax=dAB;
965  }
966  }
967  }
968  //
969  TH1F *histDist = new TH1F("RuleDist","Rule distances",100,dABmin,dABmax);
970  TTree *distNtuple = new TTree("RuleDistNtuple","RuleDist ntuple");
971  Double_t ntDist;
972  Double_t ntNcuts;
973  Double_t ntNvars;
974  distNtuple->Branch("dist", &ntDist, "dist/D");
975  distNtuple->Branch("ncuts",&ntNcuts, "ncuts/D");
976  distNtuple->Branch("nvars",&ntNvars, "nvars/D");
977  //
978  for (UInt_t i=0; i<distances.size(); i++) {
979  histDist->Fill(distances[i]);
980  ntDist = distances[i];
981  ntNcuts = fncuts[i];
982  ntNvars = fnvars[i];
983  distNtuple->Fill();
984  }
985  distNtuple->Write();
986 }
std::vector< const TMVA::Event * > fTrainingEventsRndm
Definition: RuleFit.h:164
void ForestStatistics()
summary of statistics of all trees
Definition: RuleFit.cxx:382
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
void SetPruneMethod(EPruneMethod m=kCostComplexityPruning)
Definition: DecisionTree.h:148
void MakeForest()
make a forest of decisiontrees
Definition: RuleFit.cxx:217
virtual Int_t FindBin(Double_t x, Double_t y=0, Double_t z=0)
Return Global bin number corresponding to x,y,z.
Definition: TH1.cxx:3440
virtual void Scale(Double_t c1=1, Option_t *option="")
Multiply this histogram by a constant c1.
Definition: TH1.cxx:5936
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3125
UInt_t GetNumVarsUsed() const
Definition: Rule.h:136
virtual Double_t GetMaximum(Double_t maxval=FLT_MAX) const
Return maximum value smaller than maxval of bins in the range, unless the value has been overridden b...
Definition: TH1.cxx:7664
Double_t GetTreeEveFrac() const
Random number generator class based on M.
Definition: TRandom3.h:29
virtual TList * GetListOfKeys() const
Definition: TDirectory.h:158
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
const RuleEnsemble & GetRuleEnsemble() const
Definition: RuleFit.h:148
long long Long64_t
Definition: RtypesCore.h:69
virtual void SetMaximum(Double_t maximum=-1111)
Definition: TH1.h:399
Bool_t GetCutRange(Int_t sel, Double_t &rmin, Double_t &rmax, Bool_t &dormin, Bool_t &dormax) const
get cut range for a given selector
Definition: RuleCut.cxx:170
void CalcImportance()
calculates the importance of each rule
Definition: RuleFit.cxx:414
virtual TObject * Get(const char *namecycle)
Return pointer to object identified by namecycle.
Definition: TDirectory.cxx:729
const std::vector< const TMVA::Event *> & GetTrainingEvents() const
Definition: RuleFit.h:141
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:504
Double_t CheckEvent(const TMVA::Event *, Bool_t UseYesNoLeaf=kFALSE) const
the event e is put into the decision tree (starting at the root node) and the output is NodeType (sig...
Bool_t ContainsVariable(UInt_t iv) const
check if variable in node
Definition: Rule.cxx:135
TString & ReplaceAll(const TString &s1, const TString &s2)
Definition: TString.h:635
UInt_t GetNvar() const
Definition: MethodBase.h:340
MsgLogger & Log() const
Definition: RuleFit.h:177
UInt_t GetNNodes() const
Definition: BinaryTree.h:92
virtual Int_t Fill()
Fill all branches.
Definition: TTree.cxx:4375
void NormVisHists(std::vector< TH2F *> &hlist)
normalize rule importance hists
Definition: RuleFit.cxx:483
THist< 1, float, THistStatContent, THistStatUncertainty > TH1F
Definition: THist.hxx:302
void SetMsgType(EMsgType t)
set the current message type to that of mlog for this class and all other subtools ...
Definition: RuleFit.cxx:186
const MethodBase * fMethodBase
Definition: RuleFit.h:173
const std::vector< TMVA::Rule * > & GetRulesConst() const
Definition: RuleEnsemble.h:277
Bool_t GetCorrVars(TString &title, TString &var1, TString &var2)
get first and second variables from title
Definition: RuleFit.cxx:751
void InitNEveEff()
init effective number of events (using event weights)
Definition: RuleFit.cxx:93
virtual void SetMinimum(Double_t minimum=-1111)
Definition: TH1.h:400
#define gROOT
Definition: TROOT.h:364
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Definition: TString.h:582
void FitCoefficients()
Fit the coefficients for the rule ensemble.
Definition: RuleFit.cxx:405
Basic string class.
Definition: TString.h:137
const RuleCut * GetRuleCut() const
Definition: Rule.h:145
tomato 1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
std::vector< Double_t > fEventWeights
Definition: RuleFit.h:165
const char * GetInputTitle(Int_t i) const
Definition: MethodBase.h:347
Double_t fNEveEffTrain
Definition: RuleFit.h:168
const char * Class
Definition: TXMLSetup.cxx:64
void CleanupLinear()
cleanup linear model
void SetTrainingEvents(const std::vector< const TMVA::Event *> &el)
set the training events randomly
Definition: RuleFit.cxx:436
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
const std::vector< Double_t > & GetLinCoefficients() const
Definition: RuleEnsemble.h:279
const std::vector< const TMVA::DecisionTree * > & GetForest() const
Definition: RuleFit.h:147
void SetMsgType(EMsgType t)
void RuleResponseStats()
calculate various statistics for this rule
Tools & gTools()
Definition: Tools.cxx:79
RuleFit(void)
default constructor
Definition: RuleFit.cxx:71
Double_t GetXmin() const
Definition: TAxis.h:139
TStopwatch timer
Definition: pirndm.C:37
void BuildTree(TMVA::DecisionTree *dt)
build the decision tree using fNTreeSample events from fTrainingEventsRndm
Definition: RuleFit.cxx:196
TMVA::DecisionTree::EPruneMethod GetPruneMethod() const
const std::vector< Double_t > & GetLinImportance() const
Definition: RuleEnsemble.h:281
UInt_t GetNRules() const
Definition: RuleEnsemble.h:276
const Event * GetEvent() const
Definition: MethodBase.h:745
DataSet * Data() const
Definition: MethodBase.h:405
void ReshuffleEvents()
Definition: RuleFit.h:72
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
void GetRndmSampleEvents(std::vector< const TMVA::Event * > &evevec, UInt_t nevents)
draw a random subsample of the training events without replacement
Definition: RuleFit.cxx:463
DataSetInfo & DataInfo() const
Definition: MethodBase.h:406
void SetMinType(EMsgType minType)
Definition: MsgLogger.h:76
SeparationBase * GetSeparationBase() const
Book space in a file, create I/O buffers, to fill them, (un)compress them.
Definition: TKey.h:30
TFile * GetFile() const
Definition: MethodBase.h:366
virtual ~RuleFit(void)
destructor
Definition: RuleFit.cxx:85
Long64_t GetNTrainingEvents() const
Definition: DataSet.h:93
void CalcImportance()
calculate the importance of each rule
void SetMsgType(EMsgType t)
void SetMethodBase(const MethodBase *rfbase)
set MethodBase
Definition: RuleFit.cxx:146
void CleanupRules()
cleanup rules
UInt_t fNTreeSample
Definition: RuleFit.h:166
Double_t GetPruneStrength() const
Double_t GetImportanceCut() const
Definition: RuleEnsemble.h:273
void SetNVars(Int_t n)
Definition: DecisionTree.h:202
virtual Int_t Write(const char *name=0, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition: TTree.cxx:9042
void RestoreEventWeights()
save event weights - must be done before making the forest
Definition: RuleFit.cxx:317
Double_t RuleDist(const Rule &other, Bool_t useCutValue) const
Returns: -1.0 : rules are NOT equal, i.e, variables and/or cut directions are wrong >=0: rules are eq...
Definition: Rule.cxx:187
const MethodBase * GetMethodBase() const
Definition: RuleFit.h:153
void CalcVarImportance()
Calculates variable importance using eq (35) in RuleFit paper by Friedman et.al.
void Copy(const RuleFit &other)
copy method
Definition: RuleFit.cxx:155
void Initialize(Bool_t useTMVAStyle=kTRUE)
Definition: tmvaglob.cxx:176
void FillVisHistCut(const Rule *rule, std::vector< TH2F *> &hlist)
help routine to MakeVisHists() - fills for all variables
Definition: RuleFit.cxx:681
Bool_t DoLinear() const
Definition: RuleEnsemble.h:267
void FillCorr(TH2F *h2, const TMVA::Rule *rule, Int_t v1, Int_t v2)
fill rule correlation between vx and vy, weighted with either the importance or the coefficient ...
Definition: RuleFit.cxx:605
Double_t GetCoefficient() const
Definition: Rule.h:147
void MakeDebugHists()
this will create a histograms intended rather for debugging or for the curious user ...
Definition: RuleFit.cxx:935
static const Int_t randSEED
Definition: RuleFit.h:179
tomato 2-D histogram with a float per channel (see TH1 documentation)}
Definition: TH2.h:255
EMsgType
Definition: Types.h:61
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
Definition: TString.h:558
void SetPruneStrength(Double_t p)
Definition: DecisionTree.h:154
unsigned int UInt_t
Definition: RtypesCore.h:42
Ssiz_t Length() const
Definition: TString.h:390
void FillLin(TH2F *h2, Int_t vind)
fill lin
Definition: RuleFit.cxx:581
The ROOT global object gROOT contains a list of all defined classes.
Definition: TClass.h:81
TAxis * GetYaxis()
Definition: TH1.h:325
RuleEnsemble fRuleEnsemble
Definition: RuleFit.h:170
Bool_t InheritsFrom(const char *cl) const
Return kTRUE if this class inherits from a class with name "classname".
Definition: TClass.cxx:4610
void Boost(TMVA::DecisionTree *dt)
Boost the events.
Definition: RuleFit.cxx:335
Int_t FindVarIndex(const TString &) const
find variable by name
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
Definition: TH1.cxx:7749
UInt_t GetNcuts() const
Definition: Rule.h:139
virtual Int_t FindBin(Double_t x)
Find bin number corresponding to abscissa x.
Definition: TAxis.cxx:279
TString & Remove(Ssiz_t pos)
Definition: TString.h:616
Int_t GetNCuts() const
void SaveEventWeights()
save event weights - must be done before making the forest
Definition: RuleFit.cxx:305
#define ClassImp(name)
Definition: Rtypes.h:279
void Initialize(const RuleFit *rf)
Initializes all member variables with default values.
double f(double x)
double Double_t
Definition: RtypesCore.h:55
const MethodRuleFit * fMethodRuleFit
Definition: RuleFit.h:172
Describe directory structure in memory.
Definition: TDirectory.h:44
int type
Definition: TGX11.cxx:120
void MakeVisHists()
this will create histograms visualizing the rule ensemble
Definition: RuleFit.cxx:774
void SetCurrentType(Types::ETreeType type) const
Definition: DataSet.h:114
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition: TString.h:567
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Definition: TRolke.cxx:630
void FillVisHistCorr(const Rule *rule, std::vector< TH2F *> &hlist)
help routine to MakeVisHists() - fills for all correlation plots
Definition: RuleFit.cxx:712
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
void InitPtrs(const TMVA::MethodBase *rfbase)
initialize pointers
Definition: RuleFit.cxx:105
Int_t GetNTrees() const
Bool_t UseBoost() const
Definition: MethodRuleFit.h:94
void MakeModel()
create model
virtual Int_t Branch(TCollection *list, Int_t bufsize=32000, Int_t splitlevel=99, const char *name="")
Create one branch for each element in the collection.
Definition: TTree.cxx:1652
Double_t PruneTree(const EventConstList *validationSample=NULL)
prune (get rid of internal nodes) the Decision tree to avoid overtraining serveral different pruning ...
Abstract ClassifierFactory template that handles arbitrary types.
void FillCut(TH2F *h2, const TMVA::Rule *rule, Int_t vind)
Fill cut.
Definition: RuleFit.cxx:530
virtual Double_t GetBinWidth(Int_t bin) const
Return bin width.
Definition: TAxis.cxx:526
virtual Bool_t cd(const char *path=0)
Change current directory to "this" directory.
Definition: TDirectory.cxx:435
Double_t GetImportance() const
Definition: Rule.h:151
TDirectory * BaseDir() const
returns the ROOT directory where info/histograms etc of the corresponding MVA method instance are sto...
void Init()
Initializes all parameters using the RuleEnsemble and the training tree.
UInt_t BuildTree(const EventConstList &eventSample, DecisionTreeNode *node=NULL)
building the decision tree by recursively calling the splitting of one (root-) node into two daughter...
Bool_t fVisHistsUseImp
Definition: RuleFit.h:174
RuleFitParams fRuleFitParams
Definition: RuleFit.h:171
Double_t EvalEvent(const Event &e)
evaluate single event
Definition: RuleFit.cxx:428
Bool_t IsSignal(const Event *ev) const
std::vector< const TMVA::DecisionTree * > fForest
Definition: RuleFit.h:169
A TTree object has a header with a name and a title.
Definition: TTree.h:98
Double_t EvalEvent() const
Definition: RuleEnsemble.h:426
void Initialize(const TMVA::MethodBase *rfbase)
initialize the parameters of the RuleFit method and make rules
Definition: RuleFit.cxx:115
Definition: first.py:1
Double_t CalcWeightSum(const std::vector< const TMVA::Event *> *events, UInt_t neve=0)
calculate the sum of weights
Definition: RuleFit.cxx:171
const MethodRuleFit * GetMethodRuleFit() const
Definition: RuleFit.h:152
virtual Int_t GetNbinsX() const
Definition: TH1.h:301
void SetRuleFit(RuleFit *rf)
Definition: RuleFitParams.h:70
Double_t Sqrt(Double_t x)
Definition: TMath.h:464
void MakeGDPath()
The following finds the gradient directed path in parameter space.
virtual Int_t GetBin(Int_t binx, Int_t biny, Int_t binz=0) const
Return Global bin number corresponding to binx,y,z.
Definition: TH2.cxx:966
const Bool_t kTRUE
Definition: Rtypes.h:91
Int_t Fill(Double_t)
Invalid Fill method.
Definition: TH2.cxx:292
std::vector< const TMVA::Event * > fTrainingEvents
Definition: RuleFit.h:163
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:155
THist< 2, float, THistStatContent, THistStatUncertainty > TH2F
Definition: THist.hxx:308
Double_t GetXmax() const
Definition: TAxis.h:140
Double_t GetSupport() const
Definition: Rule.h:148
MsgLogger * fLogger
Definition: RuleFit.h:176
TAxis * GetXaxis()
Definition: TH1.h:324
Double_t GetMaxFracNEve() const
virtual Int_t GetNbinsY() const
Definition: TH1.h:302
virtual const char * GetTitle() const
Returns title of object.
Definition: TNamed.h:52
Double_t GetMinFracNEve() const