yat/classifier/SupervisedClassifier.h

Code
Comments
Other
Rev Date Author Line
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 4 // $Id$
616 31 Aug 06 jari 5
675 10 Oct 06 jari 6 /*
2119 12 Dec 09 peter 7   Copyright (C) 2005 Markus Ringnér
2119 12 Dec 09 peter 8   Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
4359 23 Aug 23 peter 9   Copyright (C) 2007 Peter Johansson
2119 12 Dec 09 peter 10   Copyright (C) 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
675 10 Oct 06 jari 11
1437 25 Aug 08 peter 12   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 14   The yat library is free software; you can redistribute it and/or
675 10 Oct 06 jari 15   modify it under the terms of the GNU General Public License as
1486 09 Sep 08 jari 16   published by the Free Software Foundation; either version 3 of the
675 10 Oct 06 jari 17   License, or (at your option) any later version.
675 10 Oct 06 jari 18
675 10 Oct 06 jari 19   The yat library is distributed in the hope that it will be useful,
675 10 Oct 06 jari 20   but WITHOUT ANY WARRANTY; without even the implied warranty of
675 10 Oct 06 jari 21   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
675 10 Oct 06 jari 22   General Public License for more details.
675 10 Oct 06 jari 23
675 10 Oct 06 jari 24   You should have received a copy of the GNU General Public License
1487 10 Sep 08 jari 25   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 44      \brief Interface class for supervised classifiers that use data
1188 29 Feb 08 markus 45      in a matrix format.
1188 29 Feb 08 markus 46
1188 29 Feb 08 markus 47      The data matrix is organized with data points (samples) as
1188 29 Feb 08 markus 48      columns with rows corresponding to variables for the data
1188 29 Feb 08 markus 49      points. Supervised classifiers that do not use data in this
1188 29 Feb 08 markus 50      format include kernel-based classifiers such as SVM. A supervised
1188 29 Feb 08 markus 51      %classifier is trained on training data for which a class of each
1188 29 Feb 08 markus 52      data point is known and used in the training. A trained
1188 29 Feb 08 markus 53      supervised %classifier can be used to predict the class of test
1188 29 Feb 08 markus 54      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 61        \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 67        \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 73        @brief Create an untrained copy of the %classifier.
4200 19 Aug 22 peter 74
1188 29 Feb 08 markus 75        An interface for making new %classifier objects. This function
1188 29 Feb 08 markus 76        allows for specification at run-time of which %classifier type
1188 29 Feb 08 markus 77        to instatiate (see 'Prototype' in Design Patterns). Derived
1188 29 Feb 08 markus 78        classes should implement this function with DerivedClass* as
1188 29 Feb 08 markus 79        the return type and not SupervisedClassifier*. A dynamically
1188 29 Feb 08 markus 80        allocated DerivedClassifier should be returned. The implementation
1188 29 Feb 08 markus 81        of this function should correspond to a copy constructor with
1188 29 Feb 08 markus 82        the exception that the returned %classifier is not trained.
4200 19 Aug 22 peter 83
1188 29 Feb 08 markus 84        @returns A dynamically allocated %classifier, which has
1188 29 Feb 08 markus 85        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 92        \brief Make predictions for unweighted test data.
4200 19 Aug 22 peter 93
1188 29 Feb 08 markus 94        Samples in \a data are predicted and predictions for all
1188 29 Feb 08 markus 95        classes are returned in \a result.  The test data \a data
1188 29 Feb 08 markus 96        should have one column per test sample and one row for each
1188 29 Feb 08 markus 97        variable measured for the test samples. The rows of \a data
1188 29 Feb 08 markus 98        should be ordered identical to the rows of the data used to
1188 29 Feb 08 markus 99        train the %classifier, so that a given row corresponds to the
1188 29 Feb 08 markus 100        same variable for both training and test data. The predictions
1188 29 Feb 08 markus 101        in \a result have one column for each sample in \a data,
1188 29 Feb 08 markus 102        ordered in the same order, and one row for each class as
1188 29 Feb 08 markus 103        defined by the targets used to train the %classifier. Derived
1188 29 Feb 08 markus 104        classes should implement this function such that unweighted
1188 29 Feb 08 markus 105        calculations are used throughout when both training and test
1188 29 Feb 08 markus 106        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 112        \brief Make predictions for weighted test data.
4200 19 Aug 22 peter 113
1188 29 Feb 08 markus 114        Both \a data and \a result follow the description for
1188 29 Feb 08 markus 115        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 121        \brief Train the %classifier using unweighted training data with known
4200 19 Aug 22 peter 122        targets.
4200 19 Aug 22 peter 123
1188 29 Feb 08 markus 124        The training data \a data should have one column per training
1188 29 Feb 08 markus 125        sample and one row for each variable measured for the training
1188 29 Feb 08 markus 126        samples. The size of \a target should be the number of samples
1188 29 Feb 08 markus 127        in \a data and \a target should contain the class for each
1188 29 Feb 08 markus 128        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 133        \brief Train the %classifier using weighted training data with
4200 19 Aug 22 peter 134        known targets.
4200 19 Aug 22 peter 135
1188 29 Feb 08 markus 136        Both \a data and \a targets should follow the description for
1188 29 Feb 08 markus 137        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