Changeset 1182 for trunk/yat/classifier/NBC.cc
 Timestamp:
 Feb 28, 2008, 1:27:37 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/yat/classifier/NBC.cc
r1162 r1182 152 152 prediction.resize(centroids_.columns(), mlw.columns(), 0); 153 153 154 // first calculate lnP = sum sigma_i + (x_im_i)^2/2sigma_i^2 154 // first calculate lnP = sum (sigma_i) + 155 // N sum w_i(x_im_i)^2/2sigma_i^2 / sum w_i 155 156 for (size_t label=0; label<centroids_.columns(); ++label) { 156 157 double sum_log_sigma = sum_logsigma(label); 157 158 for (size_t sample=0; sample<prediction.rows(); ++sample) { 158 prediction(label,sample) = sum_log_sigma;159 statistics::AveragerWeighted aw; 159 160 for (size_t i=0; i<mlw.rows(); ++i) 160 // taking care of NaN and missing training features 161 if (mlw.weight(i, label) && !std::isnan(sigma2_(i, label))) { 162 prediction(label, sample) += mlw.weight(i, label)* 163 std::pow(mlw.data(i, label)centroids_(i, label),2)/ 164 sigma2_(i, label); 165 } 166 161 // missing training features 162 if (!std::isnan(sigma2_(i, label))) 163 aw.add(std::pow(mlw.data(i, label)centroids_(i, label),2)/ 164 sigma2_(i, label), mlw.weight(i, label)); 165 prediction(label,sample) = sum_log_sigma + mlw.rows()*aw.mean()/2; 167 166 } 168 167 }
Note: See TracChangeset
for help on using the changeset viewer.