LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiSupervisedInstanceClassifier.h

00001 /*
00002  * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*----------------------------------------------------------------
00025  * project ....: LTI Digital Image/Signal Processing Library
00026  * file .......: ltiSupervisedInstanceClassifier.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 29.08.2001
00030  * revisions ..: $Id: ltiSupervisedInstanceClassifier.h,v 1.3 2006/02/07 18:26:55 ltilib Exp $
00031  */
00032 
00033 
00034 #ifndef _LTI_SUPERVISEDINSTANCECLASSIFIER_H_
00035 #define _LTI_SUPERVISEDINSTANCECLASSIFIER_H_
00036 
00037 #include "ltiClassifier.h"
00038 #include "ltiVector.h"
00039 #include "ltiMatrix.h"
00040 
00041 namespace lti {
00042 
00043   /**
00044    * Abstract class, parent of all supervised instance classifiers.
00045    * This class defines the interface for all supervised train methods which
00046    * are not dependant on time.
00047    */
00048   class supervisedInstanceClassifier : public classifier {
00049 
00050   public:
00051 
00052     /**
00053      * default constructor
00054      */
00055     supervisedInstanceClassifier();
00056 
00057     /**
00058      * copy constructor
00059      * @param other the object to be copied
00060      */
00061     supervisedInstanceClassifier(const supervisedInstanceClassifier& other);
00062 
00063     /**
00064      * returns the name of this type ("supervisedInstanceClassifier")
00065      */
00066     virtual const char* getTypeName() const;
00067 
00068     /**
00069      * copy data of "other" functor.
00070      * @param other the functor to be copied
00071      * @return a reference to this functor object
00072      */
00073     supervisedInstanceClassifier& copy(const supervisedInstanceClassifier& other);
00074     /**
00075      * Alias for "copy"
00076      * @param other the functor to be copied
00077      * @return a reference to this functor object
00078      */
00079     inline supervisedInstanceClassifier& operator=(const supervisedInstanceClassifier& other) {
00080       return copy(other);
00081     }
00082 
00083     /**
00084      * returns used parameters
00085      */
00086     const parameters& getParameters() const;
00087 
00088     /**
00089      * Supervised training.
00090      * The vectors in the <code>input</code> matrix
00091      * must be trained using as "known" classes the values given in
00092      * <code>ids</code>.
00093      * @param input the matrix with input vectors (each row is a training
00094      *              vector)
00095      * @param ids the output classes ids for the input vectors.
00096      * @return true if successful, false otherwise.  (if false you can check
00097      *              the error message with getStatusString())
00098      */
00099     virtual bool train(const dmatrix& input,
00100                        const ivector& ids) = 0;
00101 
00102     /**
00103      * Classification.
00104      * Classifies the feature and returns the outputVector with
00105      * the classification result.
00106      * @param feature the %vector to be classified
00107      * @param result the result of the classification
00108      * @return false if an error occurred during classification else true
00109      */
00110     virtual bool
00111       classify(const dvector& feature, outputVector& result) const =0;
00112 
00113 
00114   protected:
00115 
00116     /**
00117      * Sets the outputTemplate probability distributions according to
00118      * the classification of the given data. The distributions are
00119      * built by the follwing rule: <p>
00120      * <ol>
00121      * <li>Classify next data vector</li>
00122      * <li>For the position in the output with the highest probability
00123      *     increase the count for the actual id by one.</li>
00124      * <li>While there is more data go back to 1</li>
00125      * <li>For each position: divide each count by total number of counts</li>
00126      * </ol>
00127      * This results in a distribution over the ids that caused highest
00128      * probability for each position of the output.
00129      * @param outSize size of the outputTemplate
00130      * @param data train of validation data
00131      * @param ids ids of the data-vectors
00132      * @returns false upon error
00133      */
00134     bool makeOutputTemplate(const int& outSize,
00135                             const dmatrix& data,
00136                             const ivector& ids);
00137   };
00138 }
00139 
00140 #endif

Generated on Sat Apr 10 15:26:15 2010 for LTI-Lib by Doxygen 1.6.1