Logo ROOT  
Reference Guide
BinaryTree.h
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Kai Voss, Eckhard von Toerne
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : BinaryTree *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * BinaryTree: A base class for BinarySearch- or Decision-Trees *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
16  * Kai Voss <Kai.Voss@cern.ch> - U. of Victoria, Canada *
17  * Eckhard v. Toerne <evt@uni-bonn.de> - U of Bonn, Germany *
18  * *
19  * Copyright (c) 2005-2011: *
20  * CERN, Switzerland *
21  * U. of Victoria, Canada *
22  * MPI-K Heidelberg, Germany *
23  * U. of Bonn, Germany *
24  * *
25  * Redistribution and use in source and binary forms, with or without *
26  * modification, are permitted according to the terms listed in LICENSE *
27  * (http://tmva.sourceforge.net/LICENSE) *
28  **********************************************************************************/
29 
30 #ifndef ROOT_TMVA_BinaryTree
31 #define ROOT_TMVA_BinaryTree
32 
33 #include "TMVA/Version.h"
34 
35 //////////////////////////////////////////////////////////////////////////
36 // //
37 // BinaryTree //
38 // //
39 // Base class for BinarySearch and Decision Trees //
40 // //
41 //////////////////////////////////////////////////////////////////////////
42 
43 #include <iosfwd>
44 #include "TROOT.h"
45 
46 #include "TMVA/Node.h"
47 
48 // -----------------------------------------------------------------------------
49 
50 // the actual tree class
51 // Handles allocation, deallocation, and sorting of nodes.
52 // the Tree consists of a "root-node" wich might have 0 to 2 daughther nodes
53 
54 namespace TMVA {
55 
56  class BinaryTree;
57  class MsgLogger;
58 
59  std::ostream& operator<< ( std::ostream& os, const BinaryTree& tree );
60  std::istream& operator>> ( std::istream& istr, BinaryTree& tree );
61 
62  class BinaryTree {
63 
64  friend std::ostream& operator<< ( std::ostream& os, const BinaryTree& tree );
65  friend std::istream& operator>> ( std::istream& istr, BinaryTree& tree );
66 
67  public:
68 
69  // or a tree with Root node "n", any daughters of this node are automatically in the tree
70  BinaryTree( void );
71 
72  virtual ~BinaryTree();
73 
74  virtual Node* CreateNode(UInt_t size=0) const = 0;
75  virtual BinaryTree* CreateTree() const = 0;
76  // virtual BinaryTree* CreateFromXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE) = 0;
77  virtual const char* ClassName() const = 0;
78 
79  // set the root node of the tree
80  void SetRoot( Node* r ) { fRoot = r; }
81 
82  // Retrieves the address of the root node
83  virtual Node* GetRoot() const { return fRoot; }
84 
85  // get number of Nodes in the Tree as counted while booking the nodes;
86  UInt_t GetNNodes() const { return fNNodes; }
87 
88  // count the number of Nodes in the Tree by looping through the tree and updates
89  // the stored number. (e.g. useful when pruning, as the number count is updated when
90  // building the tree.
91  UInt_t CountNodes( Node* n = NULL );
92 
93  UInt_t GetTotalTreeDepth() const { return fDepth; }
94 
95  void SetTotalTreeDepth( Int_t depth ) { fDepth = depth; }
96  void SetTotalTreeDepth( Node* n = NULL );
97 
98  Node* GetLeftDaughter ( Node* n);
100 
101  virtual void Print( std::ostream& os ) const;
102  virtual void Read ( std::istream& istr, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
103  virtual void* AddXMLTo(void* parent) const;
104  virtual void ReadXML(void* node, UInt_t tmva_Version_Code = TMVA_VERSION_CODE );
105 
106  private:
107 
108 
109  protected:
110  Node* fRoot; //the root node of the tree
111  // the tree only has it's root node, the "daughters" are taken car
112  // of by the "node" properties of the "root"
113 
114  // delete a node (and the corresponding event if owned by the tree)
115  void DeleteNode( Node* );
116 
117  UInt_t fNNodes; // total number of nodes in the tree (counted)
118  UInt_t fDepth; // maximal depth in tree reached
119 
120  MsgLogger& Log() const;
121 
122  ClassDef(BinaryTree,0); // Base class for BinarySearch and Decision Trees
123  };
124 
125 } // namespace TMVA
126 
127 #endif
128 
n
const Int_t n
Definition: legend1.C:16
TMVA::BinaryTree::fDepth
UInt_t fDepth
Definition: BinaryTree.h:118
TMVA::BinaryTree::DeleteNode
void DeleteNode(Node *)
protected, recursive, function used by the class destructor and when Pruning
Definition: BinaryTree.cxx:74
TMVA::BinaryTree::GetLeftDaughter
Node * GetLeftDaughter(Node *n)
get left daughter node current node "n"
Definition: BinaryTree.cxx:87
tree
Definition: tree.py:1
r
ROOT::R::TRInterface & r
Definition: Object.C:4
TMVA::BinaryTree::SetTotalTreeDepth
void SetTotalTreeDepth(Int_t depth)
Definition: BinaryTree.h:95
TMVA::operator<<
std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
TMVA::BinaryTree::CreateNode
virtual Node * CreateNode(UInt_t size=0) const =0
TMVA::BinaryTree::operator<<
friend std::ostream & operator<<(std::ostream &os, const BinaryTree &tree)
TMVA::BinaryTree::fRoot
Node * fRoot
Definition: BinaryTree.h:110
TMVA::operator>>
std::istream & operator>>(std::istream &istr, BinaryTree &tree)
TMVA::Node
Node for the BinarySearch or Decision Trees.
Definition: Node.h:58
Version.h
TROOT.h
TMVA::BinaryTree::GetRightDaughter
Node * GetRightDaughter(Node *n)
get right daughter node current node "n"
Definition: BinaryTree.cxx:95
TMVA::BinaryTree::SetRoot
void SetRoot(Node *r)
Definition: BinaryTree.h:80
TMVA::BinaryTree::~BinaryTree
virtual ~BinaryTree()
destructor (deletes the nodes and "events" if owned by the tree
Definition: BinaryTree.cxx:65
Node.h
TMVA::BinaryTree
Base class for BinarySearch and Decision Trees.
Definition: BinaryTree.h:62
TMVA::BinaryTree::Log
MsgLogger & Log() const
Definition: BinaryTree.cxx:235
TMVA::BinaryTree::operator>>
friend std::istream & operator>>(std::istream &istr, BinaryTree &tree)
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TMVA::BinaryTree::CountNodes
UInt_t CountNodes(Node *n=NULL)
return the number of nodes in the tree. (make a new count --> takes time)
Definition: BinaryTree.cxx:103
TMVA::BinaryTree::Print
virtual void Print(std::ostream &os) const
recursively print the tree
Definition: BinaryTree.cxx:125
unsigned int
TMVA::BinaryTree::ReadXML
virtual void ReadXML(void *node, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
read attributes from XML
Definition: BinaryTree.cxx:144
TMVA::MsgLogger
ostringstream derivative to redirect and format output
Definition: MsgLogger.h:59
TMVA_VERSION_CODE
#define TMVA_VERSION_CODE
Definition: Version.h:47
TMVA::BinaryTree::ClassName
virtual const char * ClassName() const =0
TMVA::BinaryTree::BinaryTree
BinaryTree(void)
constructor for a yet "empty" tree. Needs to be filled afterwards
Definition: BinaryTree.cxx:55
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TMVA::BinaryTree::GetNNodes
UInt_t GetNNodes() const
Definition: BinaryTree.h:86
TMVA::BinaryTree::GetRoot
virtual Node * GetRoot() const
Definition: BinaryTree.h:83
TMVA::BinaryTree::Read
virtual void Read(std::istream &istr, UInt_t tmva_Version_Code=TMVA_VERSION_CODE)
Read the binary tree from an input stream.
Definition: BinaryTree.cxx:169
TMVA::BinaryTree::GetTotalTreeDepth
UInt_t GetTotalTreeDepth() const
Definition: BinaryTree.h:93
TMVA::BinaryTree::AddXMLTo
virtual void * AddXMLTo(void *parent) const
add attributes to XML
Definition: BinaryTree.cxx:134
TMVA::BinaryTree::fNNodes
UInt_t fNNodes
Definition: BinaryTree.h:117
TMVA
create variable transformations
Definition: GeneticMinimizer.h:22
TMVA::BinaryTree::CreateTree
virtual BinaryTree * CreateTree() const =0
int