[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

rf_region.hxx VIGRA

1 /************************************************************************/
2 /* */
3 /* Copyright 2008-2009 by Ullrich Koethe and Rahul Nair */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35 #ifndef VIGRA_RANDOM_FOREST_REGION_HXX
36 #define VIGRA_RANDOM_FOREST_REGION_HXX
37 #include <algorithm>
38 #include <map>
39 #include <numeric>
40 #include "vigra/mathutil.hxx"
41 #include "vigra/array_vector.hxx"
42 #include "vigra/sized_int.hxx"
43 #include "vigra/matrix.hxx"
44 #include "vigra/random.hxx"
45 #include "vigra/functorexpression.hxx"
46 
47 
48 
49 namespace vigra
50 {
51 
52 
53 /** Standard Stackentry used to Build a Tree. Contains Information
54  * About the current region being split
55  */
56 template <class Iter>
58 {
59  public:
60  typedef Iter IndexIterator;
61  // tree specific stuff
62  enum ParentTag
63  {
64  DecisionTreeNoParent = -1
65  };
66 
67  /** Address of left and Right parent in the topology container
68  */
70  Int32 rightParent;
71  /** rule associated with current node
72  */
74 
75 
76  // RegionSpecificStuff
77  ArrayVector<double> classCounts_;
78  ArrayVector<double> weightedClassCounts_;
79  bool classCountsIsValid;
80  bool weightedClassCountsIsValid;
81  IndexIterator begin_, end_;
82  int size_;
83  IndexIterator oob_begin_, oob_end_;
84  int oob_size_;
85 
86  Int32 depth()
87  {
88  return rule.size();
89  }
90 
91  void setRange(IndexIterator s, IndexIterator e)
92  {
93  begin_ = s;
94  end_ = e;
95  size_ = e-s;
96  }
97  void set_oob_range(IndexIterator s, IndexIterator e)
98  {
99  oob_begin_ = s;
100  oob_end_ = e;
101  oob_size_ = e-s;
102  }
103 
104  void reset()
105  {
106  begin_ = end_ = IndexIterator();
107  oob_begin_ = oob_end_ = IndexIterator();
108  size_ = oob_size_ = 0;
109  leftParent = DecisionTreeNoParent;
110  rightParent = DecisionTreeNoParent;
111  classCountsIsValid = false;
112  }
113 
114  bool isPure()
115  {
116  int num = 0;
117 
118  for(int ii = 0; ii < static_cast<int>(classCounts().size()); ++ii)
119  {
120  num += classCounts()[ii] > 0;
121  }
122  return num <= 1;
123  }
124 
125  int& operator[](int i)
126  {
127  return *(begin_+i);
128  }
129 
130  IndexIterator & begin()
131  {
132  return begin_;
133  }
134 
135  IndexIterator & end()
136  {
137  return end_;
138  }
139  IndexIterator & oob_begin()
140  {
141  return oob_begin_;
142  }
143 
144  IndexIterator & oob_end()
145  {
146  return oob_end_;
147  }
148  ArrayVector<double> & classCounts()
149  {
150  return classCounts_;
151  }
152  ArrayVector<double> & weightedClassCounts()
153  {
154  return classCounts_;
155  }
156  bool classCountsValid(bool u)
157  {
158  classCountsIsValid = u;
159  return classCountsIsValid;
160 
161  }
162 
163  void classCounts(ArrayVector<Int32> in);
164 
165  DT_StackEntry( IndexIterator i, IndexIterator e,
166  int classCount,
167  Int32 lp = DecisionTreeNoParent,
168  Int32 rp = DecisionTreeNoParent)
169  :
170  leftParent(lp),
171  rightParent(rp),
172  classCounts_(classCount, 0u),
173  classCountsIsValid(false),
174  begin_(i),
175  end_(e),
176  size_(e-i)
177  {}
178 
179 
180  Int32 size()const
181  {
182  return size_;
183  }
184 
185 
186  Int32 oob_size()const
187  {
188  return oob_size_;
189  }
190 
191 };
192 
193 
194 }
195 //namespace vigra
196 
197 #endif // VIGRA_RANDOM_FOREST_REGION_HXX
Definition: rf_region.hxx:57
Int32 leftParent
Definition: rf_region.hxx:69
Definition: array_vector.hxx:58
detail::SelectIntegerType< 32, detail::SignedIntTypes >::type Int32
32-bit signed int
Definition: sized_int.hxx:175
size_type size() const
Definition: array_vector.hxx:358
ArrayVector< std::pair< Int32, double > > rule
Definition: rf_region.hxx:73

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1 (Fri May 19 2017)