1 | #ifndef _theplu_yat_classifier_supervisedclassifier_ |
---|
2 | #define _theplu_yat_classifier_supervisedclassifier_ |
---|
3 | |
---|
4 | // $Id$ |
---|
5 | |
---|
6 | /* |
---|
7 | Copyright (C) 2005 Markus Ringnér |
---|
8 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
---|
9 | Copyright (C) 2007 Jari Häkkinen, Peter Johansson |
---|
10 | Copyright (C) 2008 Peter Johansson, Markus Ringnér |
---|
11 | |
---|
12 | This file is part of the yat library, http://dev.thep.lu.se/yat |
---|
13 | |
---|
14 | The yat library is free software; you can redistribute it and/or |
---|
15 | modify it under the terms of the GNU General Public License as |
---|
16 | published by the Free Software Foundation; either version 2 of the |
---|
17 | License, or (at your option) any later version. |
---|
18 | |
---|
19 | The yat library is distributed in the hope that it will be useful, |
---|
20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
22 | General Public License for more details. |
---|
23 | |
---|
24 | You should have received a copy of the GNU General Public License |
---|
25 | along with this program; if not, write to the Free Software |
---|
26 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
27 | 02111-1307, USA. |
---|
28 | */ |
---|
29 | |
---|
30 | #include <cstddef> |
---|
31 | |
---|
32 | namespace theplu { |
---|
33 | namespace yat { |
---|
34 | |
---|
35 | namespace utility { |
---|
36 | class Matrix; |
---|
37 | } |
---|
38 | |
---|
39 | namespace classifier { |
---|
40 | |
---|
41 | class MatrixLookup; |
---|
42 | class MatrixLookupWeighted; |
---|
43 | class Target; |
---|
44 | |
---|
45 | /** |
---|
46 | \brief Interface class for supervised classifiers that use data |
---|
47 | in a matrix format. |
---|
48 | |
---|
49 | The data matrix is organized with data points (samples) as |
---|
50 | columns with rows corresponding to variables for the data |
---|
51 | points. Supervised classifiers that do not use data in this |
---|
52 | format include kernel-based classifiers such as SVM. A supervised |
---|
53 | %classifier is trained on training data for which a class of each |
---|
54 | data point is known and used in the training. A trained |
---|
55 | supervised %classifier can be used to predict the class of test |
---|
56 | samples. |
---|
57 | */ |
---|
58 | class SupervisedClassifier |
---|
59 | { |
---|
60 | |
---|
61 | public: |
---|
62 | /** |
---|
63 | \brief Constructor |
---|
64 | */ |
---|
65 | SupervisedClassifier(void); |
---|
66 | |
---|
67 | |
---|
68 | /** |
---|
69 | \brief Destructor |
---|
70 | */ |
---|
71 | virtual ~SupervisedClassifier(void); |
---|
72 | |
---|
73 | |
---|
74 | /** |
---|
75 | @brief Create an untrained copy of the %classifier. |
---|
76 | |
---|
77 | An interface for making new %classifier objects. This function |
---|
78 | allows for specification at run-time of which %classifier type |
---|
79 | to instatiate (see 'Prototype' in Design Patterns). Derived |
---|
80 | classes should implement this function with DerivedClass* as |
---|
81 | the return type and not SupervisedClassifier*. A dynamically |
---|
82 | allocated DerivedClassifier should be returned. The implementation |
---|
83 | of this function should correspond to a copy constructor with |
---|
84 | the exception that the returned %classifier is not trained. |
---|
85 | |
---|
86 | @returns A dynamically allocated %classifier, which has |
---|
87 | to be deleted by the caller to avoid memory leaks. |
---|
88 | */ |
---|
89 | virtual SupervisedClassifier* |
---|
90 | make_classifier() const =0; |
---|
91 | |
---|
92 | |
---|
93 | /** |
---|
94 | \brief Make predictions for unweighted test data. |
---|
95 | |
---|
96 | Samples in \a data are predicted and predictions for all |
---|
97 | classes are returned in \a result. The test data \a data |
---|
98 | should have one column per test sample and one row for each |
---|
99 | variable measured for the test samples. The rows of \a data |
---|
100 | should be ordered identical to the rows of the data used to |
---|
101 | train the %classifier, so that a given row corresponds to the |
---|
102 | same variable for both training and test data. The predictions |
---|
103 | in \a result have one column for each sample in \a data, |
---|
104 | ordered in the same order, and one row for each class as |
---|
105 | defined by the targets used to train the %classifier. Derived |
---|
106 | classes should implement this function such that unweighted |
---|
107 | calculations are used throughout when both training and test |
---|
108 | data are unweighted. |
---|
109 | */ |
---|
110 | virtual void predict(const MatrixLookup& data, utility::Matrix& result) const =0; |
---|
111 | |
---|
112 | |
---|
113 | /** |
---|
114 | \brief Make predictions for weighted test data. |
---|
115 | |
---|
116 | Both \a data and \a result follow the description for |
---|
117 | predict(const MatrixLookup& data, utility::Matrix& result). |
---|
118 | */ |
---|
119 | virtual void predict(const MatrixLookupWeighted& data, utility::Matrix& result) const =0; |
---|
120 | |
---|
121 | |
---|
122 | /** |
---|
123 | \brief Train the %classifier using unweighted training data with known |
---|
124 | targets. |
---|
125 | |
---|
126 | The training data \a data should have one column per training |
---|
127 | sample and one row for each variable measured for the training |
---|
128 | samples. The size of \a target should be the number of samples |
---|
129 | in \a data and \a target should contain the class for each |
---|
130 | sample ordered in the same order as columns in \a data. |
---|
131 | */ |
---|
132 | virtual void train(const MatrixLookup& data, const Target& targets)=0; |
---|
133 | |
---|
134 | /** |
---|
135 | \brief Train the %classifier using weighted training data with |
---|
136 | known targets. |
---|
137 | |
---|
138 | Both \a data and \a targets should follow the description for |
---|
139 | train(const MatrixLookup& data, const Target& targets). |
---|
140 | */ |
---|
141 | virtual void train(const MatrixLookupWeighted& data, const Target& targets)=0; |
---|
142 | |
---|
143 | }; |
---|
144 | |
---|
145 | }}} // of namespace classifier, yat, and theplu |
---|
146 | |
---|
147 | #endif |
---|