00001 #ifndef _LEFTTORIGHTHMM_H 00002 #define _LEFTTORIGHTHMM_H 00003 #include <vector> 00004 #include "../util/Matrix.h" 00005 00007 00010 class LeftToRightHMM 00011 { 00012 public: 00014 typedef std::vector<int> Observation; 00015 00020 LeftToRightHMM(size_t nStates, size_t alphabetSize); 00021 00027 double evaluate(Observation &obs); 00028 00034 void train(Observation &obs, size_t maxIterations); 00035 00040 const size_t getStateCount() const { return m_nStates; } 00041 00046 Matrix<double> &getTransitionProps() { return m_transitionProps; } 00047 00052 Matrix<double> &getOutputProps() { return m_outputProps; } 00053 00058 void setTransitionProps(const Matrix<double> &matrix) { m_transitionProps = matrix; } 00059 00064 void setOutputProps(const Matrix<double> &matrix) { m_outputProps = matrix; } 00065 00066 private: 00067 void adjustParameters(Observation &obs, std::vector<Matrix<double> > &xi); 00068 void calcXi(Observation &obs, Matrix<double> &alpha, 00069 Matrix<double> &beta, std::vector<Matrix<double> > &xi); 00075 Matrix<double> &forwardTrelis(Observation &obs); 00076 00082 Matrix<double> &backwardTrelis(Observation &obs); 00083 00084 size_t m_nStates; 00085 Matrix<double> m_transitionProps; 00086 Matrix<double> m_outputProps; 00087 Matrix<double> m_trelis; 00088 }; 00089 00090 #endif