# Changeset 813 for trunk/yat/classifier

Ignore:
Timestamp:
Mar 16, 2007, 8:30:02 PM (15 years ago)
Message:

Predict in NBC. Fixes #57

Location:
trunk/yat/classifier
Files:
2 edited

Unmodified
Added
Removed
• ## trunk/yat/classifier/NBC.cc

 r812 aver[target_(j)].add(data_(i,j),1.0); } for (size_t j=0; target_.nof_classes(); ++j){ assert(centroids_.columns()==target_.nof_classes()); for (size_t j=0; j(&x); // each row in prediction corresponds to a sample label (class) prediction.resize(centroids_.columns(), x.columns(), 0); // first calculate -lnP = sum sigma_i + (x_i-m_i)^2/2sigma_i^2 for (size_t label=0; labelweight(i, label)){ prediction(label, sample) += w->weight(i, label)* std::pow(w->data(i, label)-centroids_(i, label),2)/ sigma2_(i, label); } } // no weights else { prediction(label, sample) += std::pow(x(i, label)-centroids_(i, label),2)/sigma2_(i, label); } } }
• ## trunk/yat/classifier/NBC.h

 r812 /** For each sample, calculate the probabilities the sample belong to the corresponding class. Each sample (column) in \a data is predicted and predictions are returned in the corresponding column in passed \a res. Each row in \a res corresponds to a class. The prediction is the estimated probability that sample belong to class \f$j \f$ \f$P_j = \frac{1}{Z}\prod_i{\frac{1}{\sigma_i}} \exp(\frac{w_i(x_i-\mu_i)^2}{\sigma_i^2})\f$, where \f$\mu_i \f$ and \f$\sigma_i^2 \f$ are the estimated mean and variance, respectively. If \a data is a MatrixLookup is equivalent to using all weight equal to unity. */ void predict(const DataLookup2D& data, utility::matrix& res) const;
Note: See TracChangeset for help on using the changeset viewer.