Changeset 1134 for trunk/yat/classifier
- Timestamp:
- Feb 23, 2008, 11:52:43 PM (16 years ago)
- Location:
- trunk/yat/classifier
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/classifier/BootstrapSampler.cc
r1000 r1134 27 27 28 28 #include <cassert> 29 30 //#include <algorithm>31 //#include <utility>32 //#include <vector>33 29 34 30 namespace theplu { … … 75 71 } 76 72 } 77 training_index_.push_back(training_index); 78 training_target_.push_back(Target(target,training_index)); 79 validation_index_.push_back(validation_index); 80 validation_target_.push_back(Target(target,validation_index)); 73 training_index_.push_back(utility::Index(training_index)); 74 training_target_.push_back(Target(target,utility::Index(training_index))); 75 validation_index_.push_back(utility::Index(validation_index)); 76 validation_target_.push_back(Target(target, 77 utility::Index(validation_index))); 81 78 } 82 79 -
trunk/yat/classifier/CrossValidationSampler.cc
r1004 r1134 81 81 } 82 82 83 training_index_.push_back( training_index);84 validation_index_.push_back( validation_index);83 training_index_.push_back(utility::Index(training_index)); 84 validation_index_.push_back(utility::Index(validation_index)); 85 85 } 86 86 } -
trunk/yat/classifier/DataLookup2D.cc
r1088 r1134 46 46 47 47 DataLookup2D::DataLookup2D(const DataLookup2D& m, 48 const std::vector<size_t>& row,49 const std::vector<size_t>& col)48 const utility::Index& row, 49 const utility::Index& col) 50 50 : ref_count_(NULL) 51 51 { 52 assert(row_index_.empty()); 53 row_index_.reserve(row.size()); 54 for (size_t i=0; i<row.size(); i++) { 55 assert(row[i]<m.row_index_.size()); 56 row_index_.push_back(m.row_index_[row[i]]); 57 } 58 assert(column_index_.empty()); 59 column_index_.reserve(col.size()); 60 for (size_t i=0; i<col.size(); i++) { 61 assert(col[i]<m.column_index_.size()); 62 column_index_.push_back(m.column_index_[col[i]]); 63 } 52 row_index_ = utility::Index(m.row_index_, row); 53 column_index_ = utility::Index(m.column_index_, col); 64 54 } 65 55 … … 67 57 68 58 DataLookup2D::DataLookup2D(const DataLookup2D& m, 69 const std::vector<size_t>& index,59 const utility::Index& index, 70 60 const bool row) 71 61 : ref_count_(NULL) 72 62 { 73 63 if (row){ 74 assert(row_index_.empty()); 75 row_index_.reserve(index.size()); 76 for (size_t i=0; i<index.size(); i++) { 77 assert(index[i]<m.row_index_.size()); 78 row_index_.push_back(m.row_index_[index[i]]); 79 } 64 row_index_ = utility::Index(m.row_index_, index); 80 65 column_index_= m.column_index_; 81 66 } 82 67 else{ 83 assert(column_index_.empty()); 84 column_index_.reserve(index.size()); 85 for (size_t i=0; i<index.size(); i++) { 86 column_index_.push_back(m.column_index_[index[i]]); 87 } 68 column_index_ = utility::Index(m.column_index_, index); 88 69 row_index_= m.row_index_; 89 70 } … … 91 72 92 73 93 DataLookup2D::DataLookup2D(const std::vector<size_t>& row,94 const std::vector<size_t>& col,74 DataLookup2D::DataLookup2D(const utility::Index& row, 75 const utility::Index& col, 95 76 const bool own) 96 77 : row_index_(row),column_index_(col), ref_count_(NULL) -
trunk/yat/classifier/DataLookup2D.h
r1125 r1134 26 26 02111-1307, USA. 27 27 */ 28 29 #include "yat/utility/Index.h" 28 30 29 31 #include <vector> … … 69 71 /// vector as input. 70 72 /// 71 DataLookup2D(const std::vector<size_t>& row,72 const std::vector<size_t>& column,73 DataLookup2D(const utility::Index& row, 74 const utility::Index& column, 73 75 const bool own=false); 74 76 … … 82 84 /// Copy the index such that new(i,j) = old(row[i],col[j]) 83 85 /// 84 DataLookup2D(const DataLookup2D&, const std::vector<size_t>& row,85 const std::vector<size_t>& col);86 DataLookup2D(const DataLookup2D&, const utility::Index& row, 87 const utility::Index& col); 86 88 87 89 /// … … 89 91 /// Else indices are copied so new(i,j)=old(i,index[j]) 90 92 /// 91 DataLookup2D(const DataLookup2D&, const std::vector<size_t>& index,93 DataLookup2D(const DataLookup2D&, const utility::Index& index, 92 94 const bool row); 93 95 … … 124 126 /// @return Data based on selected features. 125 127 /// 126 virtual const DataLookup2D* selected(const std::vector< size_t >&) const=0;128 virtual const DataLookup2D* selected(const utility::Index&) const=0; 127 129 128 130 /// … … 133 135 /// 134 136 virtual const DataLookup2D* 135 training_data(const std::vector<size_t>&) const=0;137 training_data(const utility::Index&) const=0; 136 138 137 139 /// … … 142 144 /// 143 145 virtual const DataLookup2D* 144 validation_data(const std::vector<size_t>& train,145 const std::vector<size_t>& val) const=0;146 validation_data(const utility::Index& train, 147 const utility::Index& val) const=0; 146 148 147 149 /** … … 171 173 /// @brief which rows to look into 172 174 /// 173 std::vector<size_t>row_index_;175 utility::Index row_index_; 174 176 175 177 /// 176 178 /// @brief which columns to look into 177 179 /// 178 std::vector<size_t>column_index_;180 utility::Index column_index_; 179 181 180 182 /// -
trunk/yat/classifier/FeatureSelector.cc
r1000 r1134 50 50 51 51 52 const std::vector<size_t>FeatureSelector::features(void) const52 const utility::Index FeatureSelector::features(void) const 53 53 { 54 54 return features_; … … 58 58 const MatrixLookup& FeatureSelector::get(const MatrixLookup& matrix) 59 59 { 60 garbage_.push_back(new MatrixLookup(matrix, features_,true));60 garbage_.push_back(new MatrixLookup(matrix,utility::Index(features_),true)); 61 61 return *garbage_.back(); 62 62 } … … 66 66 FeatureSelector::get(const MatrixLookupWeighted& matrix) 67 67 { 68 garbage_weighted_.push_back(new MatrixLookupWeighted(matrix,features_, 68 garbage_weighted_.push_back(new MatrixLookupWeighted(matrix, 69 utility::Index(features_), 69 70 true)); 70 71 return *garbage_weighted_.back(); -
trunk/yat/classifier/FeatureSelector.h
r1000 r1134 25 25 */ 26 26 27 #include "yat/utility/Index.h" 28 27 29 #include <list> 28 #include <vector>29 30 30 31 namespace theplu { … … 64 65 65 66 /// 66 /// @return vector ofindices corresponding to selected features.67 /// @return indices corresponding to selected features. 67 68 /// 68 const std::vector<size_t>features(void) const;69 const utility::Index features(void) const; 69 70 70 71 /// … … 83 84 /// @brief features 84 85 /// 85 std::vector<size_t>features_;86 utility::Index features_; 86 87 87 88 /// -
trunk/yat/classifier/FeatureSelectorIR.cc
r1000 r1134 64 64 assert(data.columns()==target.size()); 65 65 InputRanker ir = InputRanker(data, target, score_); 66 features_.resize(N_);66 std::vector<size_t>* features = new std::vector<size_t>(N_); 67 67 std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_, 68 features_.begin()); 68 features->begin()); 69 features_ = 70 utility::Index(utility::SmartPtr<const std::vector<size_t> >(features)); 69 71 } 70 72 … … 75 77 assert(data.columns()==target.size()); 76 78 InputRanker ir = InputRanker(data, target, score_); 77 features_.resize(N_);79 std::vector<size_t>* features = new std::vector<size_t>(N_); 78 80 std::copy(ir.id().begin()+first_, ir.id().begin()+first_+N_, 79 features_.begin()); 80 81 features->begin()); 82 features_ = 83 utility::Index(utility::SmartPtr<const std::vector<size_t> >(features)); 81 84 } 82 85 -
trunk/yat/classifier/FeatureSelectorRandom.cc
r1004 r1134 62 62 void FeatureSelectorRandom::update(size_t total_N) 63 63 { 64 features_.resize(0);65 features _.reserve(total_N);64 std::vector<size_t>* features = new std::vector<size_t>; 65 features->reserve(total_N); 66 66 for (size_t i=0; i<total_N; ++i) 67 features _.push_back(i);67 features->push_back(i); 68 68 // Peter should use random_sample here, but not included in std 69 random::random_shuffle(features_.begin(), features_.end()); 70 features_.resize(N_); 69 random::random_shuffle(features->begin(), features->end()); 70 features->resize(N_); 71 features_ = 72 utility::Index(utility::SmartPtr<const std::vector<size_t> >(features)); 71 73 } 72 74 -
trunk/yat/classifier/Kernel.cc
r1000 r1134 65 65 : kf_(other.kf_) 66 66 { 67 data_ = other.data_->selected( index);67 data_ = other.data_->selected(utility::Index(index)); 68 68 ref_count_ = new u_int(1); 69 69 70 70 if (other.data_w_){ 71 data_w_ = other.data_w_->selected( index);71 data_w_ = other.data_w_->selected(utility::Index(index)); 72 72 ref_count_w_ = new u_int(1); 73 73 } -
trunk/yat/classifier/KernelLookup.cc
r1133 r1134 40 40 : kernel_(utility::SmartPtr<const Kernel>(&kernel, own)) 41 41 { 42 column_index_.reserve(kernel.size()); 43 for(size_t i=0; i<kernel.size(); i++) 44 column_index_.push_back(i); 42 column_index_ = utility::Index(kernel.size()); 45 43 row_index_=column_index_; 46 44 } … … 48 46 49 47 KernelLookup::KernelLookup(const Kernel& kernel, 50 const std::vector<size_t>& row,51 const std::vector<size_t>& column,48 const utility::Index& row, 49 const utility::Index& column, 52 50 const bool owner) 53 51 : column_index_(column), … … 56 54 { 57 55 // Checking that each row index is less than kernel.rows() 58 assert(row.empty() || 59 *(std::max_element(row.begin(),row.end()))<kernel_->size()); 56 assert(validate(row_index_)); 60 57 // Checking that each column index is less than kernel.column() 61 assert(column.empty() || 62 *(std::max_element(column.begin(),column.end()))<kernel_->size()); 58 assert(validate(column_index_)); 63 59 } 64 60 65 61 66 62 KernelLookup::KernelLookup(const KernelLookup& other, 67 const std::vector<size_t>& row,68 const std::vector<size_t>& column)63 const utility::Index& row, 64 const utility::Index& column) 69 65 : kernel_(other.kernel_) 70 66 { 71 assert(row_index_.empty()); 72 row_index_.reserve(row.size()); 73 for (size_t i=0; i<row.size(); i++) { 74 assert(row[i]<other.row_index_.size()); 75 row_index_.push_back(other.row_index_[row[i]]); 76 } 77 assert(column_index_.empty()); 78 column_index_.reserve(column.size()); 79 for (size_t i=0; i<column.size(); i++) { 80 assert(column[i]<other.column_index_.size()); 81 column_index_.push_back(other.column_index_[column[i]]); 82 } 67 row_index_ = utility::Index(other.row_index_, row); 68 column_index_ = utility::Index(other.column_index_, column); 83 69 } 84 70 … … 88 74 row_index_(other.row_index_) 89 75 { 90 // Checking that no index is out of range 91 assert(row_index_.empty() || 92 *(max_element(row_index_.begin(), row_index_.end()))< 93 kernel_->size()); 94 assert(column_index_.empty() || 95 *(max_element(column_index_.begin(), column_index_.end()))< 96 kernel_->size()); 76 // Checking that each row index is less than kernel.rows() 77 assert(validate(row_index_)); 78 // Checking that each column index is less than kernel.column() 79 assert(validate(column_index_)); 97 80 } 98 81 99 82 100 83 KernelLookup::KernelLookup(const KernelLookup& other, 101 const std::vector<size_t>& index,84 const utility::Index& index, 102 85 const bool row) 103 86 : kernel_(other.kernel_) 104 87 { 105 88 if (row){ 106 assert(row_index_.empty()); 107 row_index_.reserve(index.size()); 108 for (size_t i=0; i<index.size(); i++) { 109 assert(index[i]<other.row_index_.size()); 110 row_index_.push_back(other.row_index_[index[i]]); 111 } 89 row_index_ = utility::Index(other.row_index_, index); 112 90 column_index_= other.column_index_; 113 91 } 114 92 else{ 115 assert(column_index_.empty()); 116 column_index_.reserve(index.size()); 117 for (size_t i=0; i<index.size(); i++) { 118 column_index_.push_back(other.column_index_[index[i]]); 119 } 93 column_index_ = utility::Index(other.column_index_, index); 120 94 row_index_= other.row_index_; 121 95 } 122 96 assert(kernel_->size()); 123 97 124 // Checking that no index is out of range 125 assert(row_index_.empty() || 126 *(max_element(row_index_.begin(), row_index_.end()))< 127 kernel_->size()); 128 assert(column_index_.empty() || 129 *(max_element(column_index_.begin(), column_index_.end()))< 130 kernel_->size()); 98 // Checking that each row index is less than kernel.rows() 99 assert(validate(row_index_)); 100 // Checking that each column index is less than kernel.column() 101 assert(validate(column_index_)); 131 102 } 132 103 … … 209 180 210 181 const KernelLookup* 211 KernelLookup::selected(const std::vector<size_t>& inputs) const182 KernelLookup::selected(const utility::Index& inputs) const 212 183 { 213 184 const Kernel* kernel; … … 267 238 kernel_->make_kernel(*tmp, true); 268 239 269 return new KernelLookup(*kernel, row_index, column_index, true); 240 return new KernelLookup(*kernel, utility::Index(row_index), 241 utility::Index(column_index), true); 270 242 } 271 243 … … 305 277 *weight_all, true); 306 278 const Kernel* kernel = kernel_->make_kernel(*tmp, true); 307 return new KernelLookup(*kernel, row_index_, column_index, true); 279 return new KernelLookup(*kernel, row_index_, 280 utility::Index(column_index), true); 308 281 } 309 282 … … 355 328 const Kernel* kernel = 356 329 kernel_->make_kernel(MatrixLookupWeighted(*data_all, *weight_all, true)); 357 return new KernelLookup(*kernel, row_index_, column_index, true); 330 return new KernelLookup(*kernel, row_index_, 331 utility::Index(column_index), true); 358 332 } 359 333 360 334 361 335 const KernelLookup* 362 KernelLookup::training_data(const std::vector<size_t>& train) const336 KernelLookup::training_data(const utility::Index& train) const 363 337 { 364 338 return new KernelLookup(*this,train,train); … … 366 340 367 341 342 bool KernelLookup::validate(const utility::Index& index) const 343 { 344 for (size_t i=0; i<index.size(); ++i) 345 if (index[i]>=kernel_->size()) 346 return false; 347 return true; 348 } 349 350 368 351 const KernelLookup* 369 KernelLookup::validation_data(const std::vector<size_t>& train,370 const std::vector<size_t>& validation) const352 KernelLookup::validation_data(const utility::Index& train, 353 const utility::Index& validation) const 371 354 { 372 355 return new KernelLookup(*this,train,validation); -
trunk/yat/classifier/KernelLookup.h
r1133 r1134 29 29 #include "Kernel.h" 30 30 #include "yat/utility/Container2DIterator.h" 31 #include "yat/utility/Index.h" 31 32 #include "yat/utility/iterator_traits.h" 32 33 #include "yat/utility/SmartPtr.h" 33 34 #include "yat/utility/StrideIterator.h" 34 35 #include <vector>36 35 37 36 namespace theplu { … … 120 119 /// column index. 121 120 /// 122 KernelLookup(const Kernel& kernel, const std::vector<size_t>& row,123 const std::vector<size_t>& column, const bool owner=false);121 KernelLookup(const Kernel& kernel, const utility::Index& row, 122 const utility::Index& column, const bool owner=false); 124 123 125 124 /// … … 152 151 /// column index. 153 152 /// 154 KernelLookup(const KernelLookup& kl, const std::vector<size_t>& row,155 const std::vector<size_t>& column);153 KernelLookup(const KernelLookup& kl, const utility::Index& row, 154 const utility::Index& column); 156 155 157 156 /// … … 167 166 /// undefined. 168 167 /// 169 KernelLookup(const KernelLookup& kernel, const std::vector<size_t>&,168 KernelLookup(const KernelLookup& kernel, const utility::Index&, 170 169 const bool row=false); 171 170 … … 264 263 to be deleted by the caller to avoid memory leaks. 265 264 */ 266 const KernelLookup* selected(const std::vector<size_t>& index) const;265 const KernelLookup* selected(const utility::Index& index) const; 267 266 268 267 /** … … 306 305 to be deleted by the caller to avoid memory leaks. 307 306 */ 308 const KernelLookup* training_data(const std::vector<size_t>& train) const;307 const KernelLookup* training_data(const utility::Index& train) const; 309 308 310 309 /** … … 320 319 */ 321 320 const KernelLookup* 322 validation_data(const std::vector<size_t>& train,323 const std::vector<size_t>& validation) const;321 validation_data(const utility::Index& train, 322 const utility::Index& validation) const; 324 323 325 324 /** … … 336 335 private: 337 336 const KernelLookup& operator=(const KernelLookup&); 338 339 std::vector<size_t> column_index_; 337 bool validate(const utility::Index&) const; 338 339 utility::Index column_index_; 340 340 utility::SmartPtr<const Kernel> kernel_; 341 std::vector<size_t>row_index_;341 utility::Index row_index_; 342 342 343 343 }; // class KernelLookup -
trunk/yat/classifier/MatrixLookup.cc
r1121 r1134 38 38 : DataLookup2D(own), data_(&data) 39 39 { 40 row_index_.reserve(data_->rows()); 41 for(size_t i=0;i<(*data_).rows();i++) 42 row_index_.push_back(i); 43 column_index_.reserve(data_->columns()); 44 for(size_t i=0;i<(*data_).columns();i++) 45 column_index_.push_back(i); 40 column_index_ = utility::Index(data.columns()); 41 row_index_ = utility::Index(data.rows()); 46 42 } 47 43 … … 49 45 50 46 MatrixLookup::MatrixLookup(const utility::Matrix& data, 51 const std::vector<size_t>& row,52 const std::vector<size_t>& col)47 const utility::Index& row, 48 const utility::Index& col) 53 49 : DataLookup2D(row,col), data_(&data) 54 50 { 55 // Checking that each row index is less than data.rows()56 assert(row.empty() ||57 *(std::max_element(row.begin(),row.end()))<data.rows());58 // Checking that each column index is less than data.column()59 assert(col.empty() ||60 *(std::max_element(col.begin(),col.end()))<data.columns());61 51 } 62 52 … … 64 54 65 55 MatrixLookup::MatrixLookup(const utility::Matrix& data, 66 const std::vector<size_t>& index,56 const utility::Index& index, 67 57 const bool row) 68 58 : DataLookup2D(), data_(&data) 69 59 { 70 60 if (row){ 71 // Checking that each row index is less than data.rows()72 assert(index.empty() ||73 *(std::max_element(index.begin(),index.end()))<data.rows());74 61 row_index_=index; 75 assert(column_index_.empty()); 76 column_index_.reserve(data.columns()); 77 for (size_t i=0; i<data.columns(); i++) 78 column_index_.push_back(i); 62 column_index_ = utility::Index(data.columns()); 79 63 } 80 64 else{ 81 // Checking that each column index is less than data.column()82 assert(index.empty() ||83 *(std::max_element(index.begin(),index.end()))<data.columns());84 65 column_index_=index; 85 assert(row_index_.empty()); 86 column_index_.reserve(data.rows()); 87 for (size_t i=0; i<data.rows(); i++) 88 row_index_.push_back(i); 66 row_index_ = utility::Index(data.rows()); 89 67 } 90 68 } … … 103 81 104 82 MatrixLookup::MatrixLookup(const MatrixLookup& other, 105 const std::vector<size_t>& row,106 const std::vector<size_t>& col)83 const utility::Index& row, 84 const utility::Index& col) 107 85 : DataLookup2D(other,row,col), data_(other.data_) 108 86 { … … 115 93 116 94 MatrixLookup::MatrixLookup(const MatrixLookup& other, 117 const std::vector<size_t>& index, bool row)95 const utility::Index& index, bool row) 118 96 : DataLookup2D(other,index,row), data_(other.data_) 119 97 { … … 122 100 ++(*ref_count_); 123 101 124 // Checking that no index is out of range125 assert(row_index_.empty() ||126 *(max_element(row_index_.begin(), row_index_.end()))<data_->rows());127 assert(column_index_.empty() ||128 *(max_element(column_index_.begin(), column_index_.end()))<129 data_->columns());130 102 } 131 103 … … 146 118 data_ = new utility::Matrix(is,sep); 147 119 ref_count_= new u_int(1); 148 for(size_t i=0;i<(*data_).rows();i++) 149 row_index_.push_back(i); 150 for(size_t i=0;i<(*data_).columns();i++) 151 column_index_.push_back(i); 120 row_index_ = utility::Index(data_->rows()); 121 column_index_ = utility::Index(data_->columns()); 152 122 } 153 123 … … 203 173 204 174 const MatrixLookup* 205 MatrixLookup::selected(const std::vector<size_t>& i) const175 MatrixLookup::selected(const utility::Index& i) const 206 176 { 207 177 return new MatrixLookup(*this,i, true); … … 211 181 212 182 const MatrixLookup* 213 MatrixLookup::training_data(const std::vector<size_t>& i) const183 MatrixLookup::training_data(const utility::Index& i) const 214 184 { 215 185 return new MatrixLookup(*this,i, false); … … 219 189 220 190 const MatrixLookup* 221 MatrixLookup::validation_data(const std::vector<size_t>& train,222 const std::vector<size_t>& val) const191 MatrixLookup::validation_data(const utility::Index& train, 192 const utility::Index& val) const 223 193 { 224 194 return new MatrixLookup(*this,val, false); -
trunk/yat/classifier/MatrixLookup.h
r1125 r1134 29 29 #include "DataLookup2D.h" 30 30 #include "yat/utility/Container2DIterator.h" 31 #include "yat/utility/Index.h" 31 32 #include "yat/utility/iterator_traits.h" 32 33 #include "yat/utility/StrideIterator.h" … … 118 119 /// undefined. 119 120 /// 120 MatrixLookup(const utility::Matrix& matrix, const std::vector<size_t>& row,121 const std::vector<size_t>& column);121 MatrixLookup(const utility::Matrix& matrix, const utility::Index& row, 122 const utility::Index& column); 122 123 123 124 /// … … 139 140 /// 140 141 MatrixLookup(const utility::Matrix& matrix, 141 const std::vector<size_t>& index,142 const utility::Index& index, 142 143 const bool row_vectors); 143 144 … … 178 179 /// undefined. 179 180 /// 180 MatrixLookup(const MatrixLookup& ml, const std::vector<size_t>& row,181 const std::vector<size_t>& column);181 MatrixLookup(const MatrixLookup& ml, const utility::Index& row, 182 const utility::Index& column); 182 183 183 184 /// … … 203 204 /// undefined. 204 205 /// 205 MatrixLookup(const MatrixLookup& ml, const std::vector<size_t>&,206 MatrixLookup(const MatrixLookup& ml, const utility::Index&, 206 207 const bool row_vectors); 207 208 … … 279 280 280 281 */ 281 const MatrixLookup* selected(const std::vector<size_t>&) const;282 const MatrixLookup* selected(const utility::Index&) const; 282 283 283 284 /// … … 296 297 /// to be deleted by the caller to avoid memory leaks. 297 298 /// 298 const MatrixLookup* training_data(const std::vector<size_t>& index) const;299 const MatrixLookup* training_data(const utility::Index& index) const; 299 300 300 301 /// … … 310 311 /// undefined. 311 312 /// 312 const MatrixLookup* validation_data(const std::vector<size_t>&,313 const std::vector<size_t>&) const;313 const MatrixLookup* validation_data(const utility::Index&, 314 const utility::Index&) const; 314 315 /// 315 316 /// @return false -
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); -
trunk/yat/classifier/MatrixLookupWeighted.h
r1125 r1134 149 149 MatrixLookupWeighted(const utility::Matrix& matrix, 150 150 const utility::Matrix& weights, 151 const std::vector<size_t>& row,152 const std::vector<size_t>& column);151 const utility::Index& row, 152 const utility::Index& column); 153 153 154 154 /// … … 172 172 MatrixLookupWeighted(const utility::Matrix& matrix, 173 173 const utility::Matrix& weights, 174 const std::vector<size_t>& index,174 const utility::Index& index, 175 175 const bool row_vectors); 176 176 … … 207 207 /// 208 208 MatrixLookupWeighted(const MatrixLookupWeighted& ml, 209 const std::vector<size_t>& row,210 const std::vector<size_t>& column);209 const utility::Index& row, 210 const utility::Index& column); 211 211 212 212 /// … … 233 233 /// 234 234 MatrixLookupWeighted(const MatrixLookupWeighted& ml, 235 const std::vector<size_t>&,235 const utility::Index&, 236 236 const bool row_vectors); 237 237 … … 315 315 316 316 */ 317 const MatrixLookupWeighted* selected(const std::vector<size_t>& i) const;317 const MatrixLookupWeighted* selected(const utility::Index& i) const; 318 318 319 319 /// … … 330 330 /// 331 331 const MatrixLookupWeighted* 332 training_data(const std::vector<size_t>& index) const;332 training_data(const utility::Index& index) const; 333 333 334 334 /// … … 344 344 /// undefined. 345 345 /// 346 const MatrixLookupWeighted* validation_data(const std::vector<size_t>&,347 const std::vector<size_t>&) const;346 const MatrixLookupWeighted* validation_data(const utility::Index&, 347 const utility::Index&) const; 348 348 349 349 /// -
trunk/yat/classifier/Sampler.cc
r1000 r1134 53 53 } 54 54 55 const std::vector<size_t>&55 const utility::Index& 56 56 Sampler::training_index(std::vector<size_t>::size_type i) const 57 57 { … … 65 65 } 66 66 67 const std::vector<size_t>&67 const utility::Index& 68 68 Sampler::validation_index(std::vector<size_t>::size_type i) const 69 69 { -
trunk/yat/classifier/Sampler.h
r1000 r1134 27 27 28 28 #include "Target.h" 29 #include "yat/utility/Index.h" 29 30 30 31 #include <vector> … … 69 70 /// @return training indices 70 71 /// 71 const std::vector<size_t>&72 const utility::Index& 72 73 training_index(std::vector<size_t>::size_type i) const; 73 74 … … 85 86 /// @note if state is invalid the result is undefined 86 87 /// 87 const std::vector<size_t>&88 const utility::Index& 88 89 validation_index(std::vector<size_t>::size_type i) const; 89 90 … … 99 100 Target target_; 100 101 /// index of training sets for the partitions 101 std::vector< std::vector<size_t>> training_index_;102 std::vector<utility::Index> training_index_; 102 103 /// Targets for training sets for the partitions 103 104 std::vector<Target> training_target_; 104 105 /// index of validation sets for the partitions 105 std::vector< std::vector<size_t>> validation_index_;106 std::vector<utility::Index> validation_index_; 106 107 /// Targets for validation sets for the partitions 107 108 std::vector<Target> validation_target_; -
trunk/yat/classifier/SubsetGenerator.h
r1125 r1134 33 33 #include "Target.h" 34 34 #include "Sampler.h" 35 #include "yat/utility/Index.h" 35 36 #include "yat/utility/yat_assert.h" 36 37 … … 103 104 /// @return training features 104 105 /// 105 const std::vector<size_t>&106 const utility::Index& 106 107 training_features(std::vector<size_t>::size_type i) const; 107 108 … … 109 110 /// @return training index 110 111 /// 111 const std::vector<size_t>&112 const utility::Index& 112 113 training_index(std::vector<size_t>::size_type i) const; 113 114 … … 125 126 /// @return validation index 126 127 /// 127 const std::vector<size_t>&128 const utility::Index& 128 129 validation_index(std::vector<size_t>::size_type i) const; 129 130 … … 147 148 148 149 FeatureSelector* f_selector_; 149 std::vector< std::vector<size_t>> features_;150 std::vector<utility::Index > features_; 150 151 const Sampler& sampler_; 151 152 std::vector<const T*> training_data_; … … 185 186 // No feature selection, hence features same for all partitions 186 187 // and can be stored in features_[0] 187 features_.resize(1); 188 features_[0].reserve(data.rows()); 189 for (size_t i=0; i<data.rows(); ++i) 190 features_[0].push_back(i); 188 features_.push_back(utility::Index(data.rows())); 191 189 192 190 utility::yat_assert<std::runtime_error>(training_data_.size()==size()); … … 298 296 training_target(k)); 299 297 } 300 std::vector<size_t>dummie=f_selector_->features();298 utility::Index dummie=f_selector_->features(); 301 299 features_.push_back(dummie); 302 300 //features_.push_back(f_selector_->features()); … … 338 336 339 337 template<typename T> 340 const std::vector<size_t>&341 SubsetGenerator<T>::training_features( typename std::vector<size_t>::size_typei) const338 const utility::Index& 339 SubsetGenerator<T>::training_features(size_t i) const 342 340 { 343 341 return f_selector_ ? features_[i] : features_[0]; … … 346 344 347 345 template<typename T> 348 const std::vector<size_t>&349 SubsetGenerator<T>::training_index(s td::vector<size_t>::size_typei) const346 const utility::Index& 347 SubsetGenerator<T>::training_index(size_t i) const 350 348 { 351 349 return sampler_.training_index(i); … … 370 368 371 369 template<typename T> 372 const std::vector<size_t>&370 const utility::Index& 373 371 SubsetGenerator<T>::validation_index(std::vector<size_t>::size_type i) const 374 372 { -
trunk/yat/classifier/Target.cc
r1100 r1134 26 26 #include "Target.h" 27 27 #include "yat/random/random.h" 28 #include "yat/utility/Index.h" 28 29 #include "yat/utility/stl_utility.h" 29 30 #include "yat/utility/utility.h" … … 102 103 103 104 Target::Target(const Target& t, 104 const std::vector<size_t>& index)105 const utility::Index& index) 105 106 : class_map_(t.class_map_) 106 107 { -
trunk/yat/classifier/Target.h
r1100 r1134 37 37 namespace theplu { 38 38 namespace yat { 39 namespace utility { 40 class Index; 41 } 39 42 namespace classifier { 40 43 … … 74 77 /// for the Target as the original Target. 75 78 /// 76 Target(const Target& org, const std::vector<size_t>& vec);79 Target(const Target& org, const utility::Index& vec); 77 80 78 81 ///
Note: See TracChangeset
for help on using the changeset viewer.