source: trunk/yat/classifier/NCC.h @ 898

Last change on this file since 898 was 898, checked in by Markus Ringnér, 15 years ago

A first suggestion for how to adress #250. Also removed contamination of namespace std (see #251).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 2.9 KB
Line 
1#ifndef _theplu_yat_classifier_ncc_
2#define _theplu_yat_classifier_ncc_
3
4// $Id$
5
6/*
7  Copyright (C) 2005 Markus Ringnér, Peter Johansson
8  Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson
9  Copyright (C) 2007 Peter Johansson
10
11  This file is part of the yat library, http://trac.thep.lu.se/trac/yat
12
13  The yat library is free software; you can redistribute it and/or
14  modify it under the terms of the GNU General Public License as
15  published by the Free Software Foundation; either version 2 of the
16  License, or (at your option) any later version.
17
18  The yat library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  General Public License for more details.
22
23  You should have received a copy of the GNU General Public License
24  along with this program; if not, write to the Free Software
25  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26  02111-1307, USA.
27*/
28
29#include "yat/utility/matrix.h"
30#include "yat/statistics/vector_distance_ptr.h"
31#include "SupervisedClassifier.h"
32
33#include <map>
34
35namespace theplu {
36namespace yat {
37
38  namespace utlitity {
39    class vector;
40  }
41
42namespace classifier { 
43
44  class DataLookup1D;
45  class DataLookup2D;
46  class MatrixLookup;
47  class MatrixLookupWeighted;
48  class Target;
49
50  ///
51  /// @brief Class for Nearest Centroid Classification.
52  ///
53
54  class NCC : public SupervisedClassifier
55  {
56 
57  public:
58    ///
59    /// Constructor taking the training data, the target vector, and
60    /// the distance measure tag as input.
61    ///
62    NCC(const MatrixLookup&, const Target&, 
63        const statistics::vector_distance_lookup_weighted_ptr);
64   
65    ///
66    /// Constructor taking the training data with weights, the target
67    /// vector, the distance measure tag.
68    ///
69    NCC(const MatrixLookupWeighted&, const Target&, 
70        const statistics::vector_distance_lookup_weighted_ptr);
71
72    virtual ~NCC();
73
74    ///
75    /// @return the centroids for each class as columns in a matrix.
76    ///
77    const utility::matrix& centroids(void) const;
78
79    const DataLookup2D& data(void) const;
80
81    SupervisedClassifier* make_classifier(const DataLookup2D&, 
82                                          const Target&) const;
83   
84    ///
85    /// Train the classifier using the training data. Centroids are
86    /// calculated for each class.
87    ///
88    /// @return true if training succedeed.
89    ///
90    bool train();
91
92   
93    ///
94    /// Calculate the distance to each centroid for test samples
95    ///
96    void predict(const DataLookup2D&, utility::matrix&) const;
97   
98   
99  private:
100    utility::matrix centroids_;
101    const statistics::vector_distance_lookup_weighted_ptr distance_;                 
102
103    // data_ has to be of type DataLookup2D to accomodate both
104    // MatrixLookup and MatrixLookupWeighted
105    const DataLookup2D& data_;
106
107  };
108
109  ///
110  /// The output operator for the NCC class.
111  ///
112  //  std::ostream& operator<< (std::ostream&, const NCC&);
113 
114 
115}}} // of namespace classifier, yat, and theplu
116
117#endif
Note: See TracBrowser for help on using the repository browser.