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

rf_online_prediction_set.hxx
1 #include "../multi_array.hxx"
2 #include <set>
3 #include <vector>
4 
5 namespace vigra
6 {
7 
8 template<class T>
9 struct SampleRange
10 {
11  SampleRange(int start,int end,int num_features)
12  {
13  this->start=start;
14  this->end=end;
15  this->min_boundaries.resize(num_features,-FLT_MAX);
16  this->max_boundaries.resize(num_features,FLT_MAX);
17  }
18  int start;
19  mutable int end;
20  mutable std::vector<T> max_boundaries;
21  mutable std::vector<T> min_boundaries;
22  bool operator<(const SampleRange& o) const
23  {
24  return o.start<start;
25  }
26 };
27 
28 template<class T>
29 class OnlinePredictionSet
30 {
31 public:
32  template<class U>
33  OnlinePredictionSet(MultiArrayView<2,T,U>& features,int num_sets)
34  {
35  this->features=features;
36  std::vector<int> init(features.shape(0));
37  for(unsigned int i=0;i<init.size();++i)
38  init[i]=i;
39  indices.resize(num_sets,init);
40  std::set<SampleRange<T> > set_init;
41  set_init.insert(SampleRange<T>(0,init.size(),features.shape(1)));
42  ranges.resize(num_sets,set_init);
43  cumulativePredTime.resize(num_sets,0);
44  }
45  int get_worsed_tree()
46  {
47  int result=0;
48  for(unsigned int i=0;i<cumulativePredTime.size();++i)
49  {
50  if(cumulativePredTime[i]>cumulativePredTime[result])
51  {
52  result=i;
53  }
54  }
55  return result;
56  }
57  void reset_tree(int index)
58  {
59  index=index % ranges.size();
60  std::set<SampleRange<T> > set_init;
61  set_init.insert(SampleRange<T>(0,features.shape(0),features.shape(1)));
62  ranges[index]=set_init;
63  cumulativePredTime[index]=0;
64  }
65  std::vector<std::set<SampleRange<T> > > ranges;
66  std::vector<std::vector<int> > indices;
67  std::vector<int> cumulativePredTime;
68  MultiArray<2,T> features;
69 };
70 
71 }
72 

© 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.7.1 (Wed Mar 12 2014)