Logo ROOT   6.08/07
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 #ifndef ROOT_TMVA_SeparationBase
29 #include "TMVA/SeparationBase.h"
30 #endif
31 
32 #ifndef ROOT_TMVA_DecisionTree
33 #include "TMVA/DecisionTree.h"
34 #endif
35 
36 namespace TMVA {
37 
38  // class MsgLogger;
39 
40  ////////////////////////////////////////////////////////////
41  // Basic struct for saving relevant pruning information //
42  ////////////////////////////////////////////////////////////
43  class PruningInfo {
44 
45  public:
46 
48  PruningInfo( Double_t q, Double_t alpha, std::vector<DecisionTreeNode*> sequence );
49  Double_t QualityIndex; //! quality measure for a pruned subtree T of T_max
50  Double_t PruneStrength; //! the regularization parameter for pruning
51  std::vector<DecisionTreeNode*> PruneSequence; //! the sequence of pruning locations in T_max that yields T
52  };
53 
54  inline PruningInfo::PruningInfo( Double_t q, Double_t alpha, std::vector<DecisionTreeNode*> sequence )
55  : QualityIndex(q), PruneStrength(alpha), PruneSequence(sequence) {}
56 
57  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
58  // IPruneTool - a helper interface class to prune a decision tree //
59  // //
60  // Any tool which implements the interface should provide two modes for tree pruning: //
61  // 1. automatically find the "best" prune strength by minimizing the error rate on a test sample //
62  // if SetAutomatic() is called, or if automatic = kTRUE argument is set in CalculatePruningInfo() //
63  // In this case, the PruningInfo object returned contains the error rate of the optimally pruned //
64  // tree, the optimal prune strength, and the sequence of nodes to prune to obtain the optimal //
65  // pruned tree from the original DecisionTree //
66  // //
67  // 2. a user-provided pruning strength parameter is used to prune the tree, in which case the returned //
68  // PruningInfo object has QualityIndex = -1, PruneStrength = user prune strength, and PruneSequence //
69  // is the list of nodes to prune //
70  ////////////////////////////////////////////////////////////////////////////////////////////////////////////
71 
72  class IPruneTool {
73 
74  public:
75 
76  typedef std::vector<const Event*> EventSample;
77 
78  IPruneTool( );
79  virtual ~IPruneTool();
80 
81  public:
82 
83  // returns the PruningInfo object for a given tree and test sample
84  virtual PruningInfo* CalculatePruningInfo( DecisionTree* dt, const EventSample* testEvents = NULL,
85  Bool_t isAutomatic = kFALSE ) = 0;
86 
87  public:
88 
89  // set the prune strength parameter to use in pruning
90  inline void SetPruneStrength( Double_t alpha ) { fPruneStrength = alpha; }
91  // return the prune strength the tool is using
92  inline Double_t GetPruneStrength( ) const { return fPruneStrength; }
93 
94  // if the prune strength parameter is < 0, the tool will automatically find an optimal strength
95  // set the tool to automatic mode
96  inline void SetAutomatic( ) { fPruneStrength = -1.0; };
97  inline Bool_t IsAutomatic( ) const { return fPruneStrength <= 0.0; }
98 
99  protected:
100 
101  // mutable MsgLogger* fLogger; //! output stream to save logging information
102  // MsgLogger& Log() const { return *fLogger; }
103  Double_t fPruneStrength; //! regularization parameter in pruning
104 
105 
107  };
108 
110  fPruneStrength(0.0),
111  S(0),
112  B(0)
113  {}
115 
116 }
117 
118 #endif
static double B[]
Double_t PruneStrength
quality measure for a pruned subtree T of T_max
Definition: IPruneTool.h:50
Double_t fPruneStrength
Definition: IPruneTool.h:103
std::vector< DecisionTreeNode * > PruneSequence
the regularization parameter for pruning
Definition: IPruneTool.h:51
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
void SetAutomatic()
Definition: IPruneTool.h:96
Double_t GetPruneStrength() const
Definition: IPruneTool.h:92
Bool_t IsAutomatic() const
Definition: IPruneTool.h:97
std::vector< const Event * > EventSample
Definition: IPruneTool.h:76
Double_t S
regularization parameter in pruning
Definition: IPruneTool.h:106
RooArgSet S(const RooAbsArg &v1)
double Double_t
Definition: RtypesCore.h:55
Abstract ClassifierFactory template that handles arbitrary types.
#define NULL
Definition: Rtypes.h:82
Double_t QualityIndex
Definition: IPruneTool.h:49
void SetPruneStrength(Double_t alpha)
Definition: IPruneTool.h:90
float * q
Definition: THbookFile.cxx:87
virtual ~IPruneTool()
Definition: IPruneTool.h:114