4200 |
19 Aug 22 |
peter |
1 |
#ifndef _theplu_yat_classifier_supervisedclassifier_ |
4200 |
19 Aug 22 |
peter |
2 |
#define _theplu_yat_classifier_supervisedclassifier_ |
476 |
22 Dec 05 |
markus |
3 |
|
616 |
31 Aug 06 |
jari |
// $Id$ |
616 |
31 Aug 06 |
jari |
5 |
|
675 |
10 Oct 06 |
jari |
6 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2005 Markus Ringnér |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér |
675 |
10 Oct 06 |
jari |
11 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
13 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
18 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
23 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
26 |
*/ |
675 |
10 Oct 06 |
jari |
27 |
|
1271 |
09 Apr 08 |
peter |
28 |
#include <cstddef> |
476 |
22 Dec 05 |
markus |
29 |
|
476 |
22 Dec 05 |
markus |
30 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
31 |
namespace yat { |
476 |
22 Dec 05 |
markus |
32 |
|
616 |
31 Aug 06 |
jari |
33 |
namespace utility { |
1121 |
22 Feb 08 |
peter |
34 |
class Matrix; |
476 |
22 Dec 05 |
markus |
35 |
} |
476 |
22 Dec 05 |
markus |
36 |
|
4200 |
19 Aug 22 |
peter |
37 |
namespace classifier { |
476 |
22 Dec 05 |
markus |
38 |
|
1157 |
26 Feb 08 |
markus |
39 |
class MatrixLookup; |
1157 |
26 Feb 08 |
markus |
40 |
class MatrixLookupWeighted; |
593 |
25 Aug 06 |
markus |
41 |
class Target; |
476 |
22 Dec 05 |
markus |
42 |
|
1188 |
29 Feb 08 |
markus |
43 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Interface class for supervised classifiers that use data |
1188 |
29 Feb 08 |
markus |
in a matrix format. |
1188 |
29 Feb 08 |
markus |
46 |
|
1188 |
29 Feb 08 |
markus |
The data matrix is organized with data points (samples) as |
1188 |
29 Feb 08 |
markus |
columns with rows corresponding to variables for the data |
1188 |
29 Feb 08 |
markus |
points. Supervised classifiers that do not use data in this |
1188 |
29 Feb 08 |
markus |
format include kernel-based classifiers such as SVM. A supervised |
1188 |
29 Feb 08 |
markus |
%classifier is trained on training data for which a class of each |
1188 |
29 Feb 08 |
markus |
data point is known and used in the training. A trained |
1188 |
29 Feb 08 |
markus |
supervised %classifier can be used to predict the class of test |
1188 |
29 Feb 08 |
markus |
samples. |
1188 |
29 Feb 08 |
markus |
55 |
*/ |
476 |
22 Dec 05 |
markus |
56 |
class SupervisedClassifier |
476 |
22 Dec 05 |
markus |
57 |
{ |
4200 |
19 Aug 22 |
peter |
58 |
|
476 |
22 Dec 05 |
markus |
59 |
public: |
1188 |
29 Feb 08 |
markus |
60 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Constructor |
1188 |
29 Feb 08 |
markus |
62 |
*/ |
1157 |
26 Feb 08 |
markus |
63 |
SupervisedClassifier(void); |
526 |
01 Mar 06 |
markus |
64 |
|
4200 |
19 Aug 22 |
peter |
65 |
|
1188 |
29 Feb 08 |
markus |
66 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Destructor |
1188 |
29 Feb 08 |
markus |
68 |
*/ |
680 |
11 Oct 06 |
jari |
69 |
virtual ~SupervisedClassifier(void); |
476 |
22 Dec 05 |
markus |
70 |
|
722 |
27 Dec 06 |
markus |
71 |
|
1188 |
29 Feb 08 |
markus |
72 |
/** |
1188 |
29 Feb 08 |
markus |
@brief Create an untrained copy of the %classifier. |
4200 |
19 Aug 22 |
peter |
74 |
|
1188 |
29 Feb 08 |
markus |
An interface for making new %classifier objects. This function |
1188 |
29 Feb 08 |
markus |
allows for specification at run-time of which %classifier type |
1188 |
29 Feb 08 |
markus |
to instatiate (see 'Prototype' in Design Patterns). Derived |
1188 |
29 Feb 08 |
markus |
classes should implement this function with DerivedClass* as |
1188 |
29 Feb 08 |
markus |
the return type and not SupervisedClassifier*. A dynamically |
1188 |
29 Feb 08 |
markus |
allocated DerivedClassifier should be returned. The implementation |
1188 |
29 Feb 08 |
markus |
of this function should correspond to a copy constructor with |
1188 |
29 Feb 08 |
markus |
the exception that the returned %classifier is not trained. |
4200 |
19 Aug 22 |
peter |
83 |
|
1188 |
29 Feb 08 |
markus |
@returns A dynamically allocated %classifier, which has |
1188 |
29 Feb 08 |
markus |
to be deleted by the caller to avoid memory leaks. |
1188 |
29 Feb 08 |
markus |
86 |
*/ |
4200 |
19 Aug 22 |
peter |
87 |
virtual SupervisedClassifier* |
1157 |
26 Feb 08 |
markus |
88 |
make_classifier() const =0; |
476 |
22 Dec 05 |
markus |
89 |
|
4200 |
19 Aug 22 |
peter |
90 |
|
1188 |
29 Feb 08 |
markus |
91 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Make predictions for unweighted test data. |
4200 |
19 Aug 22 |
peter |
93 |
|
1188 |
29 Feb 08 |
markus |
Samples in \a data are predicted and predictions for all |
1188 |
29 Feb 08 |
markus |
classes are returned in \a result. The test data \a data |
1188 |
29 Feb 08 |
markus |
should have one column per test sample and one row for each |
1188 |
29 Feb 08 |
markus |
variable measured for the test samples. The rows of \a data |
1188 |
29 Feb 08 |
markus |
should be ordered identical to the rows of the data used to |
1188 |
29 Feb 08 |
markus |
train the %classifier, so that a given row corresponds to the |
1188 |
29 Feb 08 |
markus |
same variable for both training and test data. The predictions |
1188 |
29 Feb 08 |
markus |
in \a result have one column for each sample in \a data, |
1188 |
29 Feb 08 |
markus |
ordered in the same order, and one row for each class as |
1188 |
29 Feb 08 |
markus |
defined by the targets used to train the %classifier. Derived |
1188 |
29 Feb 08 |
markus |
classes should implement this function such that unweighted |
1188 |
29 Feb 08 |
markus |
calculations are used throughout when both training and test |
1188 |
29 Feb 08 |
markus |
data are unweighted. |
4200 |
19 Aug 22 |
peter |
107 |
*/ |
4200 |
19 Aug 22 |
peter |
108 |
virtual void predict(const MatrixLookup& data, utility::Matrix& result) const =0; |
722 |
27 Dec 06 |
markus |
109 |
|
722 |
27 Dec 06 |
markus |
110 |
|
1188 |
29 Feb 08 |
markus |
111 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Make predictions for weighted test data. |
4200 |
19 Aug 22 |
peter |
113 |
|
1188 |
29 Feb 08 |
markus |
Both \a data and \a result follow the description for |
1188 |
29 Feb 08 |
markus |
predict(const MatrixLookup& data, utility::Matrix& result). |
1188 |
29 Feb 08 |
markus |
116 |
*/ |
4200 |
19 Aug 22 |
peter |
117 |
virtual void predict(const MatrixLookupWeighted& data, utility::Matrix& result) const =0; |
722 |
27 Dec 06 |
markus |
118 |
|
1160 |
26 Feb 08 |
markus |
119 |
|
1188 |
29 Feb 08 |
markus |
120 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Train the %classifier using unweighted training data with known |
4200 |
19 Aug 22 |
peter |
targets. |
4200 |
19 Aug 22 |
peter |
123 |
|
1188 |
29 Feb 08 |
markus |
The training data \a data should have one column per training |
1188 |
29 Feb 08 |
markus |
sample and one row for each variable measured for the training |
1188 |
29 Feb 08 |
markus |
samples. The size of \a target should be the number of samples |
1188 |
29 Feb 08 |
markus |
in \a data and \a target should contain the class for each |
1188 |
29 Feb 08 |
markus |
sample ordered in the same order as columns in \a data. |
1188 |
29 Feb 08 |
markus |
129 |
*/ |
1176 |
27 Feb 08 |
markus |
130 |
virtual void train(const MatrixLookup& data, const Target& targets)=0; |
4200 |
19 Aug 22 |
peter |
131 |
|
1188 |
29 Feb 08 |
markus |
132 |
/** |
1188 |
29 Feb 08 |
markus |
\brief Train the %classifier using weighted training data with |
4200 |
19 Aug 22 |
peter |
known targets. |
4200 |
19 Aug 22 |
peter |
135 |
|
1188 |
29 Feb 08 |
markus |
Both \a data and \a targets should follow the description for |
1188 |
29 Feb 08 |
markus |
train(const MatrixLookup& data, const Target& targets). |
1188 |
29 Feb 08 |
markus |
138 |
*/ |
1176 |
27 Feb 08 |
markus |
139 |
virtual void train(const MatrixLookupWeighted& data, const Target& targets)=0; |
1157 |
26 Feb 08 |
markus |
140 |
|
4200 |
19 Aug 22 |
peter |
141 |
}; |
4200 |
19 Aug 22 |
peter |
142 |
|
680 |
11 Oct 06 |
jari |
143 |
}}} // of namespace classifier, yat, and theplu |
476 |
22 Dec 05 |
markus |
144 |
|
476 |
22 Dec 05 |
markus |
145 |
#endif |