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

rf_online_prediction_set.hxx VIGRA

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 
19  int start;
20  mutable int end;
21  mutable std::vector<T> max_boundaries;
22  mutable std::vector<T> min_boundaries;
23 
24  bool operator<(const SampleRange& o) const
25  {
26  return o.start<start;
27  }
28 };
29 
30 template<class T>
31 class OnlinePredictionSet
32 {
33 public:
34  template<class U>
35  OnlinePredictionSet(MultiArrayView<2,T,U>& features,int num_sets)
36  {
37  this->features=features;
38  std::vector<int> init(features.shape(0));
39  for(unsigned int i=0;i<init.size();++i)
40  init[i]=i;
41  indices.resize(num_sets,init);
42  std::set<SampleRange<T> > set_init;
43  set_init.insert(SampleRange<T>(0,init.size(),features.shape(1)));
44  ranges.resize(num_sets,set_init);
45  cumulativePredTime.resize(num_sets,0);
46  }
47 
48  int get_worsed_tree()
49  {
50  int result=0;
51  for(unsigned int i=0;i<cumulativePredTime.size();++i)
52  {
53  if(cumulativePredTime[i]>cumulativePredTime[result])
54  {
55  result=i;
56  }
57  }
58  return result;
59  }
60 
61  void reset_tree(int index)
62  {
63  index=index % ranges.size();
64  std::set<SampleRange<T> > set_init;
65  set_init.insert(SampleRange<T>(0,features.shape(0),features.shape(1)));
66  ranges[index]=set_init;
67  cumulativePredTime[index]=0;
68  }
69 
70  std::vector<std::set<SampleRange<T> > > ranges;
71  std::vector<std::vector<int> > indices;
72  std::vector<int> cumulativePredTime;
73  MultiArray<2,T> features;
74 };
75 
76 }
77 
bool operator<(FixedPoint< IntBits1, FracBits1 > l, FixedPoint< IntBits2, FracBits2 > r)
less than
Definition: fixedpoint.hxx:512

© 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)