Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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
32namespace TMVA {
33
34 // class MsgLogger;
35
36 ////////////////////////////////////////////////////////////
37 // Basic struct for saving relevant pruning information //
38 ////////////////////////////////////////////////////////////
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
55IPruneTool - a helper interface class to prune a decision tree
56
57Any 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 = nullptr,
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
105 };
106
108 fPruneStrength(0.0),
109 S(0),
110 B(0)
111 {}
112}
113
114#endif
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
float * q
Implementation of a Decision Tree.
IPruneTool - a helper interface class to prune a decision tree.
Definition IPruneTool.h:70
void SetAutomatic()
Definition IPruneTool.h:94
Double_t fPruneStrength
! regularization parameter in pruning
Definition IPruneTool.h:101
Double_t GetPruneStrength() const
Definition IPruneTool.h:90
void SetPruneStrength(Double_t alpha)
Definition IPruneTool.h:88
virtual PruningInfo * CalculatePruningInfo(DecisionTree *dt, const EventSample *testEvents=nullptr, Bool_t isAutomatic=kFALSE)=0
std::vector< const Event * > EventSample
Definition IPruneTool.h:74
Bool_t IsAutomatic() const
Definition IPruneTool.h:95
Double_t QualityIndex
Definition IPruneTool.h:45
std::vector< DecisionTreeNode * > PruneSequence
the regularization parameter for pruning
Definition IPruneTool.h:47
Double_t PruneStrength
quality measure for a pruned subtree T of T_max
Definition IPruneTool.h:46
create variable transformations