[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
vigra/random_forest/features.hxx | ![]() |
00001 #ifndef RN_FEATURES_HXX 00002 #define RN_FEATURES_HXX 00003 00004 00005 00006 00007 00008 class FeatureBase 00009 { 00010 public: 00011 MultiArrayShape<2>::type shape() = 0; 00012 int shape(int index) 00013 { 00014 return shape()[index]; 00015 } 00016 double & operator() (int i, int j) = 0; 00017 }; 00018 00019 00020 class CompositFeatures : public FeatureBase 00021 { 00022 public: 00023 typedef typename MultiArrayShape<2>::type 00024 Shp; 00025 ArrayVector<Shp> 00026 ext2int; 00027 ArrayVector<FeatureBase > sub_feats; 00028 void add(FeatureBase & feat) 00029 { 00030 if(feat.shape(0) != this->shape(0)) 00031 throw std::runtime_error("Wrong Number Of samples"); 00032 00033 sub_feats.push_back(feat); 00034 for(int ii = 0; ii < feat.shape(1); ++ii) 00035 ext2int.push_back(Shp(sub_feats.size()-1, 00036 ii)); 00037 00038 } 00039 00040 MultiArrayShape<2>::type shape() 00041 { 00042 return MultiArrayShape<2>::type(sub_feats[0].shape(0), 00043 ext2int.size()); 00044 } 00045 00046 double & operator() (int i, int j) 00047 { 00048 return sub_feats[ext2int[j][0]](i, ext2int[j][1]); 00049 } 00050 }; 00051 00052 template<int N, class T, class C> 00053 class NeighborFeatures : public FeatureBase 00054 { 00055 public: 00056 typedef typename MultiArrayShape<N>::type Shp; 00057 MultiArrayView<N, T, C> raw_data; 00058 ArrayVector<Shp > 00059 feat_coos; 00060 MultiArrayShape<2>::type shape() 00061 { 00062 return MultiArrayShape<2>::type(raw_data.size(), 00063 feat_coos.size()); 00064 } 00065 00066 double & operator() (int i, int j) 00067 { 00068 return raw_data(raw_data.scanOrderIndexToCoordinate(i) + feat_coos(j)); 00069 } 00070 NeighborFeatures(MultiArrayView<N, T, C> & in, MultiArrayView<2, int> const & coos) 00071 : raw_data(in) 00072 { 00073 for(int ii = 0; ii < coos.shape(0); ++ii) 00074 feat_coos.push_back(Shp()); 00075 for(int jj = 0; jj < coos.shape(1); ++jj) 00076 feat_coos.back()[jj] = coos(ii, jj); 00077 } 00078 00079 }; 00080 00081 00082 class BindFeatureColumn : public FeatureBase 00083 { 00084 typedef typename MultiArrayShape<N>::type Shp; 00085 int index; 00086 FeatureBase & underlying; 00087 00088 MultiArrayShape<2>::type shape() 00089 { 00090 return MultiArrayShape<2>::type(underlying.shape(0), 1); 00091 } 00092 00093 double & operator() (int i, int j) 00094 { 00095 return underlying(i, index); 00096 } 00097 double & operator[](int i) 00098 { 00099 return underlying(i, index); 00100 } 00101 00102 BindFeatureColumn(FeaetureBase & in, int index_) 00103 : index(index_), underlying(in) 00104 { 00105 ; 00106 } 00107 }; 00108 00109 FeatureBase columnVector(FeatureBase & in, int ii) 00110 { 00111 return BindFeatureColumn(in, ii); 00112 } 00113 00114 #endif
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|