Changeset 1134 for trunk/yat/classifier/MatrixLookupWeighted.cc
 Timestamp:
 Feb 23, 2008, 11:52:43 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/MatrixLookupWeighted.cc
r1121 r1134 43 43 assert(data.rows()==weights.rows()); 44 44 assert(data.columns()==weights.columns()); 45 for(size_t i=0;i<(*data_).rows();i++) 46 row_index_.push_back(i); 47 for(size_t i=0;i<(*data_).columns();i++) 48 column_index_.push_back(i); 45 row_index_ = utility::Index(data.rows()); 46 column_index_ = utility::Index(data.columns()); 49 47 } 50 48 … … 57 55 weights_= new utility::Matrix(weights); 58 56 ref_count_weights_=new u_int(1); 59 for(size_t i=0;i<(*data_).rows();i++) 60 row_index_.push_back(i); 61 for(size_t i=0;i<(*data_).columns();i++) 62 column_index_.push_back(i); 57 row_index_ = utility::Index(data.rows()); 58 column_index_ = utility::Index(data.columns()); 63 59 } 64 60 … … 78 74 MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data, 79 75 const utility::Matrix& weights, 80 const std::vector<size_t>& row,81 const std::vector<size_t>& col)76 const utility::Index& row, 77 const utility::Index& col) 82 78 : DataLookup2D(row,col), data_(&data), weights_(&weights), 83 79 ref_count_weights_(NULL) 84 80 { 85 // Checking that each row index is less than data.rows()86 assert(row.empty() 87 *(std::max_element(row.begin(),row.end()))<data.rows());88 // Checking that each column index is less than data.column()89 assert(col.empty() 90 *(std::max_element(col.begin(),col.end()))<data.columns());91 // Checking that each row index is less than weights.rows()92 assert(row.empty() 93 *(std::max_element(row.begin(),row.end()))<weights.rows());94 // Checking that each column index is less than weights.column()95 assert(col.empty() 96 *(std::max_element(col.begin(),col.end()))<weights.columns());97 81 } 98 82 … … 101 85 MatrixLookupWeighted::MatrixLookupWeighted(const utility::Matrix& data, 102 86 const utility::Matrix& weights, 103 const std::vector<size_t>& index,87 const utility::Index& index, 104 88 const bool row) 105 89 : DataLookup2D(), data_(&data), weights_(&weights), 106 90 ref_count_weights_(NULL) 107 91 { 92 assert(data.rows()==weights.rows()); 93 assert(data.columns()==weights.columns()); 108 94 if (row){ 109 // Checking that each row index is less than data.rows()110 assert(index.empty() 111 *(std::max_element(index.begin(),index.end()))<data.rows());112 // Checking that each row index is less than weights.rows()113 assert(index.empty() 114 *(std::max_element(index.begin(),index.end()))<weights.rows());115 95 row_index_=index; 116 assert(column_index_.empty()); 117 column_index_.reserve(data.columns()); 118 for (size_t i=0; i<data.columns(); i++) 119 column_index_.push_back(i); 96 column_index_ = utility::Index(data.columns()); 120 97 } 121 98 else{ 122 // Checking that each column index is less than data.column()123 assert(index.empty() 124 *(std::max_element(index.begin(),index.end()))<data.columns());125 // Checking that each column index is less than weights.column()126 assert(index.empty() 127 *(std::max_element(index.begin(),index.end()))<weights.columns());128 99 column_index_=index; 129 assert(row_index_.empty()); 130 column_index_.reserve(data.rows()); 131 for (size_t i=0; i<data.rows(); i++) 132 row_index_.push_back(i); 100 row_index_ = utility::Index(data.rows()); 133 101 } 134 102 } … … 159 127 160 128 MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookupWeighted& other, 161 const std::vector<size_t>& row,162 const std::vector<size_t>& col)129 const utility::Index& row, 130 const utility::Index& col) 163 131 : DataLookup2D(other,row,col), data_(other.data_), weights_(other.weights_) 164 132 { … … 174 142 175 143 MatrixLookupWeighted::MatrixLookupWeighted(const MatrixLookupWeighted& other, 176 const std::vector<size_t>& index,144 const utility::Index& index, 177 145 bool row) 178 146 : DataLookup2D(other,index,row), data_(other.data_), … … 186 154 ++(*ref_count_weights_); 187 155 188 // Checking that no index is out of range189 assert(row_index_.empty() 190 *(max_element(row_index_.begin(), row_index_.end()))<data_>rows());191 assert(column_index_.empty() 192 *(max_element(column_index_.begin(), column_index_.end()))<193 data_>columns());194 // Checking that no index is out of range195 assert(row_index_.empty() 196 *(max_element(row_index_.begin(), row_index_.end()))<197 weights_>rows());198 assert(column_index_.empty() 199 *(max_element(column_index_.begin(), column_index_.end()))<200 weights_>columns());201 156 } 202 157 … … 221 176 data_ = new utility::Matrix(is,sep); 222 177 ref_count_=new u_int(1); 223 for(size_t i=0;i<(*data_).rows();i++) 224 row_index_.push_back(i); 225 for(size_t i=0;i<(*data_).columns();i++) 226 column_index_.push_back(i); 178 row_index_ = utility::Index(data_>rows()); 179 column_index_ = utility::Index(data_>columns()); 227 180 utility::Matrix weights; 228 181 utility::nan(*data_,weights); … … 296 249 297 250 const MatrixLookupWeighted* 298 MatrixLookupWeighted::selected(const std::vector<size_t>& i) const251 MatrixLookupWeighted::selected(const utility::Index& i) const 299 252 { 300 253 return new MatrixLookupWeighted(*this,i, true); … … 304 257 305 258 const MatrixLookupWeighted* 306 MatrixLookupWeighted::training_data(const std::vector<size_t>& i) const259 MatrixLookupWeighted::training_data(const utility::Index& i) const 307 260 { 308 261 return new MatrixLookupWeighted(*this,i, false); … … 312 265 313 266 const MatrixLookupWeighted* 314 MatrixLookupWeighted::validation_data(const std::vector<size_t>& train,315 const std::vector<size_t>& val) const267 MatrixLookupWeighted::validation_data(const utility::Index& train, 268 const utility::Index& val) const 316 269 { 317 270 return new MatrixLookupWeighted(*this,val, false);
Note: See TracChangeset
for help on using the changeset viewer.