Logo ROOT  
Reference Guide
ExpectedErrorPruneTool.h
Go to the documentation of this file.
1 /**********************************************************************************
2  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
3  * Package: TMVA *
4  * Class : TMVA::DecisionTree *
5  * Web : http://tmva.sourceforge.net *
6  * *
7  * Description: *
8  * Implementation of a Decision Tree *
9  * *
10  * Authors (alphabetical): *
11  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
12  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
13  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
14  * Doug Schouten <dschoute@sfu.ca> - Simon Fraser U., Canada *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * U. of Victoria, Canada *
19  * MPI-K Heidelberg, Germany *
20  * *
21  * Redistribution and use in source and binary forms, with or without *
22  * modification, are permitted according to the terms listed in LICENSE *
23  * (http://mva.sourceforge.net/license.txt) *
24  * *
25  **********************************************************************************/
26 
27 #ifndef ROOT_TMVA_ExpectedErrorPruneTool
28 #define ROOT_TMVA_ExpectedErrorPruneTool
29 
30 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
31 // ExpectedErrorPruneTool - a helper class to prune a decision tree using the expected error (C4.5) method //
32 // //
33 // Uses an upper limit on the error made by the classification done by each node. If the S/S+B of the node //
34 // is f, then according to the training sample, the error rate (fraction of misclassified events by this //
35 // node) is (1-f). Now f has a statistical error according to the binomial distribution hence the error on //
36 // f can be estimated (same error as the binomial error for efficiency calculations //
37 // ( sigma = sqrt(eff(1-eff)/nEvts ) ) //
38 // //
39 // This tool prunes branches from a tree if the expected error of a node is less than that of the sum of //
40 // the error in its descendants. //
41 // //
42 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
43 
44 #include <vector>
45 
46 #include "TMath.h"
47 
48 #include "TMVA/IPruneTool.h"
49 
50 namespace TMVA {
51 
52  class MsgLogger;
53 
55  public:
57  virtual ~ExpectedErrorPruneTool( );
58 
59  // returns the PruningInfo object for a given tree and test sample
60  virtual PruningInfo* CalculatePruningInfo( DecisionTree* dt, const IPruneTool::EventSample* testEvents = NULL,
61  Bool_t isAutomatic = kFALSE );
62 
63  public:
64  // set the increment dalpha with which to scan for the optimal prune strength
65  inline void SetPruneStrengthIncrement( Double_t dalpha ) { fDeltaPruneStrength = dalpha; }
66 
67  private:
68  void FindListOfNodes( DecisionTreeNode* node );
69  Double_t GetNodeError( DecisionTreeNode* node ) const;
71  Int_t CountNodes( DecisionTreeNode* node, Int_t icount = 0 );
72 
73  Double_t fDeltaPruneStrength; //! the stepsize for optimizing the pruning strength parameter
74  Double_t fNodePurityLimit; //! the purity limit for labelling a terminal node as signal
75  std::vector<DecisionTreeNode*> fPruneSequence; //! the (optimal) prune sequence
76  // std::multimap<const Double_t, Double_t> fQualityMap; //! map of tree quality <=> prune strength
77  mutable MsgLogger* fLogger; // message logger
78  MsgLogger& Log() const { return *fLogger; }
79  };
80 
84  Int_t counter = icount + 1; // count this node
85  if(!(node->IsTerminal()) && l != NULL && r != NULL) {
86  counter = CountNodes(l,counter);
87  counter = CountNodes(r,counter);
88  }
89  return counter;
90  }
91 }
92 
93 #endif
94 
l
auto * l
Definition: textangle.C:4
TMVA::ExpectedErrorPruneTool::CalculatePruningInfo
virtual PruningInfo * CalculatePruningInfo(DecisionTree *dt, const IPruneTool::EventSample *testEvents=NULL, Bool_t isAutomatic=kFALSE)
Definition: ExpectedErrorPruneTool.cxx:79
TMVA::IPruneTool
IPruneTool - a helper interface class to prune a decision tree.
Definition: IPruneTool.h:70
TMVA::ExpectedErrorPruneTool::FindListOfNodes
void FindListOfNodes(DecisionTreeNode *node)
recursive pruning of nodes using the Expected Error Pruning (EEP)
Definition: ExpectedErrorPruneTool.cxx:175
TMVA::PruningInfo
Definition: IPruneTool.h:39
TMVA::ExpectedErrorPruneTool::fDeltaPruneStrength
Double_t fDeltaPruneStrength
Definition: ExpectedErrorPruneTool.h:73
TMVA::IPruneTool::EventSample
std::vector< const Event * > EventSample
Definition: IPruneTool.h:74
TMVA::ExpectedErrorPruneTool::GetSubTreeError
Double_t GetSubTreeError(DecisionTreeNode *node) const
calculate the expected statistical error on the subtree below "node" which is used in the expected er...
Definition: ExpectedErrorPruneTool.cxx:193
TMVA::ExpectedErrorPruneTool::SetPruneStrengthIncrement
void SetPruneStrengthIncrement(Double_t dalpha)
Definition: ExpectedErrorPruneTool.h:65
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TMVA::ExpectedErrorPruneTool::ExpectedErrorPruneTool
ExpectedErrorPruneTool()
Definition: ExpectedErrorPruneTool.cxx:62
TMVA::DecisionTreeNode
Definition: DecisionTreeNode.h:117
TMVA::ExpectedErrorPruneTool::GetNodeError
Double_t GetNodeError(DecisionTreeNode *node) const
Calculate an UPPER limit on the error made by the classification done by this node.
Definition: ExpectedErrorPruneTool.cxx:219
TMVA::DecisionTreeNode::IsTerminal
Bool_t IsTerminal() const
Definition: DecisionTreeNode.h:337
TMVA::DecisionTree
Implementation of a Decision Tree.
Definition: DecisionTree.h:65
bool
TMVA::ExpectedErrorPruneTool::Log
MsgLogger & Log() const
Definition: ExpectedErrorPruneTool.h:78
TMVA::DecisionTreeNode::GetLeft
virtual DecisionTreeNode * GetLeft() const
Definition: DecisionTreeNode.h:282
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::ExpectedErrorPruneTool::CountNodes
Int_t CountNodes(DecisionTreeNode *node, Int_t icount=0)
Definition: ExpectedErrorPruneTool.h:81
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::MsgLogger
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
TMVA::ExpectedErrorPruneTool::fPruneSequence
std::vector< DecisionTreeNode * > fPruneSequence
the purity limit for labelling a terminal node as signal
Definition: ExpectedErrorPruneTool.h:75
TMVA::ExpectedErrorPruneTool::fLogger
MsgLogger * fLogger
the (optimal) prune sequence
Definition: ExpectedErrorPruneTool.h:77
TMVA::ExpectedErrorPruneTool::fNodePurityLimit
Double_t fNodePurityLimit
the stepsize for optimizing the pruning strength parameter
Definition: ExpectedErrorPruneTool.h:74
TMVA::ExpectedErrorPruneTool
A helper class to prune a decision tree using the expected error (C4.5) method.
Definition: ExpectedErrorPruneTool.h:54
TMVA::ExpectedErrorPruneTool::~ExpectedErrorPruneTool
virtual ~ExpectedErrorPruneTool()
Definition: ExpectedErrorPruneTool.cxx:71
IPruneTool.h
TMVA::DecisionTreeNode::GetRight
virtual DecisionTreeNode * GetRight() const
Definition: DecisionTreeNode.h:283
TMath.h
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
int