source: trunk/yat/classifier/SupervisedClassifier.h @ 1271

Last change on this file since 1271 was 1271, checked in by Peter, 13 years ago

replaced u_int with unsigned int or size_t

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date ID
File size: 4.8 KB
Line 
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, 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/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 <cstddef>
30
31namespace theplu {
32namespace yat {
33
34  namespace utility {
35    class Matrix;
36  }
37
38namespace classifier { 
39
40  class MatrixLookup;
41  class MatrixLookupWeighted;
42  class Target;
43
44  /**
45     \brief Interface class for supervised classifiers that use data
46     in a matrix format.
47
48     The data matrix is organized with data points (samples) as
49     columns with rows corresponding to variables for the data
50     points. Supervised classifiers that do not use data in this
51     format include kernel-based classifiers such as SVM. A supervised
52     %classifier is trained on training data for which a class of each
53     data point is known and used in the training. A trained
54     supervised %classifier can be used to predict the class of test
55     samples.
56  */
57  class SupervisedClassifier
58  {
59   
60  public:
61    /**
62       \brief Constructor
63    */
64    SupervisedClassifier(void);
65   
66
67    /**
68       \brief Destructor
69    */
70    virtual ~SupervisedClassifier(void);
71
72
73    /**
74       @brief Create an untrained copy of the %classifier.
75       
76       An interface for making new %classifier objects. This function
77       allows for specification at run-time of which %classifier type
78       to instatiate (see 'Prototype' in Design Patterns). Derived
79       classes should implement this function with DerivedClass* as
80       the return type and not SupervisedClassifier*. A dynamically
81       allocated DerivedClassifier should be returned. The implementation
82       of this function should correspond to a copy constructor with
83       the exception that the returned %classifier is not trained.
84       
85       @returns A dynamically allocated %classifier, which has
86       to be deleted by the caller to avoid memory leaks.
87    */
88    virtual SupervisedClassifier* 
89    make_classifier() const =0;
90   
91
92    /**
93       \brief Make predictions for unweighted test data.
94       
95       Samples in \a data are predicted and predictions for all
96       classes are returned in \a result.  The test data \a data
97       should have one column per test sample and one row for each
98       variable measured for the test samples. The rows of \a data
99       should be ordered identical to the rows of the data used to
100       train the %classifier, so that a given row corresponds to the
101       same variable for both training and test data. The predictions
102       in \a result have one column for each sample in \a data,
103       ordered in the same order, and one row for each class as
104       defined by the targets used to train the %classifier. Derived
105       classes should implement this function such that unweighted
106       calculations are used throughout when both training and test
107       data are unweighted.
108    */       
109    virtual void predict(const MatrixLookup& data, utility::Matrix& result) const =0;   
110
111
112    /**
113       \brief Make predictions for weighted test data.
114       
115       Both \a data and \a result follow the description for
116       predict(const MatrixLookup& data, utility::Matrix& result).
117    */
118    virtual void predict(const MatrixLookupWeighted& data, utility::Matrix& result) const =0;   
119
120
121    /**
122       \brief Train the %classifier using unweighted training data with known
123       targets.
124   
125       The training data \a data should have one column per training
126       sample and one row for each variable measured for the training
127       samples. The size of \a target should be the number of samples
128       in \a data and \a target should contain the class for each
129       sample ordered in the same order as columns in \a data.
130    */
131    virtual void train(const MatrixLookup& data, const Target& targets)=0;
132   
133    /**
134       \brief Train the %classifier using weighted training data with
135       known targets.
136       
137       Both \a data and \a targets should follow the description for
138       train(const MatrixLookup& data, const Target& targets).
139    */
140    virtual void train(const MatrixLookupWeighted& data, const Target& targets)=0;
141
142  }; 
143 
144}}} // of namespace classifier, yat, and theplu
145
146#endif
Note: See TracBrowser for help on using the repository browser.