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

Last change on this file since 1615 was 1487, checked in by Jari Häkkinen, 13 years ago

Addresses #436. GPL license copy reference should also be updated.

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