1 #ifndef _theplu_yat_classifier_ncc_
2 #define _theplu_yat_classifier_ncc_
27 #include "MatrixLookup.h"
28 #include "MatrixLookupWeighted.h"
29 #include "SupervisedClassifier.h"
32 #include "yat/statistics/Averager.h"
33 #include "yat/statistics/AveragerWeighted.h"
34 #include "yat/utility/concept_check.h"
35 #include "yat/utility/Exception.h"
36 #include "yat/utility/Matrix.h"
37 #include "yat/utility/MatrixWeighted.h"
38 #include "yat/utility/Vector.h"
40 #include "yat/utility/yat_assert.h"
42 #include <boost/concept_check.hpp>
50 namespace classifier {
64 template <
typename Distance>
180 template <
typename Distance>
187 template <
typename Distance>
195 template <
typename Distance>
201 template <
typename Distance>
208 template <
typename Distance>
217 template <
typename Distance>
221 for(
size_t i=0; i<data.
rows(); i++) {
222 std::vector<statistics::Averager> class_averager;
224 for(
size_t j=0; j<data.
columns(); j++) {
225 class_averager[target(j)].add(data(i,j));
228 centroids_(i,c) = class_averager[c].mean();
234 template <
typename Distance>
238 for(
size_t i=0; i<data.
rows(); i++) {
239 std::vector<statistics::AveragerWeighted> class_averager;
241 for(
size_t j=0; j<data.
columns(); j++)
242 class_averager[target(j)].add(data.
data(i,j),data.
weight(i,j));
244 if(class_averager[c].sum_w()==0) {
247 centroids_(i,c) = class_averager[c].mean();
253 template <
typename Distance>
257 utility::yat_assert<utility::runtime_error>
258 (centroids_.rows()==test.
rows(),
259 "NCC::predict test data with incorrect number of rows");
269 predict_unweighted(test,prediction);
273 template <
typename Distance>
277 utility::yat_assert<utility::runtime_error>
278 (centroids_.rows()==test.
rows(),
279 "NCC::predict test data with incorrect number of rows");
282 predict_weighted(test,prediction);
286 template <
typename Distance>
290 for(
size_t j=0; j<test.
columns();j++)
291 for(
size_t k=0; k<centroids_.columns();k++)
293 centroids_.begin_column(k));
296 template <
typename Distance>
297 void NCC<Distance>::predict_weighted(
const MatrixLookupWeighted& test,
301 for(
size_t j=0; j<test.columns();j++)
302 for(
size_t k=0; k<centroids_.columns();k++)
303 prediction(k,j) = distance_(test.begin_column(j), test.end_column(j),
304 weighted_centroids.begin_column(k));