UTF8gbsn
The direct method of computing
P
(
O
∣
λ
)
P(O|\lambda)
P(O∣λ) is ultra expensive.
Fortunately, there are some other ways to get an appropriate
performance. Let’s look at the first improvement called forward method.
- Definition: The forward probability of
O = ( o 1 , o 2 , ⋯ , o t ) O=\left( o_1, o_2, \cdots, o_t \right) O=(o1,o2,⋯,ot) and i t = q i i_t=q_i it=qi is:
α t ( i ) = P ( o 1 , o 2 , ⋯ , o t , i t = q i ∣ λ ) \alpha_t(i)=P(o_1,o_2,\cdots, o_t,i_t=q_i|\lambda) αt(i)=P(o1,o2,⋯,ot,it=qi∣λ)
i
t
i_t
it means the state of step
t
t
t, and
q
i
∈
Q
q_i\in Q
qi∈Q means the exact state
of
i
t
i_t
it
Alg:
-
Input: λ = ( A , B , π ) \lambda=(A,B,\pi) λ=(A,B,π) and observation sequence O O O
-
Output: The probability of the observation sequence P ( O ∣ λ ) P(O|\lambda) P(O∣λ)
Steps:
-
initialization: α 1 ( i ) = π i b i ( o 1 ) , i ∈ ( 1 , 2 , ⋯ , N ) \alpha_1(i)=\pi_ib_i(o_1), i\in (1,2,\cdots, N) α1(i)=πibi(o1),i∈(1,2,⋯,N)
-
recursion:
α t + 1 ( i ) = ∑ j = 1 N ( α t ( j ) a j i ) b i ( o t + 1 ) , i ∈ ( 1 , 2 , ⋯ , N ) \alpha_{t+1}(i)=\sum_{j=1}^{N}(\alpha_t(j)a_{ji})b_i(o_{t+1}), i\in (1,2,\cdots, N) αt+1(i)=j=1∑N(αt(j)aji)bi(ot+1),i∈(1,2,⋯,N) -
stop: P ( O ∣ λ ) = ∑ i = 1 N α T ( i ) P(O|\lambda)=\sum_{i=1}^{N}\alpha_T(i) P(O∣λ)=i=1∑NαT(i)
The complexity of this algorithm is
O
(
N
2
T
)
O(N^2T)
O(N2T), which is lower than the
direct method’s
O
(
N
N
T
)
O(N^NT)
O(NNT).
Example:
Let’s consider a HMM
λ
=
(
A
,
B
,
π
)
\lambda=(A,B,\pi)
λ=(A,B,π),
Q
=
{
1
,
2
,
3
}
Q=\{1,2,3\}
Q={1,2,3},
V
=
{
r
e
d
,
w
h
i
t
e
}
V=\{red, white\}
V={red,white}.
A
=
[
0.5
0.2
0.3
0.3
0.5
0.2
0.2
0.3
0.5
]
B
=
(
0.5
0.5
0.4
0.6
0.7
0.3
)
π
=
(
0.3
0.4
0.4
)
A=\left. \begin{aligned} \left[ \begin{array}{ccc} 0.5 & 0.2 & 0.3 \\ 0.3 & 0.5 & 0.2 \\ 0.2 & 0.3 & 0.5 \end{array} \right] \end{aligned} \right. B=\left. \begin{aligned} \left( \begin{array}{cc} 0.5 & 0.5 \\ 0.4 & 0.6 \\ 0.7 & 0.3 \end{array} \right) \end{aligned} \right.\pi=\left. \begin{aligned} \left( \begin{array}{c} 0.3 \\ 0.4 \\ 0.4 \end{array} \right) \end{aligned} \right.
A=⎣⎡0.50.30.20.20.50.30.30.20.5⎦⎤B=⎝⎛0.50.40.70.50.60.3⎠⎞π=⎝⎛0.30.40.4⎠⎞ Let,
T
=
3
,
O
=
{
R
e
d
,
W
h
i
t
e
,
R
e
d
}
T=3, O=\{Red, White, Red\}
T=3,O={Red,White,Red}. How to use forward
method to calculate
P
(
O
∣
λ
)
P(O|\lambda)
P(O∣λ).
-
initialization α 1 ( 1 ) = π 1 b 1 ( o 1 ) = 0.2 × 0.5 = 0.1 α 1 ( 2 ) = π 2 b 2 ( o 1 ) = 0.4 × 0.4 = 0.1 a 1 ( 3 ) = π 3 b 3 ( o 1 ) = 0.4 × 0.7 = 0.28 \left. \begin{aligned} \alpha_1(1)&=\pi_1b_1(o_1)=0.2\times 0.5 = 0.1\\ \alpha_1(2)&=\pi_2b_2(o_1)=0.4\times 0.4 = 0.1\\ a_1(3)&=\pi_3b_3(o_1)=0.4\times 0.7 = 0.28 \end{aligned} \right. α1(1)α1(2)a1(3)=π1b1(o1)=0.2×0.5=0.1=π2b2(o1)=0.4×0.4=0.1=π3b3(o1)=0.4×0.7=0.28
-
forward α 2 ( 1 ) = [ ∑ i = 1 3 α 1 ( i ) a i 1 ] b 1 ( o 2 ) = 0.154 × 0.5 = 0.077 α 2 ( 2 ) = [ ∑ i = 1 3 α 1 ( i ) a i 2 ] b 2 ( o 2 ) = 0.184 × 0.6 = 0.1104 α 2 ( 3 ) = [ ∑ i = 1 3 α 1 ( i ) a i 3 ] b 3 ( o 2 ) = 0.202 × 0.3 = 0.0606 α 3 ( 1 ) = [ ∑ i = 1 3 α 2 ( i ) a i 1 ] b 1 ( o 3 ) = 0.04187 α 3 ( 2 ) = [ ∑ i = 1 3 α 2 ( i ) a i 2 ] b 2 ( o 3 ) = 0.03551 α 3 ( 3 ) = [ ∑ i = 1 3 α 2 ( i ) a i 3 ] b 3 ( o 3 ) = 0.05284 \left. \begin{aligned} &\alpha_2(1)=\left[ \sum_{i=1}^{3}\alpha_1(i)a_{i1}\right]b_1(o_2)=0.154 \times 0.5 = 0.077\\ &\alpha_{2}(2)=\left[\sum_{i=1}^{3} \alpha_{1}(i) a_{i 2}\right] b_{2}\left(o_{2}\right)=0.184 \times 0.6=0.1104\\ &\alpha_{2}(3)=\left[\sum_{i=1}^{3} \alpha_{1}(i) a_{i 3}\right] b_{3}\left(o_{2}\right)=0.202 \times 0.3=0.0606\\ &\alpha_{3}(1)=\left[\sum_{i=1}^{3} \alpha_{2}(i) a_{i 1}\right] b_{1}\left(o_{3}\right)=0.04187\\ &\alpha_{3}(2)=\left[\sum_{i=1}^{3} \alpha_{2}(i) a_{i 2}\right] b_{2}\left(o_{3}\right)=0.03551\\ &\alpha_{3}(3)=\left[\sum_{i=1}^{3} \alpha_{2}(i) a_{i 3}\right] b_{3}\left(o_{3}\right)=0.05284 \end{aligned} \right. α2(1)=[i=1∑3α1(i)ai1]b1(o2)=0.154×0.5=0.077α2(2)=[i=1∑3α1(i)ai2]b2(o2)=0.184×0.6=0.1104α2(3)=[i=1∑3α1(i)ai3]b3(o2)=0.202×0.3=0.0606α3(1)=[i=1∑3α2(i)ai1]b1(o3)=0.04187α3(2)=[i=1∑3α2(i)ai2]b2(o3)=0.03551α3(3)=[i=1∑3α2(i)ai3]b3(o3)=0.05284
-
stop: P ( O ∣ λ ) = ∑ i = 1 3 α 3 ( i ) = 0.13022 P(O \mid \lambda)=\sum_{i=1}^{3} \alpha_{3}(i)=0.13022 P(O∣λ)=i=1∑3α3(i)=0.13022