GestureRecognition/abstractrecogniser.h

Go to the documentation of this file.
00001 /*  -*- c++ -*-  (for Emacs)
00002  *
00003  *  abstractrecogniser.h
00004  *  Digest
00005  * 
00006  *  Created by Aidan Lane on Mon Jul 11 2005.
00007  *  Copyright (c) 2005-2006 Optimisation and Constraint Solving Group,
00008  *  Monash University. All rights reserved.
00009  *
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00023  */
00024 
00025 #ifndef ABSTRACTRECOGNISER_H
00026 #define ABSTRACTRECOGNISER_H
00027 
00028 
00029 #include <QObject>
00030 
00031 #include <QHash>
00032 #include <QList>
00033 #include <QPointer>
00034 #include <QSet>
00035 #include <QString>
00036 #include <QVector>
00037 
00038 #include <jni.h>
00039 
00040 #include "Gesture/strokelist.h"
00041 #include "MvcDigestDb/dexperimentresultrecord.h" // for ClassProbabilityT
00042 
00043 #include "abstractfeature.h"
00044 
00045 class QByteArray;
00046 class QVariant;
00047 
00048 class DigestDbModel;
00049 class DTrainedRecogRecord;
00050 
00051 // Note: FeatureResultT is defined in abstractfeature.h
00052 typedef QVector<FeatureResultT>                       FeatureVec;
00053 typedef QVectorIterator<FeatureResultT>               FeatureVecIterator;
00054 typedef QMutableVectorIterator<FeatureResultT>        MutableFeatureVecIterator;
00055 
00056 
00057 class AbstractRecogniser : public QObject {
00058 
00059   Q_OBJECT
00060 
00061 public:
00062   AbstractRecogniser( JavaVM* jvm,
00063                       DigestDbModel* digestDbModel,
00064                       QObject* parent = 0 );
00065 
00066   virtual ~AbstractRecogniser();
00067 
00068   virtual QByteArray  key()         const = 0;
00069   virtual QString     title()       const = 0;
00070   virtual QString     description() const = 0;
00071 
00072   JavaVM*             jvm()             const;
00073   DigestDbModel*      digestDbModel()   const;
00074 
00075   const QSet<int>&                 trainingSet()     const;
00076   const QList<QByteArray>&         orderedFeatures() const;
00077   const QString&                   modelFilePath()   const;
00078   const QHash<QString, QVariant>&  params()          const;
00079 
00080   virtual QHash<QString, QVariant> defaultParams() const = 0;
00081 
00082   int currentTrainingProgress() const;
00083 
00084   virtual bool loadRecord( const DTrainedRecogRecord& record );
00085 
00086   virtual bool train( const QSet<int>& trainingSet,
00087                       const QList<QByteArray>& orderedFeatures,
00088                       const QString& modelFilePath,
00089                       const QHash<QString, QVariant>& params );
00090 
00091   virtual ClassProbabilities classify( const StrokeList& strokes );
00092 
00093 
00094 signals:
00095   void trainingProgressed( int progress );
00096 
00097 
00098 protected:
00099   virtual bool initTraining( const QList<QByteArray>& featureKeys,
00100                              const QHash<QString, QVariant>& params ) = 0;
00101   virtual bool examineSample( const FeatureVec& featureVec,
00102                               const QSet<int>& classes ) = 0;
00103   virtual bool finaliseTraining() = 0;
00104 
00105   virtual bool writeModelFile( const QString& fileName ) = 0;
00106   virtual bool readModelFile( const QString& fileName ) = 0;
00107 
00108   virtual Stroke flatten( const StrokeList& strokes );
00109   virtual ClassProbabilities classify( const FeatureVec& featureVec ) = 0;
00110 
00111   virtual FeatureVec extractFeatures( const Stroke& stroke );
00112 
00113 
00114 private:
00115   void rebuildFeatureInstances();
00116 
00117   JavaVM*                    m_jvm;
00118   QPointer<DigestDbModel>    m_digestDbModel;
00119 
00120   QSet<int>                  m_trainingSet;
00121   QList<QByteArray>          m_orderedFeatures;
00122   QString                    m_modelFilePath;
00123   QHash<QString, QVariant>   m_params;
00124 
00125   int                        m_trainingProgress;
00126 
00127   QVector<AbstractFeature*>  m_featureInstances;
00128 };
00129 
00130 
00131 #endif  // ! ABSTRACTRECOGNISER_H

Generated on Mon Jul 30 09:46:50 2007 for Digest by  doxygen 1.5.2