330 likes | 475 Views
Algorithms for H idden M arkov M odels milidiu@inf.puc-rio.br. PUC-Rio University. Agenda. Algorithms Forward Modified Forward Backward Forward-Backward. Language Model. HMM Structure P(x1, x2, x3, x4, o1, o2, o3, o4)
E N D
Algorithms for Hidden Markov Models milidiu@inf.puc-rio.br PUC-Rio University
Agenda • Algorithms • Forward • Modified Forward • Backward • Forward-Backward
Language Model • HMM Structure P(x1, x2, x3, x4, o1, o2, o3, o4) P(x4 | x3).P(x3 | x2).P(x2 | x1).P(x1).P(o1| x1).P(o2| x2).P(o3| x3).P(o4| x4) X1 X2 X3 X4 O1 O2 O3 O4
Language Model • Problem P(o1, o2, o3, o4) = ? P(x1). P(x2 | x1). P(x3 | x2). P(x4 | x3). P(o1| x1).P(o2| x2).P(o3| x3).P(o4| x4) X1 X2 X3 X4 O1 O2 O3 O4
Language Model • Problem P(o1, o2, o3, o4) = ? P(x1). P(x2 | x1). P(x3 | x2). P(x4 | x3). P(o1| x1).P(o2| x2).P(o3| x3).P(o4| x4) • Trivial Solution x1 x2 x3 x4P(x1, x2, x3, x4, o1, o2, o3, o4) N 4
Chain P(x1, x2, x3, x4, o1, o2, o3, o4) P(x1). P(x2 | x1). P(x3 | x2). P(x4 | x3). P(o1| x1).P(o2| x2).P(o3| x3).P(o4| x4)
Subchain P(x1, x2, x3, o1, o2, o3) x4 o4P(x1). P(x2 | x1). P(x3 | x2). P(x4 | x3). P(o1| x1).P(o2| x2).P(o3| x3).P(o4| x4) P(x1).P(x2 | x1).P(x3 | x2).P(o1| x1).P(o2| x2).P(o3| x3). x4 P(x4 | x3).o4P(o4| x4) P(x1).P(x2 | x1).P(x3 | x2).P(o1| x1).P(o2| x2).P(o3| x3). x4 P(x4 | x3).1 P(x1).P(x2 | x1).P(x3 | x2).P(o1| x1).P(o2| x2).P(o3| x3).1
Subchain P(x1, x2, x3, o1, o2, o3) P(x1).P(x2 | x1).P(x3 | x2).P(o1| x1).P(o2| x2).P(o3| x3)
Structural Decomposition P(x1, x2, x3, x4, o1, o2, o3, o4) = P(x4 | x3). P(x1).P(x2 | x1).P(x3 | x2).P(o1| x1).P(o2| x2).P(o3| x3). P(o4| x4)
Structural Decomposition P(x1, x2, x3, x4, o1, o2, o3, o4) = P(x4 | x3). P(x1, x2, x3, o1, o2, o3). P(o4| x4)
Structural Decomposition chain P(x1, x2, x3, x4, o1, o2, o3, o4) = P(x1, x2, x3, o1, o2, o3) . P(x4 | x3) . P(o4| x4) subchain transition emission
Factoring Trick P(o1, o2, o3, o4) x4 x3 x2 x1P(x1, x2, x3, x4, o1, o2, o3, o4) x4 x3 x2 x1P(x1,x2,x3,o1,o2,o3).P(x4 | x3).P(o4| x4) x4P(o4| x4) x3P(x4 | x3)x2 x1P(x1,x2,x3,o1,o2,o3) x4P(o4| x4) x3P(x4 | x3).P(x3, o1, o2, o3)
Recursive Factoring Trick P(x3, o1, o2, o3) x2 x1P(x1, x2, x3, o1, o2, o3) x2 x1P(x1, x2, o1, o2).P(x3 | x2).P(o3| x3) P(o3| x3) x2P(x3 | x2)x1P(x1, x2,o1, o2) P(o3| x3) x2P(x3 | x2).P(x2, o1, o2)
Recursive Factoring Trick P(x2, o1, o2) x1P(x1, x2,o1, o2) x1P(x1, o1).P(x2 | x1).P(o2| x2) P(o2| x2) x1P(x2 | x1)P(x1,o1)
Recursive Factoring Trick P(x1, o1) = P(o1| x1).P(x1)
Factoring Trick • P(x1, o1) x1 = 1..N = P(o1| x1).P(x1) • P(x2, o1, o2) x2 = 1..N = P(o2| x2) x1P(x2 | x1)P(x1,o1) • P(x3, o1, o2, o3) x3 = 1..N = P(o3| x3) x2P(x3 | x2).P(x2, o1, o2) • P(x4, o1, o2, o3, o4) x4 = 1..N = P(o4| x4) x3P(x4 | x3).P(x3, o1, o2, o3) • P(o1, o2, o3, o4) = x4P(x4, o1, o2, o3, o4)
Xk Dynamic Programming N.n P(o1, … , ok, xk) = P(o1, … , ok-1, xk-1).P(xk | xk-1 ).P(ok | xk)
Xk-1 Advance & Emit P(o(k), xk) = P(o(k-1), xk-1) . P(xk | xk-1 ) .P(ok | xk)
Xn Final P(o1, … , on) = P(o1, … , on, xn)
X(k-1) X(k-1) X(k-2) Xk-1 Xk-1 Correctness • P(o(k), xk) = P(o(k), x(k-1), xk) = P(o(k), x(k-1))P(xk | xk-1).P(ok | xk) = P(ok | xk). P(xk | xk-1).P(o(k) , x(k-2), xk-2) = P(ok | xk). P(xk | xk-1) . P(o(k) , xk-2)
j i Forward Procedure k(i) P(o(k), Xk=i) i = 1,…,N 1(i) P(o1| X1=i).P(X1=i) k = 2,…,n i = 1,…,N k(i) P(ok| Xk=i). P(Xk=i| Xk-1=j).k-1(j) P(o(n)) n(i) N.n
Modified Recursive Factoring Trick P(x3, o1, o2) x2 x1o3P(x1, x2, x3, o1, o2, o3) x2 x1P(x1, x2, o1, o2).P(x3 | x2) o3P(o3|x3) x2P(x3 | x2)x1P(o2|x2).P(x1, x2,o1) x2P(x3 | x2). P(o2|x2).P(x2, o1)
Modified Factoring Trick • P(x1) x1 = 1..N • P(x2, o1) x2 = 1..N = x1P(x2 | x1) P(o1| x1)P(x1) • P(x3, o1, o2) x3 = 1..N = x2P(x3 | x2) P(o3| x3)P(x2, o1) • P(x4, o1, o2, o3) x4 = 1..N = x3P(x4 | x3) P(o4| x4)P(x3, o1, o2) • P(o1, o2, o3, o4) = x4P(o4| x4)P(x4, o1, o2, o3)
j Modified Forward Procedure *k(i) P(o(k), Xk+1=i) i = 1,…,N *0(i) P(X1=i) k = 1,…,n-1 i = 1,…,N *k(i) P(ok| Xk=j).P(Xk+1=i| Xk=j). *k-1(j) P(o(n)) P(on| Xn=j). *n-1(j) N.n j
Backward Procedure • Use Reverse Chain • Apply Modified Forward Procedure • Convert transition probabilities to direct chain
Modified Reverse Factoring Trick P(x3, o4, o5) x4 x5o3P(x3, x4, x5, o3, o4, o5) x4 x5P(x4, x5, o4, o5).P(x3 | x4) o3P(o3|x3) x4P(x3 | x4)x5P(o4|x4).P(x5, x4,o5) x4P(x3 | x2). P(o4|x4).P(x4, o5)
Modified Reverse Factoring Trick P(x3, o4, o5) / P(x3) x4 x5o3P(x3, x4, x5, o3, o4, o5) / P(x3) x4 x5P(x4, x5, o4, o5).P(x3 | x4) o3P(o3|x3)/P(x3) x4 [P(x3 | x4)/P(x3)] x5P(o4|x4).P(x5, x4,o5) x4 [P(x4 | x3)/P(x4)]. P(o4|x4).P(x4, o5) x4P(x4 | x3). P(o4|x4).P(x4, o5) / P(x4)
Modified Reverse Factoring Trick P(o4, o5 | x3) x4 x5o3P(x3, x4, x5, o3, o4, o5) / P(x3) x4 x5P(x4, x5, o4, o5).P(x3 | x4) o3P(o3|x3)/P(x3) x4 [P(x3 | x4)/P(x3)] x5P(o4|x4).P(x5, x4,o5) x4 [P(x4 | x3)/P(x4)]. P(o4|x4).P(x4, o5) x4P(x4 | x3). P(o4|x4).P(o5 | x4)
j j Backward Procedure k(i) P(o(k+1)| Xk=i) i = 1,…,N n(i) 1 k = n,…,1 i = 1,…,N k(i) P(Xk+1=j| Xk=i).P(ok+1|Xk+1=j).k+1(j) P(o(n)) P(X1=j).P(o1|X1=j).1(j) N.n
Correctness • Reverse Chain • Modified forward procedure • *k(i) P(o(k+1), Xk=i) • Probabilities from thedirect chain k(i) = P(o(k+1), Xk=i) / P(Xk=i) • k(i) P(o(k+1)| Xk=i)
Correctness k(i) P(ok+1,…,on| Xk=i) k(i) = P(ok+1,…,on, Xk=i) / P(Xk=i) k(i) = xk+1 P(ok+1| Xk+1=j)P(Xk=i| Xk+1=j)*k+1(j) /P(Xk=i) k(i) = xk+1 P(ok+1| Xk+1=j) [P(Xk=i| Xk+1=j)/P(Xk=i)] *k+1(j) k(i) = xk+1 P(ok+1| Xk+1=j) [P(Xk+1=j| Xk=i)/P(Xk+1=j)] *k+1(j) k(i) = xk+1 P(ok+1| Xk+1=j) P(Xk+1=j| Xk=i) *k+1(j) / P(Xk+1=j) k(i) = xk+1 P(ok+1| Xk+1=j) P(Xk+1=j| Xk=i) k+1(j)
i Combined Procedure P(o(n)) k(i).k(i)
Summary • Divide & Conquer • Recursion elimination • Dynamic programming • Four procedures • Forward • Modified Forward • Backward • Combined