Changeset 866
 Timestamp:
 Sep 12, 2007, 2:25:28 PM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/EnsembleBuilder.cc
r865 r866 28 28 #include "FeatureSelector.h" 29 29 #include "KernelLookup.h" 30 #include "MatrixLookup.h" 31 #include "MatrixLookupWeighted.h" 30 32 #include "Sampler.h" 31 33 #include "SubsetGenerator.h" … … 82 84 83 85 84 void 86 void EnsembleBuilder::predict 85 87 (const DataLookup2D& data, 86 88 std::vector<std::vector<statistics::Averager> >& result) … … 92 94 93 95 utility::matrix prediction; 94 const KernelLookup* kernel = dynamic_cast<const KernelLookup*>(&data); 95 if (kernel) { 96 for(u_long k=0;k<subset_>size();k++) { 96 97 const KernelLookup* kernel = dynamic_cast<const KernelLookup*>(&data); 98 const MatrixLookupWeighted* mw = 99 dynamic_cast<const MatrixLookupWeighted*>(&data); 100 const MatrixLookup* m = dynamic_cast<const MatrixLookup*>(&data); 101 102 if(kernel) { 103 for(u_long k=0;k<subset_>size();k++) { 97 104 KernelLookup sub_kernel(*kernel,subset_>training_index(k),true); 98 105 classifier(k).predict(sub_kernel,prediction); 99 100 for(size_t i=0; i<prediction.rows();i++) 101 for(size_t j=0; j<prediction.columns();j++) 102 result[i][j].add(prediction(i,j)); 106 } 107 } 108 else if(mw) { 109 for(u_long k=0;k<subset_>size();k++) { 110 MatrixLookupWeighted sub_matrix(*mw,subset_>training_features(k),true); 111 classifier(k).predict(sub_matrix,prediction); 112 } 113 } 114 else if(m) { 115 for(u_long k=0;k<subset_>size();k++) { 116 MatrixLookup sub_matrix(*m,subset_>training_features(k),true); 117 classifier(k).predict(sub_matrix,prediction); 103 118 } 104 119 } 105 120 else { 106 for(u_long k=0;k<subset_>size();k++) { 107 classifier(k).predict(data,prediction); 108 for(size_t i=0; i<prediction.rows();i++) 109 for(size_t j=0; j<prediction.columns();j++) 110 result[i][j].add(prediction(i,j)); 111 112 } 121 std::string str; 122 str = "Error in NCC::predict: DataLookup2D of unexpected class."; 123 throw std::runtime_error(str); 113 124 } 125 126 for(size_t i=0; i<prediction.rows();i++) 127 for(size_t j=0; j<prediction.columns();j++) 128 result[i][j].add(prediction(i,j)); 114 129 } 115 130 116 131 117 132 const std::vector<std::vector<statistics::Averager> >& 118 133 EnsembleBuilder::validate(void) … … 127 142 for(u_long k=0;k<subset_>size();k++) { 128 143 classifier(k).predict(subset_>validation_data(k),prediction); 129 144 145 // map results to indices of samples in training + validation data set 130 146 for(size_t i=0; i<prediction.rows();i++) 131 147 for(size_t j=0; j<prediction.columns();j++) {
Note: See TracChangeset
for help on using the changeset viewer.