Escolar Documentos
Profissional Documentos
Cultura Documentos
Pi19404
March 13, 2014
Contents
Contents
Hidden Markov Models with continuous emission
0.1 Introduction . . . . . . . . . . . . . . . 0.2 Continuous Emission . . . . . . . . 0.2.1 Gaussian Mixture Models 0.2.2 Forward Algorithm . . . . 0.3 Code . . . . . . . . . . . . . . . . . . . . . References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 3 5 5 8 8
2|8
At each time step the system generates a hidden state cording to a a state to state transition matrix T .
i;j t
X act
Once x has been generated the system generates a hidden cluster y according to the state to emission probability distribution.
t
Gaussian mixture models are used to model a multi-modal density function in Euclidean space. Each hidden state is associated with emission probability distribution.
3|8
= x1; : : : ; x ; n 2 N
n
P (yjx ) =
Y i
X=1
k
a ( ;
i;k i;k
i;k
i;k
is a vector of dimension
i;k
is a matrix of size
DxD
Given we have a observation Y we need to determine the probability that observation is emitted by the hidden state X that is given by the modeled conditional distribution. This distribution is used to model the emission probability. Thus the continuous emission hidden Markov model is specified by transition matrix,initial probability matrix and emission probability distribution specified by Gaussian mixture model.
MatrixXf _transition; MatrixXf _initial; vector<GaussianMixture> _emission; int _nstates; int _nobs;
Let M be the number of hidden states,possible discrete value the random variable X can take.
n
Let
With a continuous HMM B corresponds to a family of parametric distributions p () where 2 R and B = (1 ; : : : ; ). For each hidden state we have a associated parametric distribution.
P (y; ) =
Y i
Xa
k
i;k
( ;
i;k
i;k
Another interpretation of above representation is,that hidden state i consists of hidden subsets k 2 N
4|8
Again the task is the present article is sequence classification. For the implementation we require implementation of Gaussian Mixture model and then see the modifications required in the forward/backward algorithm for continuous emission models.
We can consider this to be a soft-clustering process where a continuous random vector x is assigned to clusters specified with the mixture models with some probability.
n
The clusters can be considers as hidden discrete emission which again emits a continuous random vector which is truly being observed. Thus we can consider than we have a another hidden latent variable which is the discrete emission specified by the cluter. The Class GaussianMixture which can be found in OpenVision Library which encapsulates Gaussian Mixture model is used to model the emission probabilities
P (y1 ; : : : ; y
(z
) = P (x1; : : : ; x ; z )(z ) =
n n n n n
X (Z
n1
1 )P (x jz )P (z jz 1 )
n n n n
The quantity P (x jz ) was take from emission matrix in case of discrete hidden Markov model.
5|8
i;k
Remaining computation remain the same,just instead of a lookup table in case of discrete distribution we have to perform computation according to model of parametric distribution in case of continuous observation variable. To verify the code the scikit-learn -a ptyhon machine learning package was used consider the following hidden Markov model for sequence classification.
#number of hidden states _nstates=2; #number of emissions per state _nmix=2; #length of the feature vector ndim=3; #transition probability model.transmat_=[[0.9,0.1],[0.1,0.9]]; #inital state probability model.startprob=[0.5,0.5]; #multivariate Gaussian for emission 1 a1=GMM(n_components=_nmix,covariance_type='full'); #the mean vector a1.means_=np.array([[ 0.08513302,-0.02109036,-0.54525889], [-0.02646832,0.01030935,0.55921764]]); #the covariance vector a1.covars_=np.array([[ [1.6045371 ,0,0],[0, 0.95491166,0],[0,0, 0.76062784]] [ [0.63467475,0,0],[0, 1.03482635,0],[0,0, 0.53010913]]]); #the mixture weights a1.weights_=[0.48161747,0.51838253];
#multivariate Gaussian for emission 2 a2=GMM(n_components=_nmix,covariance_type='full'); a2.means_=np.array([[ 0.06263125, -0.01238598, -0.38820614], [ 0.3781768 , -0.29539352, 0.84720285]]); a2.covars_=np.array([[ [0.66081899, 0,0],[0,1.3027587,0],[0,0, 0.68465955]], [ [1.23561827,0,0],[ 0, 0.55178899,0],[ 0,0,0.80040462]]]); a2.weights_=[ 0.74733838, 0.25266162]; model.gmms_[0]=a1; model.gmms_[1]=a2; #input feature vector sequence x=[[0.3,0.4,0.5],[0.1,0.2,0.3],[0.4,0.4,0.6]];
6|8
int hmm_test1(int argc,char **argv) { Config cfg; // Read the file. If there is an error, report it and exit. try { cfg.readFile(argv[1]); } catch(const FileIOException &fioex) { std::cerr << "I/O error while reading file." << std::endl; return(EXIT_FAILURE); } catch(const ParseException &pex) { std::cerr << "Parse error at " << pex.getFile() << ":" << pex.getLine() << " - " << pex.getError() << std::endl; return(EXIT_FAILURE); } //defining the object for continuous emission hmm ocv::CHMM hmm1; //load the parameters of hmm hmm1.loadConf(cfg,"hmm1"); Mat sequence=Mat(3,3,CV_32FC1); sequence.at<float>(0,0)=0.3; sequence.at<float>(0,1)=0.4; sequence.at<float>(0,2)=0.5; sequence.at<float>(1,0)=0.1; sequence.at<float>(1,1)=0.2; sequence.at<float>(1,2)=0.3; sequence.at<float>(2,0)=0.4; sequence.at<float>(2,1)=0.4; sequence.at<float>(2,2)=0.6;
7|8
The result estimated from the developed code is in accordance with the results provided by the scikit-learn package.
0.3 Code
The class CHMM encapsulates the continuous emission hidden Markov model.The class can be found in files hmm.cpp and hmm.hpp files in the OpenVision :A Machine vision library at https:// github.com/pi19404/OpenVision in ImgML subdirectory. The configuration files can be found in the conf subdirectory of the repository.
8|8