Changeset 916 for trunk/yat/classifier/KNN.h
 Timestamp:
 Sep 30, 2007, 2:50:10 AM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/KNN.h
r904 r916 10 10 #include "yat/statistics/vector_distance.h" 11 11 #include "yat/utility/matrix.h" 12 12 #include "yat/utility/yat_assert.h" 13 14 #include <cmath> 13 15 #include <map> 14 16 … … 119 121 120 122 // matrix with training samples as rows and test samples as columns 121 utility::matrix* distances = new utility::matrix(data_.columns(),input.columns()); 123 utility::matrix* distances = 124 new utility::matrix(data_.columns(),input.columns()); 122 125 123 126 if(weighted_data && weighted_input) { … … 126 129 for(size_t j=0; j<input.columns(); j++) { 127 130 classifier::DataLookupWeighted1D test(*weighted_input,j,false); 131 yat_assert(training.size()==test.size()); 128 132 (*distances)(i,j)=statistics::vector_distance(training.begin(),training.end(),test.begin(),typename statistics::vector_distance_traits<Distance>::distance()); 133 yat_assert(!std::isnan((*distances)(i,j))); 129 134 } 130 135 } … … 186 191 utility::matrix* distances=calculate_distances(input); 187 192 188 // for each test sample (column in distances) find the closest training samples 189 prediction.clone(utility::matrix(target_.nof_classes(), input.columns(),0.0)); 193 // for each test sample (column in distances) find the closest 194 // training samples 195 prediction.clone(utility::matrix(target_.nof_classes(),input.columns(),0.0)); 190 196 for(size_t sample=0;sample<distances>columns();sample++) { 191 197 std::vector<size_t> k_index;
Note: See TracChangeset
for help on using the changeset viewer.