X-Boost  2.3.8
IndirectDecisionTree.h
Go to the documentation of this file.
1 /* XBoost: Ada-Boost and Friends on Haar/ICF/HOG Features, Library and ToolBox
2  *
3  * Copyright (c) 2008-2014 Paolo Medici <medici@ce.unipr.it>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20 
21 #ifndef _INDIRECT_DECISION_TREE_H
22 #define _INDIRECT_DECISION_TREE_H
23 
27 #include <iostream>
28 #include "Types.h"
29 
32 template<class DataType>
34 public:
35 
39  DataType th;
40 
42  int category;
43 
46 
47 public:
48 
49 
50  IndirectDecisionTree() : left(0), right(0) { }
51 
52  IndirectDecisionTree(const IndirectDecisionTree<DataType> & src) : left(0), right(0)
53  {
54  classifier = src.classifier;
55  th = src.th;
56  category = src.category;
57 
58  if(src.left)
60  if(src.right)
61  right = new IndirectDecisionTree<DataType>(*src.right);
62  }
63 
64  static std::string signature() {
65  return "x-decision-tree";
66  }
67 
68  void operator=(const IndirectDecisionTree<DataType> & src)
69  {
70  delete left;
71  delete right;
72 
73  classifier = src.classifier;
74  th = src.th;
75  category = src.category;
76 
77  if(src.left)
79  else
80  left = 0;
81  if(src.right)
82  right = new IndirectDecisionTree<DataType>(*src.right);
83  else
84  right = 0;
85  }
86 
87  void print(int depth)
88  {
89  for(int i =0; i<depth; ++i) std::cout << "| ";
90  if(left!=0)
91  {
92  std::cout << "* f[" << classifier <<"] > " << th << "?\n";
93  right->print(depth+1);
94  left->print(depth+1);
95  }
96  else
97  std::cout << "# " << category << std::endl;
98  }
99 
101  int classify(const DataType *features, long stride) const {
102  if(left!=0)
103  {
104  return ( features[classifier * stride] > th ) ? right->classify(features, stride) : left->classify(features, stride);
105  }
106 
107  return category;
108  }
109 
111  inline int operator()(const DataType *features, long stride) const {
112  return classify(features, stride);
113  }
114 
115 
117  delete left;
118  delete right;
119  }
120 
121 };
122 
123 
124 #endif
Types involved in boosting.
IndirectDecisionTree< DataType > * left
sub-nodes (if null is a leaf)
Definition: IndirectDecisionTree.h:45
int category
if not a node, a category
Definition: IndirectDecisionTree.h:42
int classifier
index to a Binary Classifier
Definition: IndirectDecisionTree.h:37
int classify(const DataType *features, long stride) const
execute classification using the DecisionTree
Definition: IndirectDecisionTree.h:101
DataType th
Classifier Threshold.
Definition: IndirectDecisionTree.h:39
Definition: IndirectDecisionTree.h:33