Changeset 1088
- Timestamp:
- Feb 14, 2008, 3:26:19 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/iterator_test.cc
r1062 r1088 79 79 classifier::MatrixLookupWeighted mw(m,w); 80 80 classifier::DataLookupWeighted1D aw(mw,0,true); 81 size_t nof1=std::count(aw.begin(),aw.end(),1.0); 81 size_t nof1=std::count(aw.begin(),aw.end(), 82 std::pair<double, double>(1.0, 1.0)); 82 83 if(nof1!=2) { 83 84 *message << "std algoritm with IteratorWeighted failed" << std::endl; -
trunk/yat/classifier/DataLookup2D.cc
r1000 r1088 123 123 124 124 125 double DataLookup2D::data(size_t i, size_t j) const 126 { 127 return (*this)(i,j); 128 } 129 130 125 131 size_t DataLookup2D::rows(void) const 126 132 { 127 133 return row_index_.size(); 134 } 135 136 137 double DataLookup2D::weight(size_t i, size_t j) const 138 { 139 return 1.0; 128 140 } 129 141 -
trunk/yat/classifier/DataLookup2D.h
r1000 r1088 110 110 size_t columns(void) const; 111 111 112 113 /** 114 \return data 115 */ 116 virtual double data(size_t i, size_t j) const; 117 112 118 /// 113 119 /// @return number of rows … … 139 145 const std::vector<size_t>& val) const=0; 140 146 147 /** 148 \return data 149 */ 150 virtual double weight(size_t i, size_t j) const; 151 141 152 /// 142 153 /// Is lookup weighted? -
trunk/yat/classifier/DataLookupWeighted1D.cc
r1000 r1088 69 69 DataLookupWeighted1D::const_iterator DataLookupWeighted1D::begin(void) const 70 70 { 71 return DataLookupWeighted1D::const_iterator(*this, 0); 71 if (column_vector_) 72 return const_iterator(const_iterator::iterator_type(*matrix_, 0, index_), 73 matrix_->columns()); 74 return const_iterator(const_iterator::iterator_type(*matrix_, index_, 0),1); 72 75 } 73 76 … … 81 84 DataLookupWeighted1D::const_iterator DataLookupWeighted1D::end(void) const 82 85 { 83 return DataLookupWeighted1D::const_iterator(*this, size()); 86 if (column_vector_) 87 return const_iterator(const_iterator::iterator_type(*matrix_, 88 matrix_->rows(), 89 index_), 90 matrix_->columns()); 91 return const_iterator(const_iterator::iterator_type(*matrix_,index_+1,0),1); 84 92 } 85 93 -
trunk/yat/classifier/DataLookupWeighted1D.h
r1000 r1088 26 26 */ 27 27 28 #include "yat/utility/IteratorWeighted.h" 28 #include "DataLookup2D.h" 29 #include "yat/utility/Iterator.h" 30 #include "yat/utility/IteratorPolicy.h" 31 #include "yat/utility/StrideIterator.h" 29 32 30 33 #include <iostream> 34 #include <utility> 31 35 #include <vector> 32 36 … … 46 50 47 51 public: 48 49 /// 'Read Only' Iterator 50 typedef utility::IteratorWeighted<const double, const classifier::DataLookupWeighted1D> 52 /// 'Read Only' iterator 53 typedef utility::StrideIterator< 54 utility::Iterator<const DataLookup2D, const std::pair<double, double>, 55 void, const std::pair<double, double>, 56 utility::IteratorPolicyWeighted<const DataLookup2D, 57 const double, 58 const double> > > 51 59 const_iterator; 52 60 -
trunk/yat/classifier/EnsembleBuilder.h
r1087 r1088 27 27 */ 28 28 29 #include "FeatureSelector.h" ;29 #include "FeatureSelector.h" 30 30 #include "Sampler.h" 31 31 #include "SubsetGenerator.h" -
trunk/yat/statistics/AveragerPairWeighted.h
r1043 r1088 149 149 { 150 150 for ( ; first1 != last1; ++first1, ++first2) { 151 ap.add(utility::iterator_traits _data(first1),152 utility::iterator_traits _data(first2),153 utility::iterator_traits _weight(first1),154 utility::iterator_traits _weight(first2));151 ap.add(utility::iterator_traits<Iter1>().data(first1), 152 utility::iterator_traits<Iter2>().data(first2), 153 utility::iterator_traits<Iter1>().weight(first1), 154 utility::iterator_traits<Iter2>().weight(first2)); 155 155 } 156 156 } -
trunk/yat/statistics/AveragerWeighted.h
r1043 r1088 218 218 { 219 219 for ( ; first != last; ++first) 220 a.add(utility::iterator_traits _data(first),221 utility::iterator_traits _weight(first));220 a.add(utility::iterator_traits<Iter>().data(first), 221 utility::iterator_traits<Iter>().weight(first)); 222 222 } 223 223 -
trunk/yat/utility/Iterator.h
r1083 r1088 261 261 //Iterator& operator=(const Iterator&); 262 262 }; 263 264 /** 265 Whether Iterator is weighted is desiced by Policy. 266 */ 267 template<typename A, typename B, typename C, typename D, typename Policy> 268 struct weighted_iterator_traits<Iterator<A, B, C, D, Policy> > { 269 typedef typename Policy::weighted_iterator_type type; 270 }; 271 272 template<typename A, typename B, typename C, typename D, typename E> 273 struct iterator_traits<Iterator<A, B, C, D, E> > { 274 /** 275 \return data 276 */ 277 double data(Iterator<A, B, C, D, E> iter) const 278 { return iter.data(); } 279 280 /** 281 \return weight 282 */ 283 double weight(Iterator<A, B, C, D, E> iter) const 284 { return iter.weight(); } 285 286 }; 287 288 263 289 }}} // of namespace utility, yat, and theplu 264 290 -
trunk/yat/utility/Makefile.am
r1081 r1088 37 37 Alignment.h ColumnStream.h CommandLine.h \ 38 38 Exception.h FileUtil.h Iterator.h IteratorPolicy.h iterator_traits.h \ 39 IteratorWeighted.hkNNI.h matrix.h NNI.h \39 kNNI.h matrix.h NNI.h \ 40 40 Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \ 41 41 OptionHelp.h OptionSwitch.h \ -
trunk/yat/utility/StrideIterator.h
r1066 r1088 44 44 struct weighted_iterator_traits<StrideIterator<Iter> > { 45 45 typedef typename weighted_iterator_traits<Iter>::type type; 46 }; 47 48 template <class Iter> 49 struct iterator_traits<StrideIterator<Iter> > { 50 /** 51 \return data that is *iter 52 */ 53 double data(StrideIterator<Iter> iter) const 54 { iterator_traits<Iter> jojo; 55 return jojo.data(iter.base()); } 56 57 /** 58 \return 1.0 59 */ 60 double weight(StrideIterator<Iter> iter) const 61 { return iterator_traits<Iter>().weight(iter.base()); } 62 46 63 }; 47 64 -
trunk/yat/utility/iterator_traits.h
r1041 r1088 120 120 121 121 /** 122 Function to be used to make compile-time decision how to return 123 data from an iterator separating two cases: weighted and 124 unweighted. 122 \brief traits to make unweighted iterator work in as a weighted 125 123 126 In this way unweighted iterators can be used in a weighted context. 124 This class must be implemented for every iterator that can be weighted. 125 126 \see StrideIterator and Iterator 127 127 */ 128 // Peter, perhaps these should be templatized, but for now return129 // type double is hard coded.130 128 template <class Iter> 131 double iterator_traits_data(Iter iter) 132 { return iterator_traits_data(iter, typename 133 weighted_iterator_traits<Iter>::type()); } 129 struct iterator_traits { 130 // Peter, perhaps these should be templatized, but for now return 131 // type double is hard coded. 132 /** 133 \return data that is *iter 134 */ 135 double data(Iter iter) const 136 { check_iterator_is_unweighted(iter); return *iter; } 134 137 135 /** 136 \return data for weighted iterator 137 */ 138 template <class Iter> 139 double iterator_traits_data(Iter i, weighted_type) 140 { return i.data(); } 138 /** 139 \return 1.0 140 */ 141 double weight(Iter iter) const 142 { check_iterator_is_unweighted(iter); return 1.0; } 141 143 142 /** 143 \return data for unweighted data 144 */ 145 template <class Iter> 146 double iterator_traits_data(Iter i, unweighted_type) 147 { return *i; } 148 149 /** 150 Function to be used to make compile-time decision how to return 151 data from an iterator separating two cases: weighted and 152 unweighted. 153 154 In this way unweighted iterators can be used in a weighted context 155 and weight will be set to unity. 156 */ 157 // Peter, perhaps these should be templatized, but for now return 158 // type double is hard coded. 159 template <class Iter> 160 double iterator_traits_weight(Iter iter) 161 { return iterator_traits_weight(iter, typename 162 weighted_iterator_traits<Iter>::type()); } 163 164 /** 165 \return weight for weighted iterator 166 */ 167 template <class Iter> 168 double iterator_traits_weight(Iter i, weighted_type) 169 { return i.weight(); } 170 171 /** 172 \return weight for unweighted iterator 173 */ 174 template <class Iter> 175 double iterator_traits_weight(Iter i, unweighted_type) 176 { return 1.0; } 177 144 }; 178 145 179 146 }}} // of namespace utility, yat, and theplu
Note: See TracChangeset
for help on using the changeset viewer.