Computational Intelligence, SS08 2 VO 442.070 + 1 RU 708.070 last updated:
General
Course Notes (Skriptum)
Online Tutorials
Practical Course Slides
Homework
 Assignments Scores Guidelines Archive
Exams
Animated Algorithms
Interactive Tests
Key Definitions
News
mailto:webmaster

# Homework 21: Hidden Markov Models

[Points: 8; Issued: 2004/06/04; Deadline: 2004/06/28; Tutor: Bernhard Tittelbach; Infohour: 2004/06/21, 12:00-13:00, Seminarraum IGI; Einsichtnahme: 2004/07/05, 12:00-13:00, Seminarraum IGI; Download: pdf; ps.gz]

Go through the tutorial Hidden Markov Models'' and download the accompanying MATLAB programs and data. The tasks issued in this homework are a subset of the tasks in the tutorial.

You can use a printout of this homework designation as a basis for your elaboration, and fill in your results in the tables. Add sheets of paper with descriptions of your observations, printouts of important MATLAB figures and of your Viterbi decoding function vit_ghmm.

• Load the Hidden Markov Models (HMMs) , and make a sketch of each of the models with states and transition probabilities. The parameters of the Markov models and of the Gaussian emission pdfs are stored in the file data.mat. Each HMM is stored as an object, e.g., hmm1, with fields hmm1.trans, hmm1.pi, hmm1.means, and hmm1.vars. The trans field contains the transition matrix , and the pi field the prior probability vector . The means field contains a matrix composed of mean vectors of the Gaussian emission pdfs, where each column of the matrix corresponds to one state of the HMM (to access the mean vector of, e.g., the second state from hmm1 use: hmm1.means(:,2). The vars field contains a 3 dimensional array of covariance matrices, where the third dimension corresponds to the state (e.g., to access the covariance matrix of state 1 use hmm1.vars(:,:,1)).
• Generate samples from the HMMs hmm1, hmm2, hmm3, and hmm4 and plot them with plotseq and plotseq2. In the resulting plots, the obtained sequences are represented by a yellow line where each point is overlaid with a colored dot. The different colors of the dots indicate the state from which a particular sample has been drawn.

» % Example: generate a sequence of length T from HMM1

» [X,ST] = sample_ghmm(hmm1,T)

» plotseq(X,ST) % View of both dimensions as separate sequences

» plotseq2(X,ST,hmm) % 2D view with location of Gaussian states

Draw several sequences for each HMM and compare. Compare the MATLAB figures with your sketch of the models and add (some of) them to your homework elaboration. Moreover, explain: What is the effect of the different transition matrices of the HMMs on the sequences obtained? Hence, what is the role of the transition probabilities in the HMM?

• Pattern recognition with HMM's: Classify the sequences , given in the file Xdata.mat, in a maximum likelihood sense with respect to the four Markov models , and . Use the function loglik_ghmm to compute the log-likelihood of a sequence with respect to a HMM . Store the results in a matrix (they will be used in the next section).

» % Example:

» logLike(1,1) = loglik_ghmm(X1,hmm1)

» logLike(1,2) = loglik_ghmm(X1,hmm2)

...

» logLike(i,j) = loglik_ghmm(Xi,hmmj)

...

Filling the logLike matrix can be done automatically with the help of loops:

>> for i=1:4,
for j=1:4,
stri = num2str(i);
strj = num2str(j);
eval([ 'logLike(' , stri , ',' , strj , ')=...
loglik_ghmm(X' , stri , ',hmm' , strj , ');' ]);
end;
end;

You can find the maximum of each row in the matrix with the MATLAB function max:
>> for i=1:4;
[v,index] = max(logLike(i,:));
disp(['X',num2str(i),' -> HMM',num2str(index)]);
end

 Sequence Most likely model
• Viterbi decoder: Write a MATLAB function to implement the Viterbi decoding algorithm to find the most likely state sequence for a given observation sequence for HMMs with Gaussian emission probabilities.
[loglik,path] = vit_ghmm(data,HMM)
% Compute the path and the log likelihood of a given model and
% observation sequence
%
% INPUT
%      data ... containing a sequence of observation
%         size(data)=[Number of features of each obs., length of sequence]
%      HMM is an object containing
%       HMM.trans = state transition probability matrix;
%       HMM.pi = prior probability vector;
%       HMM.means = mean vectors of Gaussian emission pdf for each state;
%       HMM.vars = covariance matrices of Gaussian em. pdf for each state;
% OUTPUT
%       loglik ... log likelihood of the most likely path for the data
%       path ... most likely path

• Use your function vit_ghmm to compute the most likely paths for the sequences with respect to each model . Use the function mk_ghmm_obs_lik to calculate the log-likelihood matrices, and compute the log-likelihoods along the most likely paths found by the Viterbi decoder. Note down your results below. Compare with the log-likelihoods obtained in the previous section with the function loglik_ghmm(...):

» diffL = logLike-logLikeViterbi

Log-likelihoods along the best path:

 Sequence Most likely model

Difference between log-likelihoods of a sequence given the model and log-likelihoods along the best path found by the Viterbi algorithm, :

 Sequence HMM1 HMM2 HMM3 HMM4

Is the likelihood along the best path a good approximation of the real likelihood of a sequence given a model ?