Logo ROOT  
Reference Guide
IPruneTool.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  * IPruneTool - a helper interface class to prune a decision tree *
9  * *
10  * Authors (alphabetical): *
11  * Doug Schouten <dschoute@sfu.ca> - Simon Fraser U., Canada *
12  * *
13  * Copyright (c) 2005: *
14  * CERN, Switzerland *
15  * MPI-K Heidelberg, Germany *
16  * *
17  * Redistribution and use in source and binary forms, with or without *
18  * modification, are permitted according to the terms listed in LICENSE *
19  * (http://mva.sourceforge.net/license.txt) *
20  **********************************************************************************/
21 
22 #ifndef ROOT_TMVA_IPruneTool
23 #define ROOT_TMVA_IPruneTool
24 
25 #include <iosfwd>
26 #include <vector>
27 
28 #include "TMVA/SeparationBase.h"
29 
30 #include "TMVA/DecisionTree.h"
31 
32 namespace TMVA {
33 
34  // class MsgLogger;
35 
36  ////////////////////////////////////////////////////////////
37  // Basic struct for saving relevant pruning information //
38  ////////////////////////////////////////////////////////////
39  class PruningInfo {
40 
41  public:
42 
44  PruningInfo( Double_t q, Double_t alpha, std::vector<DecisionTreeNode*> sequence );
45  Double_t QualityIndex; //! quality measure for a pruned subtree T of T_max
46  Double_t PruneStrength; //! the regularization parameter for pruning
47  std::vector<DecisionTreeNode*> PruneSequence; //! the sequence of pruning locations in T_max that yields T
48  };
49 
50  inline PruningInfo::PruningInfo( Double_t q, Double_t alpha, std::vector<DecisionTreeNode*> sequence )
51  : QualityIndex(q), PruneStrength(alpha), PruneSequence(sequence) {}
52 
53 /*! \class TMVA::IPruneTool
54 \ingroup TMVA
55 IPruneTool - a helper interface class to prune a decision tree
56 
57 Any tool which implements the interface should provide two modes for tree pruning:
58 
59  1. automatically find the "best" prune strength by minimizing the error rate on a test sample
60  if SetAutomatic() is called, or if automatic = kTRUE argument is set in CalculatePruningInfo()
61  In this case, the PruningInfo object returned contains the error rate of the optimally pruned
62  tree, the optimal prune strength, and the sequence of nodes to prune to obtain the optimal
63  pruned tree from the original DecisionTree
64 
65  2. a user-provided pruning strength parameter is used to prune the tree, in which case the returned
66  PruningInfo object has QualityIndex = -1, PruneStrength = user prune strength, and PruneSequence
67  is the list of nodes to prune
68 */
69 
70  class IPruneTool {
71 
72  public:
73 
74  typedef std::vector<const Event*> EventSample;
75 
76  IPruneTool( );
77  virtual ~IPruneTool();
78 
79  public:
80 
81  // returns the PruningInfo object for a given tree and test sample
82  virtual PruningInfo* CalculatePruningInfo( DecisionTree* dt, const EventSample* testEvents = NULL,
83  Bool_t isAutomatic = kFALSE ) = 0;
84 
85  public:
86 
87  // set the prune strength parameter to use in pruning
88  inline void SetPruneStrength( Double_t alpha ) { fPruneStrength = alpha; }
89  // return the prune strength the tool is using
90  inline Double_t GetPruneStrength( ) const { return fPruneStrength; }
91 
92  // if the prune strength parameter is < 0, the tool will automatically find an optimal strength
93  // set the tool to automatic mode
94  inline void SetAutomatic( ) { fPruneStrength = -1.0; };
95  inline Bool_t IsAutomatic( ) const { return fPruneStrength <= 0.0; }
96 
97  protected:
98 
99  // mutable MsgLogger* fLogger; //! output stream to save logging information
100  // MsgLogger& Log() const { return *fLogger; }
101  Double_t fPruneStrength; //! regularization parameter in pruning
102 
103 
104  Double_t S, B;
105  };
106 
108  fPruneStrength(0.0),
109  S(0),
110  B(0)
111  {}
112 }
113 
114 #endif
TMVA::IPruneTool
Definition: IPruneTool.h:89
TMVA::PruningInfo
Definition: IPruneTool.h:58
TMVA::IPruneTool::EventSample
std::vector< const Event * > EventSample
Definition: IPruneTool.h:93
TMVA::IPruneTool::B
Double_t B
Definition: IPruneTool.h:123
TMVA::PruningInfo::PruneStrength
Double_t PruneStrength
quality measure for a pruned subtree T of T_max
Definition: IPruneTool.h:84
TMVA::IPruneTool::GetPruneStrength
Double_t GetPruneStrength() const
Definition: IPruneTool.h:109
TMVA::IPruneTool::SetPruneStrength
void SetPruneStrength(Double_t alpha)
Definition: IPruneTool.h:107
TMVA::IPruneTool::S
Double_t S
regularization parameter in pruning
Definition: IPruneTool.h:123
RooFitShortHand::S
RooArgSet S(const RooAbsArg &v1)
Definition: RooGlobalFunc.cxx:348
TMVA::IPruneTool::~IPruneTool
virtual ~IPruneTool()
Definition: ExpectedErrorPruneTool.cxx:58
TMVA::PruningInfo::PruneSequence
std::vector< DecisionTreeNode * > PruneSequence
the regularization parameter for pruning
Definition: IPruneTool.h:85
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TMVA::DecisionTree
Definition: DecisionTree.h:65
bool
q
float * q
Definition: THbookFile.cxx:89
SeparationBase.h
DecisionTree.h
kFALSE
const Bool_t kFALSE
Definition: RtypesCore.h:92
TMVA::IPruneTool::IPruneTool
IPruneTool()
Definition: IPruneTool.h:126
TMVA::IPruneTool::IsAutomatic
Bool_t IsAutomatic() const
Definition: IPruneTool.h:114
Double_t
double Double_t
Definition: RtypesCore.h:59
TMVA::IPruneTool::fPruneStrength
Double_t fPruneStrength
Definition: IPruneTool.h:120
TMVA::IPruneTool::CalculatePruningInfo
virtual PruningInfo * CalculatePruningInfo(DecisionTree *dt, const EventSample *testEvents=NULL, Bool_t isAutomatic=kFALSE)=0
ROOT::Math::Cephes::B
static double B[]
Definition: SpecFuncCephes.cxx:178
TMVA::IPruneTool::SetAutomatic
void SetAutomatic()
Definition: IPruneTool.h:113
TMVA::PruningInfo::PruningInfo
PruningInfo()
Definition: IPruneTool.h:81
TMVA::PruningInfo::QualityIndex
Double_t QualityIndex
Definition: IPruneTool.h:83
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22