Changeset 1170
- Timestamp:
- Feb 27, 2008, 1:06:55 AM (16 years ago)
- Location:
- trunk
- Files:
-
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/matrix_lookup_test.cc
r1168 r1170 79 79 ok =false; 80 80 *error << "ERROR:" << std::endl; 81 *error << "rows: " << m2.rows() << " expected 2\n" 82 << "columns: " << m2.columns() << " expected 2\n" 83 << "(0,0): " << m2(0,0) << " expected " << gsl_m2(1,2) << "\n" 84 << "(0,1): " << m2(1,0) << " expected " << gsl_m2(1,0) << "\n" 85 << "(1,0): " << m2(0,1) << " expected " << gsl_m2(3,2) << "\n" 86 << "(0,0): " << m2(0,0) << " expected " << gsl_m2(3,0) << "\n"; 81 87 } 82 88 else -
trunk/test/subset_generator_test.cc
r1167 r1170 171 171 std::vector<size_t> t_class_count2(3,0); 172 172 for(u_long l=0;l<cv_training.size();l++) { 173 const classifier:: DataLookup2D& t_view=cv_training.training_data(l);173 const classifier::MatrixLookup& t_view=cv_training.training_data(l); 174 174 const classifier::Target& t_target=cv_training.training_target(l); 175 175 const utility::Index& t_index=cv_training.training_index(l); 176 const classifier:: DataLookup2D& v_view=cv_training.validation_data(l);176 const classifier::MatrixLookup& v_view=cv_training.validation_data(l); 177 177 const classifier::Target& v_target=cv_training.validation_target(l); 178 178 const utility::Index& v_index=cv_training.validation_index(l); -
trunk/yat/classifier/DataLookup1D.h
r1146 r1170 59 59 /// 60 60 /// @param row_vector if true DataLookup1D is looking into a 61 /// row of DataLookup2D, otherwise looking into a61 /// row of MatrixLookup, otherwise looking into a 62 62 /// column. @param index which row/column to look into. 63 63 /// … … 96 96 97 97 /// 98 /// @brief Destructor deletes underlying DataLookup2Dif object is owner98 /// @brief Destructor deletes underlying MatrixLookup if object is owner 99 99 /// 100 100 virtual ~DataLookup1D(); -
trunk/yat/classifier/InputRanker.h
r1085 r1170 36 36 namespace classifier { 37 37 38 class DataLookup2D;39 38 class MatrixLookup; 40 39 class MatrixLookupWeighted; -
trunk/yat/classifier/KernelLookup.h
r1167 r1170 298 298 this was built from. 299 299 300 @note Returns a dynamically allocated DataLookup2D, which has300 @note Returns a dynamically allocated KernelLookup, which has 301 301 to be deleted by the caller to avoid memory leaks. 302 302 */ -
trunk/yat/classifier/Makefile.am
r1112 r1170 32 32 DataLookup1D.cc \ 33 33 DataLookupWeighted1D.cc \ 34 DataLookup2D.cc \35 34 FeatureSelector.cc \ 36 35 FeatureSelectorIR.cc \ … … 63 62 CrossValidationSampler.h \ 64 63 DataLookup1D.h \ 65 DataLookup2D.h \66 64 DataLookupWeighted1D.h \ 67 65 EnsembleBuilder.h \ -
trunk/yat/classifier/MatrixLookup.cc
r1169 r1170 30 30 #include <cassert> 31 31 #include <fstream> 32 #include <vector> 32 33 33 34 namespace theplu { … … 36 37 37 38 MatrixLookup::MatrixLookup(const utility::Matrix& data, const bool own) 38 : DataLookup2D(own),data_(MatrixP(&data, own))39 : data_(MatrixP(&data, own)) 39 40 { 40 41 column_index_ = utility::Index(data.columns()); 41 42 row_index_ = utility::Index(data.rows()); 43 assert(rows()==data.rows()); 44 assert(columns()==data.columns()); 45 assert(validate()); 42 46 } 43 47 … … 47 51 const utility::Index& row, 48 52 const utility::Index& col) 49 : DataLookup2D(row,col), data_(MatrixP(&data, false)) 50 { 53 : column_index_(col), 54 data_(MatrixP(&data, false)), 55 row_index_(row) 56 57 { 58 assert(rows()==row.size()); 59 assert(columns()==col.size()); 60 assert(validate()); 51 61 } 52 62 … … 56 66 const utility::Index& index, 57 67 const bool row) 58 : DataLookup2D(),data_(MatrixP(&data, false))68 : data_(MatrixP(&data, false)) 59 69 { 60 70 if (row){ … … 66 76 row_index_ = utility::Index(data.rows()); 67 77 } 78 assert(row || rows()==data.rows()); 79 assert(row || columns()==index.size()); 80 assert(!row || rows()==index.size()); 81 assert(!row || columns()==data.columns()); 82 assert(validate()); 68 83 } 69 84 … … 71 86 72 87 MatrixLookup::MatrixLookup(const MatrixLookup& other) 73 : DataLookup2D(other), data_(other.data_) 74 { 88 : column_index_(other.column_index_), 89 data_(other.data_), 90 row_index_(other.row_index_) 91 { 92 assert(validate()); 75 93 } 76 94 … … 80 98 const utility::Index& row, 81 99 const utility::Index& col) 82 : DataLookup2D(other,row,col), data_(other.data_) 83 { 100 : column_index_(utility::Index(other.column_index_, col)), 101 data_(other.data_), row_index_(utility::Index(other.row_index_, row)) 102 { 103 assert(rows()==row.size()); 104 assert(columns()==col.size()); 105 assert(validate()); 84 106 } 85 107 … … 88 110 MatrixLookup::MatrixLookup(const MatrixLookup& other, 89 111 const utility::Index& index, bool row) 90 : DataLookup2D(other,index,row), data_(other.data_) 91 { 112 : data_(other.data_) 113 { 114 if (row){ 115 row_index_ = utility::Index(other.row_index_, index); 116 column_index_= other.column_index_; 117 } 118 else{ 119 column_index_ = utility::Index(other.column_index_, index); 120 row_index_= other.row_index_; 121 } 122 assert(validate()); 92 123 } 93 124 … … 96 127 MatrixLookup::MatrixLookup(const size_t rows, const size_t columns, 97 128 const double value) 98 : DataLookup2D(rows,columns) 99 { 100 data_ = MatrixP(new utility::Matrix(1,1,value)); 129 : data_(MatrixP(new utility::Matrix(1,1,value))) 130 { 131 column_index_ = utility::Index(std::vector<size_t>(columns, 0)); 132 row_index_ = utility::Index(std::vector<size_t>(rows,0)); 133 assert(validate()); 101 134 } 102 135 103 136 104 137 MatrixLookup::MatrixLookup(std::istream& is, char sep) 105 : DataLookup2D()106 { 107 data_ = MatrixP(new utility::Matrix(is,sep));138 : data_(MatrixP(new utility::Matrix(is,sep))) 139 { 140 column_index_ = utility::Index(data_->columns()); 108 141 row_index_ = utility::Index(data_->rows()); 109 column_index_ = utility::Index(data_->columns());142 assert(validate()); 110 143 } 111 144 … … 133 166 { 134 167 return const_row_iterator(const_row_iterator::iterator_type(*this,i,0), 1); 168 } 169 170 171 size_t MatrixLookup::columns(void) const 172 { 173 return column_index_.size(); 135 174 } 136 175 … … 157 196 158 197 198 size_t MatrixLookup::rows(void) const 199 { 200 return row_index_.size(); 201 } 202 203 204 bool MatrixLookup::validate(void) const 205 { 206 for (size_t i=0; i<row_index_.size(); ++i) 207 if (row_index_[i]>=data_->rows()) 208 return false; 209 for (size_t i=0; i<column_index_.size(); ++i) 210 if (column_index_[i]>=data_->columns()) 211 return false; 212 return true; 213 } 214 215 159 216 bool MatrixLookup::weighted(void) const 160 217 { … … 168 225 assert(row<rows()); 169 226 assert(column<columns()); 227 assert(row_index_[row]<data_->rows()); 228 assert(column_index_[column]<data_->columns()); 170 229 return (*data_)(row_index_[row], column_index_[column]); 171 230 } … … 176 235 { 177 236 if (this!=&other){ 178 DataLookup2D::operator=(other); 237 row_index_ = other.row_index_; 238 column_index_ = other.column_index_; 179 239 data_ = other.data_; 180 240 } 241 assert(validate()); 181 242 return *this; 182 243 } -
trunk/yat/classifier/MatrixLookup.h
r1169 r1170 27 27 */ 28 28 29 #include "DataLookup2D.h"30 29 #include "yat/utility/Container2DIterator.h" 31 30 #include "yat/utility/Index.h" … … 72 71 /// constructors and assignments. 73 72 /// 74 class MatrixLookup : public DataLookup2D73 class MatrixLookup 75 74 { 76 75 public: … … 257 256 258 257 /** 258 \return number of columns 259 */ 260 size_t columns(void) const; 261 262 /** 259 263 \return const_iterator pointing to end of matrix 260 264 */ … … 270 274 */ 271 275 const_row_iterator end_row(size_t) const; 276 277 /** 278 \return number of rows 279 */ 280 size_t rows(void) const; 272 281 273 282 /// … … 296 305 friend class MatrixLookupWeighted; 297 306 307 utility::Index column_index_; 298 308 typedef utility::SmartPtr<const utility::Matrix> MatrixP; 299 309 MatrixP data_; 310 utility::Index row_index_; 311 312 // for assertions 313 bool validate(void) const; 300 314 }; 301 315 302 316 /// 303 /// The output operator DataLookup2D317 /// The output operator MatrixLookup 304 318 /// 305 319 std::ostream& operator<< (std::ostream& s, const MatrixLookup&); -
trunk/yat/classifier/MatrixLookupWeighted.cc
r1169 r1170 27 27 #include "yat/utility/Matrix.h" 28 28 29 #include <algorithm>30 29 #include <cassert> 31 30 #include <fstream> 31 #include <vector> 32 32 33 33 namespace theplu { … … 44 44 row_index_ = utility::Index(data.rows()); 45 45 column_index_ = utility::Index(data.columns()); 46 assert(validate()); 46 47 } 47 48 48 49 49 50 MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data) 50 : DataLookup2D(),data_(MatrixP(&data, false))51 : data_(MatrixP(&data, false)) 51 52 { 52 53 utility::Matrix weights; … … 55 56 row_index_ = utility::Index(data.rows()); 56 57 column_index_ = utility::Index(data.columns()); 58 assert(validate()); 57 59 } 58 60 59 61 60 62 MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookup& ml) 61 : DataLookup2D(ml), data_(ml.data_) 62 { 63 weights_= MatrixP(new utility::Matrix(data_->rows(), data_->columns(),1.0)); 63 : column_index_(ml.column_index_), data_(ml.data_), 64 row_index_(ml.row_index_), 65 weights_(MatrixP(new utility::Matrix(data_->rows(),data_->columns(),1.0))) 66 { 67 assert(validate()); 64 68 } 65 69 … … 69 73 const utility::Index& row, 70 74 const utility::Index& col) 71 : DataLookup2D(row,col), data_(MatrixP(new utility::Matrix(data), false)), 72 weights_(MatrixP(new utility::Matrix(weights), false)) 73 { 75 : column_index_(col), data_(MatrixP(new utility::Matrix(data), false)), 76 row_index_(row), weights_(MatrixP(new utility::Matrix(weights), false)) 77 { 78 assert(validate()); 74 79 } 75 80 … … 80 85 const utility::Index& index, 81 86 const bool row) 82 : DataLookup2D(),data_(MatrixP(new utility::Matrix(data), false)),87 : data_(MatrixP(new utility::Matrix(data), false)), 83 88 weights_(MatrixP(new utility::Matrix(weights), false)) 84 89 { … … 93 98 row_index_ = utility::Index(data.rows()); 94 99 } 100 assert(validate()); 95 101 } 96 102 … … 106 112 107 113 MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookupWeighted& other) 108 : DataLookup2D(other), data_(other.data_), weights_(other.weights_) 109 { 114 : column_index_(other.column_index_), data_(other.data_), 115 row_index_(other.row_index_), weights_(other.weights_) 116 { 117 assert(validate()); 110 118 } 111 119 … … 115 123 const utility::Index& row, 116 124 const utility::Index& col) 117 : DataLookup2D(other,row,col), data_(other.data_), weights_(other.weights_) 118 { 125 : column_index_(utility::Index(other.column_index_, col)), 126 data_(other.data_), row_index_(utility::Index(other.row_index_, row)), 127 weights_(other.weights_) 128 { 129 assert(validate()); 119 130 } 120 131 … … 124 135 const utility::Index& index, 125 136 bool row) 126 : DataLookup2D(other,index,row),data_(other.data_),137 : data_(other.data_), 127 138 weights_(other.weights_) 128 139 { 140 if (row){ 141 row_index_ = utility::Index(other.row_index_, index); 142 column_index_= other.column_index_; 143 } 144 else{ 145 column_index_ = utility::Index(other.column_index_, index); 146 row_index_= other.row_index_; 147 } 148 assert(validate()); 129 149 } 130 150 … … 135 155 const double value, 136 156 const double weight) 137 : DataLookup2D(rows,columns),157 : column_index_(utility::Index(std::vector<size_t>(rows, 0))), 138 158 data_(MatrixP(new utility::Matrix(1,1,value))), 159 row_index_(utility::Index(std::vector<size_t>(columns, 0))), 139 160 weights_(MatrixP(new utility::Matrix(1,1,weight))) 140 161 { 162 assert(validate()); 141 163 } 142 164 143 165 144 166 MatrixLookupWeighted::MatrixLookupWeighted(std::istream& is, char sep) 145 : DataLookup2D()146 { 147 data_ = MatrixP(new utility::Matrix(is,sep));167 : data_(MatrixP(new utility::Matrix(is,sep))) 168 { 169 column_index_ = utility::Index(data_->columns()); 148 170 row_index_ = utility::Index(data_->rows()); 149 column_index_ = utility::Index(data_->columns());150 171 utility::Matrix weights; 151 172 utility::nan(*data_,weights); 152 173 // Peter, should be possible to avoid this copying 153 174 weights_= MatrixP(new utility::Matrix(weights)); 175 assert(validate()); 154 176 } 155 177 … … 183 205 184 206 207 size_t MatrixLookupWeighted::columns(void) const 208 { 209 return column_index_.size(); 210 } 211 212 185 213 double MatrixLookupWeighted::data(size_t row, size_t column) const 186 214 { 215 assert(row<rows()); 216 assert(column<columns()); 217 assert(row_index_[row]<data_->rows()); 218 assert(column_index_[column]<data_->columns()); 187 219 return (*data_)(row_index_[row], column_index_[column]); 188 220 } … … 212 244 213 245 246 size_t MatrixLookupWeighted::rows(void) const 247 { 248 return row_index_.size(); 249 } 250 251 252 bool MatrixLookupWeighted::validate(void) const 253 { 254 for (size_t i=0; i<row_index_.size(); ++i) 255 if (row_index_[i]>=data_->rows()) 256 return false; 257 for (size_t i=0; i<column_index_.size(); ++i) 258 if (column_index_[i]>=data_->columns()) 259 return false; 260 for (size_t i=0; i<row_index_.size(); ++i) 261 if (row_index_[i]>=weights_->rows()) 262 return false; 263 for (size_t i=0; i<column_index_.size(); ++i) 264 if (column_index_[i]>=weights_->columns()) 265 return false; 266 return true; 267 } 268 269 214 270 double MatrixLookupWeighted::weight(size_t row, size_t column) const 215 271 { 272 assert(row<rows()); 273 assert(column<columns()); 274 assert(row_index_[row]<weights_->rows()); 275 assert(column_index_[column]<weights_->columns()); 216 276 return (*weights_)(row_index_[row], column_index_[column]); 217 277 } … … 238 298 { 239 299 if (this!=&other){ 240 DataLookup2D::operator=(other); 300 column_index_=other.column_index_; 301 row_index_=other.row_index_; 241 302 data_ = other.data_; 242 303 weights_ = other.weights_; 243 304 } 305 assert(validate()); 244 306 return *this; 245 307 } -
trunk/yat/classifier/MatrixLookupWeighted.h
r1169 r1170 26 26 */ 27 27 28 #include "DataLookup2D.h"29 28 #include "yat/utility/Container2DIterator.h" 29 #include "yat/utility/Index.h" 30 30 #include "yat/utility/IteratorPolicy.h" 31 31 #include "yat/utility/SmartPtr.h" … … 67 67 /// constructors and assignments. 68 68 /// 69 class MatrixLookupWeighted : public DataLookup2D69 class MatrixLookupWeighted 70 70 { 71 71 … … 284 284 const_row_iterator begin_row(size_t) const; 285 285 286 /** 287 \return number of columns 288 */ 289 size_t columns(void) const; 290 286 291 /// 287 292 /// @return data value of element (@a row, @a column) … … 303 308 */ 304 309 const_row_iterator end_row(size_t) const; 310 311 /** 312 \return number of rows 313 */ 314 size_t rows(void) const; 305 315 306 316 /// … … 333 343 private: 334 344 typedef utility::SmartPtr<const utility::Matrix> MatrixP; 345 utility::Index column_index_; 335 346 MatrixP data_; 347 utility::Index row_index_; 336 348 MatrixP weights_; 349 350 // for assertions 351 bool validate(void) const; 337 352 }; 338 353 -
trunk/yat/classifier/SVM.h
r1125 r1170 74 74 /// 75 75 virtual ~SVM(); 76 77 //const DataLookup2D& data(void) const;78 76 79 77 ///
Note: See TracChangeset
for help on using the changeset viewer.