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

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

Closes #129

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 3.0 KB
Line 
1#ifndef _theplu_yat_classifier_ncc_
2#define _theplu_yat_classifier_ncc_
3
4// $Id$
5
6/*
7  Copyright (C) The authors contributing to this file.
8
9  This file is part of the yat library, http://lev.thep.lu.se/trac/yat
10
11  The yat library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU General Public License as
13  published by the Free Software Foundation; either version 2 of the
14  License, or (at your option) any later version.
15
16  The yat library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  General Public License for more details.
20
21  You should have received a copy of the GNU General Public License
22  along with this program; if not, write to the Free Software
23  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24  02111-1307, USA.
25*/
26
27#include "yat/utility/matrix.h"
28#include "SupervisedClassifier.h"
29
30#include <map>
31
32namespace theplu {
33namespace yat {
34
35  namespace utlitity {
36    class vector;
37  }
38
39  namespace statistics {
40    class Distance;
41  }
42
43namespace classifier { 
44
45  class DataLookup1D;
46  class DataLookup2D;
47  class MatrixLookup;
48  class MatrixLookupWeighted;
49  class Target;
50
51  ///
52  /// Class for Nearest Centroid Classification.
53  ///
54
55  class NCC : public SupervisedClassifier
56  {
57 
58  public:
59    ///
60    /// Constructor taking the training data, the target vector, and
61    /// the distance measure as input.
62    ///
63    NCC(const MatrixLookup&, const Target&, const statistics::Distance&);
64   
65    ///
66    /// Constructor taking the training data with weights, the target
67    /// vector, the distance measure, and a weight matrix for the
68    /// training data as input.
69    ///
70    NCC(const MatrixLookupWeighted&, const Target&, const statistics::Distance&);
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::Distance& distance_;                 
102
103    // data_ has to be of type DataLookup2D to accomodate both
104    // MatrixLookup and MatrixLookupWeighted
105    const DataLookup2D& data_;
106
107    ///
108    /// Calculate the distance to each centroid for a test sample
109    ///
110    void predict(const DataLookup1D&, const utility::vector&,
111                 utility::vector&) const;
112
113  };
114
115  ///
116  /// The output operator for the NCC class.
117  ///
118  //  std::ostream& operator<< (std::ostream&, const NCC&);
119 
120 
121}}} // of namespace classifier, yat, and theplu
122
123#endif
Note: See TracBrowser for help on using the repository browser.