ToPS
DecodableModel.hpp
00001 /*
00002  *       DecodableModel.hpp
00003  *
00004  *       Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br>
00005  *                      Ígor Bonádio <ibonadio@ime.usp.br>
00006  *                      Vitor Onuchic <vitoronuchic@gmail.com>
00007  *                      Alan Mitchell Durham <aland@usp.br>
00008  *
00009  *       This program is free software; you can redistribute it and/or modify
00010  *       it under the terms of the GNU  General Public License as published by
00011  *       the Free Software Foundation; either version 3 of the License, or
00012  *       (at your option) any later version.
00013  *
00014  *       This program is distributed in the hope that it will be useful,
00015  *       but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *       GNU General Public License for more details.
00018  *
00019  *       You should have received a copy of the GNU General Public License
00020  *       along with this program; if not, write to the Free Software
00021  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022  *       MA 02110-1301, USA.
00023  */
00024 
00025 #ifndef DECODABLE_MODEL_HPP
00026 #define DECODABLE_MODEL_HPP
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include "ProbabilisticModel.hpp"
00031 #include "Sequence.hpp"
00032 #include "util.hpp"
00033 #include "SparseMatrix.hpp"
00034 #include <boost/shared_ptr.hpp>
00035 
00036 namespace tops {
00038   class DLLEXPORT DecodableModel : public ProbabilisticModel  {
00039   public:
00040     DecodableModel(){};
00041     virtual ~DecodableModel(){};
00042 
00043     virtual double evaluate(const Sequence & s, unsigned int begin, unsigned int end) const;
00044 
00045     virtual Sequence & choose(Sequence & h, int size) const;
00046 
00047     virtual Sequence & choose(Sequence & h, Sequence & path,  int size) const;
00048 
00049     virtual Sequence & choose(Sequence & h, Sequence & path,  int i, int size) const;
00050 
00051 
00053     virtual double forward(const Sequence & s, Matrix &alpha) const = 0;
00054 
00056     virtual double backward(const Sequence & s, Matrix &beta) const = 0;
00057 
00059     virtual double viterbi (const Sequence &s, Sequence &path, Matrix & gamma) const = 0;
00060 
00062       virtual void choosePath(const Sequence &s, Sequence &path);
00063 
00065     virtual void posteriorProbabilities (const Sequence &s, Matrix & probabilities) const;
00066     virtual void posteriorProbabilities (const Sequence &s, SparseMatrixPtr probabilities) const;
00067     virtual void posteriorProbabilities (const Sequence &s, fMatrix &probabilities) const;
00068 
00069     virtual float MEAPred(const Sequence &s, Sequence &path);
00070     virtual float MEAPred(const Sequence &s, Sequence &path, SparseMatrixPtr postProbs);
00071 
00073     virtual void posteriorDecoding (const Sequence &s, Sequence &path, Matrix & probabilities) const;
00074 
00076 
00077     virtual Sequence &  chooseObservation ( Sequence & h,int i, int state ) const = 0;
00078 
00080     virtual int chooseState(int state ) const = 0;
00081 
00083     virtual int chooseFirstState() const = 0;
00084 
00086     virtual std::string getStateName(int state) const = 0;
00087 
00089     virtual AlphabetPtr getStateNames() const = 0;
00090 
00091     virtual DecodableModel* decodable() {
00092       return this;
00093     }
00094   };
00095   typedef boost::shared_ptr<DecodableModel>  DecodableModelPtr;
00096 }
00097 
00098 #endif