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

ltiSupervisedSequenceClassifier.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 .......: ltiSupervisedSequenceClassifier.h
00027  * authors ....: Peter Doerfler
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 29.08.2001
00030  * revisions ..: $Id: ltiSupervisedSequenceClassifier.h,v 1.3 2006/02/07 18:27:33 ltilib Exp $
00031  */
00032 
00033 
00034 #ifndef _LTI_SUPERVISEDSEQUENCECLASSIFIER_H_
00035 #define _LTI_SUPERVISEDSEQUENCECLASSIFIER_H_
00036 
00037 #include "ltiClassifier.h"
00038 #include "ltiVector.h"
00039 #include "ltiSequence.h"
00040 
00041 #include <vector>
00042 
00043 namespace lti {
00044 
00045   /**
00046    * Abstract class, parent of all supervised classifiers for sequences.
00047    * This class defines the interface for training methods of classifiers
00048    * that work on time series.
00049    */
00050   class supervisedSequenceClassifier : public classifier {
00051 
00052   public:
00053 
00054     /**
00055      * default constructor
00056      */
00057     supervisedSequenceClassifier();
00058 
00059     /**
00060      * copy constructor
00061      * @param other the object to be copied
00062      */
00063     supervisedSequenceClassifier(const supervisedSequenceClassifier& other);
00064 
00065     /**
00066      * returns the name of this type ("supervisedSequenceClassifier")
00067      */
00068     virtual const char* getTypeName() const;
00069 
00070     /**
00071      * copy data of "other" functor.
00072      * @param other the functor to be copied
00073      * @return a reference to this functor object
00074      */
00075     supervisedSequenceClassifier& copy(const supervisedSequenceClassifier& other);
00076     /**
00077      * Alias for "copy".
00078      * @param other the functor to be copied
00079      * @return a reference to this functor object
00080      */
00081     inline supervisedSequenceClassifier& operator=(const supervisedSequenceClassifier& other) {
00082       return copy(other);
00083     }
00084 
00085     /**
00086      * returns used parameters
00087      */
00088     const parameters& getParameters() const;
00089 
00090     /**
00091      * Supervised sequence training.
00092      * The sequences in the <code>input</code> %vector are used for training
00093      * the %sequence %classifier. Each %sequence is associated with an id
00094      * given in the %vector <code>ids</code>.
00095      * @param input %vector of training %sequences
00096      * @param ids the classes of the training sequences
00097      * @return true if successful, false otherwise.  (if false you can check
00098      *              the error message with getStatusString())
00099      */
00100     virtual bool train(const std::vector< sequence<dvector> > &input,
00101                        const ivector& ids) = 0;
00102 
00103     /**
00104      * Classification.
00105      * Classifies the %sequence of features and returns the outputVector with
00106      * the classification result. Since %sequence classifiers usually keep
00107      * an inner state, this method is not const.
00108      * @param observations the %sequence to be classified
00109      * @param result the result of the classification
00110      * @return false if an error occurred during classification else true
00111      */
00112     virtual bool classify(const sequence<dvector>& observations,
00113                           outputVector& result) = 0;
00114 
00115 
00116   protected:
00117 
00118     /**
00119      * Sets the outputTemplate probability distributions according to
00120      * the classification of the given data. The distributions are
00121      * built by the follwing rule: <p>
00122      * <ol>
00123      * <li>Classify next data sequence</li>
00124      * <li>For the position in the output with the highest probability
00125      *     increase the count for the actual id by one.</li>
00126      * <li>While there is more data go back to 1</li>
00127      * <li>For each position: divide each count by total number of counts</li>
00128      * </ol>
00129      * This results in a distribution over the ids that caused highest
00130      * probability for each position of the output.
00131      * @param outSize size of the outputTemplate
00132      * @param data train of validation data %sequences
00133      * @param ids ids of the data-vectors
00134      * @returns false upon error
00135      */
00136     bool makeOutputTemplate(const int& outSize,
00137                             const std::vector< sequence<dvector> >& data,
00138                             const ivector& ids);
00139   };
00140 }
00141 
00142 #endif

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