Changeset 857 for trunk/yat/classifier
 Timestamp:
 Sep 7, 2007, 1:23:27 AM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/NCC.cc
r831 r857 91 91 centroids_.clone(utility::matrix(data_.rows(), target_.nof_classes())); 92 92 utility::matrix nof_in_class(data_.rows(), target_.nof_classes()); 93 const MatrixLookupWeighted* weighted_data = 94 dynamic_cast<const MatrixLookupWeighted*>(&data_); 95 bool weighted = weighted_data; 96 93 97 for(size_t i=0; i<data_.rows(); i++) { 94 98 for(size_t j=0; j<data_.columns(); j++) { 95 99 centroids_(i,target_(j)) += data_(i,j); 96 try { 97 nof_in_class(i,target_(j))+= 98 dynamic_cast<const MatrixLookupWeighted&>(data_).weight(i,j); 99 } 100 catch (std::bad_cast) { 100 if (weighted) 101 nof_in_class(i,target_(j))+= weighted_data>weight(i,j); 102 else 101 103 nof_in_class(i,target_(j))+=1.0; 102 }103 104 } 104 105 } … … 135 136 { 136 137 prediction.clone(utility::matrix(centroids_.columns(), input.columns())); 137 try { 138 const MatrixLookupWeighted& data= 139 dynamic_cast<const MatrixLookupWeighted&>(input); 138 // weighted case 139 const MatrixLookupWeighted* data = 140 dynamic_cast<const MatrixLookupWeighted*>(&input); 141 if (data) { 140 142 for(size_t j=0; j<input.columns();j++) { 141 143 DataLookup1D in(input,j,false); 142 144 utility::vector weights(in.size(),0); 143 145 for(size_t i=0; i<in.size();i++) 144 weights(i)=data .weight(i,j);146 weights(i)=data>weight(i,j); 145 147 utility::vector out; 146 148 predict(in,weights,out); 147 149 prediction.column(j,out); 148 150 } 151 return; 149 152 } 150 catch (std::bad_cast) { 151 try { 152 dynamic_cast<const MatrixLookup&>(input); 153 for(size_t j=0; j<input.columns();j++) { 154 DataLookup1D in(input,j,false); 155 utility::vector weights(in.size(),1.0); 156 utility::vector out; 157 predict(in,weights,out); 158 prediction.column(j,out); 159 } 160 } 161 catch (std::bad_cast e) { 162 std::cerr << "Error in NCC::predict: DataLookup2D of unexpected class. " 163 << "bad_cast: " << e.what() << std::endl; 164 } 153 // nonweighted case 154 const MatrixLookup* x = dynamic_cast<const MatrixLookup*>(&input); 155 if (!x){ 156 std::string str; 157 str = "Error in NCC::predict: DataLookup2D of unexpected class."; 158 throw std::runtime_error(str); 159 } 160 for(size_t j=0; j<input.columns();j++) { 161 DataLookup1D in(input,j,false); 162 utility::vector weights(in.size(),1.0); 163 utility::vector out; 164 predict(in,weights,out); 165 prediction.column(j,out); 165 166 } 166 167 }
Note: See TracChangeset
for help on using the changeset viewer.