Professional Documents
Culture Documents
l5 HMM Hand
l5 HMM Hand
l5 HMM Hand
Wrap-Up
Davide Bacciu
Dipartimento di Informatica
Università di Pisa
bacciu@di.unipi.it
Lecture Plan
Sequences
Markov Chain
First-Order Markov Chain
Directed graphical model for sequences s.t. element Xt only
depends on its predecessor in the sequence
X
P(Y =y) = P(Y = y, S = s)
s
X
= {P(S1 = s1 )P(Y1 = y1 |S1 = s1 )
s1 ,...,sT
T
)
Y
P(St = st |St−1 = st−1 )P(Yt = yt |St = st )
t=2
Generative models for sequences
Hidden Markov Models
Learning and Inference in HMM
Wrap-Up
Max-Product Inference in HMM
HMMs as Automata
Definition (Smoothing)
Given a model θ and an observed sequence y, determine the
distribution of the t-th hidden state P(St |Y = y, θ)
Definition (Learning)
Given a dataset of N observed sequences D = {y1 , . . . , yN }
and the number of hidden states C, find the parameters π, A
and B that maximize the probability of model θ = {π, A, B}
having generated the sequences in D
Forward-Backward Algorithm
Smoothing - How do we determine the posterior P(St = i|y)?
Exploit factorization
P(St = i|y) ∝P(St = i, y) = P(St = i, Y1:t , Yt+1:T )
= P(St = i, Y1:t )P(Yt+1:T |St = i) = αt (i)βt (i)
Learning in HMM
Learning HMM parameters θ = (π, A, B) by maximum likelihood
N
Y
L(θ) = log P(Yn |θ)
n=1
N X
Y Tn
Y
= log P(S1n )P(Y1n |S1n ) P(Stn |St−1
n
)P(Ytn |Stn )
n=1 s1n ,...,sTn t=2
n
Expectation-Maximization
Iterate 2 steps until |Lc (θ)it − Lc (θ)it−1 | < (or stop if maximum
number of iterations is reached)
Generative models for sequences
Hidden Markov Models
Learning and Inference in HMM
Wrap-Up
Max-Product Inference in HMM
E-Step (I)
Compute the expectation of the complete log-likelihood w.r.t
indicator variables ztin assuming (estimated) parameters
θt = (π t , At , B t ) fixed at time t (i.e. constants)
E-Step (II)
αt (i)βt (i)
γt (i) = P(St = i|Y) = PC
j=1 αt (j)βt (j)
M-Step (I)
M-Step (II)
State distributions
PN PT n n PN n
n=1 t=2 γt,t−1 (i, j) n=1 γ1 (i)
Aij = PN PT n n and πi =
n=1 t=2 γt−1 (j)
N
Decoding Problem
Viterbi Algorithm
An efficient dynamic programming algorithm based on a
backward-forward recursion
An example of a max-product message passing algorithm
t−1 (st−1 ) = max P(Yt |St = st )P(St = st |St−1 = st−1 )t (st ),
st
Coupled HMM
HMM in Matlab
HMM in Python
Next Lecture