









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










In this lecture we will consider a very special graphical model: the Hidden Markov model (HMM). We will see a special case of the sum-product algorithm for inference, the so-called forward-backward algo- rithm, for computing the probability of a sequence of observations. This can also be used for classification: training multiple HMMs, one for each possible class, and then selecting the class that maximizes the prob- ability of the observed data. We also introduce the Viterbi algorithm, which finds the sequence of hidden states that maximize the probability of an observation. Finally, we see how to use maximum likelihood to learn parameters when training data is fully labeled (both outputs and hidden state), and also how to use expectation-maximization (EM) for training in the usual case of unobservable hidden states. In the setting of HMMs the EM algorithm is called the Baum-Welch algorithm.
Up to now, all the probabilistic models we have dealt with have been static models. They encode the probability distribution over the state of the world, and the observations seen by an agent, at a single point in time. In reality, the world evolves. We want to describe the way the world evolves in a probabilistic manner. This allows us to achieve a number of things. First of all, an agent can use a model of how the world changes to maintain a probability distribution over the state of the world. Rather than just relying on its current observations to reason about the state of the world, an agent can remember prior observations and use all of this information for inference about the current state of the world. For example, suppose a robot receives a sensor input that tells it there is an obstacle directly in front of it. Suppose that a moment later, it does not receive the same sensor input, even though the robot does not change position. Now, a robot that has to rely only on its current sensors will believe that there is no longer an obstacle in front of it. However, there are other explanations as to why the robot did not detect the obstacle in the second instance— for example, its sensor could be faulty (as many robotic sensors are). A robot that uses both its previous sensor input as well as the new one will have some degree of belief about the presence of the obstacle, that is more accurate than the one that ignores all previous sensor inputs. Hidden Markov Models (HMMs) are temporal probabilistic models that allow this type of reasoning. HMMs have many applications. An application is to the modeling of sequence data. Perhaps the most famous and widespread application of HMMs is to speech recognition. Other applications include to the classification of cursive writing into characters, to financial models of various kinds, and prediction of rainfall on successive days. Sequential data can also arise in other contexts, for example within biological data such as the sequencing on a DNA stand.
The basic assumption of HMMs is that the world passes through a sequence of states. The states through which the world passes are hidden, or unobserved. However, at each point in time we also get an observation, that in some way reflects on the current state of the world.
By way of motivation, let us first consider a couple of even simpler models of sequential data. The most simple is to ignore any relationship between events in subsequent periods. For example, we can construct a trivial probabilistic model in which a random observation Ot ∈ {NR, R} (no rain, rain) occurs independently on each successive day. As a Bayes Net, we have:
Shaded to indicate observed variables.
We would learn a separate parameter θR,t for the probability of rain on day t. Coupled with a stationarity assumption, then there are k − 1 parameters to learn when there are k possible observations, with P (Ot = k) = θk and
k θk^ = 1. To be clear:^ Ot^ is a random variable indicating the observation in period^ t, with domain { 1 ,... , k}. The set of observations will be indexed j. But suppose that we believe that whether or not it is raining today affects the probability that it will rain tomorrow. A Markov model would allow for this dependency, with
and P (O 1 , O 2 , O 3 ) = P (O 1 )P (O 2 | O 1 )P (O 3 | O 2 , O 1 ) = P (O 1 )P (O 2 | O 1 )P (O 3 | O 2 ), where we make the Markov assumption, that
P (Ot | O 1 ,... , Ot− 1 ) = P (Ot | Ot− 1 ) (1)
so that the probability of the next observation is independent of past observations given the observation on the immediately preceding day. Without any additional assumptions then we would need to learn separate parameters for the conditional probability in each period. But we could instead insist on stationarity, and
require P (Ot = j′^ | Ot− 1 = j) = θj,j′^ for all t, and with prior P (O 1 = j) = θ (1) j. Altogether we would have (k − 1)k + (k − 1) parameters. But this is still limiting. What if the probability of rain today depends on whether or not it has rained in the past few days? The problem here is that as we increase the dependency on the past the number of parameters we require grows exponentially. This is where HMMs come in. We instead introduce random variables Xt, on domain { 1 ,... , n}, where Xt is the hidden state in period t. (Don’t be confused– there are as many realizations hidden states as there are time periods, and each state can only be one of n states.) The set of possible states is indexed by i. Given this, we have the following graphical model:
As is familiar from the local conditional independence encoded by Bayes nets, in adopting this model we make the following conditional independence assumptions:
P (Ot | X 1 ,... , Xt, O 1 ,... , Ot− 1 ) = P (Ot | Xt) (2) P (Xt | X 1 ,... , Xt− 1 , O 1 ,... , Ot− 1 ) = P (Xt | Xt− 1 ) (3)
Terminal Node state 1 represents phoneme one (and is associated with a distribution on frequency vectors)
Each unit might roughly correspond to a different phoneme. This is a so-called “left to right” model because there is a topological ordering on states in the state-transition diagram. This examples illustrates the classification problem that we might seek to solve with HMMs. Given observations o 1 ,... , oT , over T periods, and C > 1 HMM models, each with different learned parameters θ 1 ,... , θC , then find
arg max c P (C = c | O 1 = o 1 ,... , OT = oT ) = arg max c P (O 1 = o 1 ,... , OT = oT | θc)P (C = c), (7)
where P (C = c) is the prior on class c.
We might also just want to predict the weather on the next day. This is the problem of prediction. Given observations o 1 ,... , oT , compute P (OT +1 | O 1 = o 1 ,... , OT = oT ).
For a second example application, suppose that we observe the sound “crunch” when a mouse in a multi- chambered maze finds food, and we want to reason about which room the mouse is in based on the sequence of “crunches.”
First of all, we might be interested in smoothing, which is the problem of given observations, o 1 ,... , oT , finding P (Xt | O 1 = o 1 ,... , OT = oT ) for t < T. For the special case of the current time period, this is the problem of filtering: given observations o 1 ,... , oT , compute P (XT | O 1 = o 1 ,... , OT = oT ). Note that the estimate of the probability of XT given observations o 1 ,... , oT will in general be different from the estimate of XT from smoothing given additional data, o 1 ,... , oT ′^ with T ′^ > T. The additional observations provide evidence about the hidden state in period T , and may “smooth” out the estimate. In addition, we might want the maximum likelihood explanation of the sequence of hidden states given the observations. This is, given observations o 1 ,... , oT , find the sequence of hidden states that
arg max x 1 ,...,xT P (X 1 = x 1 ,... , XT = xT | O 1 = o 1 ,... , OT = oT ) (8)
In our application, the maximum likelihood explanation effective segments the observations into time intervals for which all observations are most likely generated from the mouse being in the same room. Similarly, for the word recognition example, we segment the speech into different phonemes.
Central to efficient inference using HMMs is the forward-backward algorithm. This is nothing more than the sum-product algorithm for inference on Bayes nets applied to HMMs. HMMs are always polytrees and thus the sum-product algorithm is well defined. The forward-backward algorithm takes as input an observation sequence o 1 ,... , oT , and computes P (O 1 = o 1 ,... , OT = oT ), i.e., the probability that the sequence would be generated by the HMM model. Recall that the basic challenge is to compute this probability without explicitly summing out over all possible instantia- tions of variables X 1 ,... , XT. We will soon see many applications of this basic functionality, including most obviously to classification. The forward-backward algorithm can be conceptualized as passing so-called alpha messages, {αt(xt)} for each xt ∈ { 1 ,... , n}, forward from variable Xt to Xt+1, and beta messages {βt(xt)} for each xt ∈ { 1 ,... , n}, backward from variable Xt to Xt− 1 , with
αt(xt) = P (O 1 = o 1 ,... , Ot = ot, Xt = xt) (9) βt(xt) = P (Ot+1 = ot+1,... , OT = oT | Xt = xt), (10)
and where it is convenient to define βT (xT ) = 1 for all xT ∈ { 1 ,... , n}, for the special case of t = T. Note that forward-backward does not literally need to be implemented via message passing, but this is a conceptual way to understand the algorithm (and a good, readily distributed implementation for very large models). In our weather example, suppose that we have a sequence of three observations, for example NR, NR, R. The associated HMM along with the messages that will be computed and passed around are:
β 3 (x 3 ) = 1
α 1 (x 1 ) α 2 (x 2 ) α 3 (x 3 )
β 1 (x 1 ) β 2 (x 2 )
Key to the power of the algorithm is that the forward and backward messages can be computed locally. To see this, we can first adopt variable elimination with “forward” elimination order X 1 , X 2 and then X 3 :
P (O 1 = o 1 , O 2 = o 2 , O 3 = o 3 ) =
x 3
P (o 3 | x 3 )
x 2
P (x 3 | x 2 )P (o 2 | x 2 )
x 1
P (o 1 | x 1 )P (x 1 )P (x 2 | x 1 )
x 3
P (o 3 | x 3 )
x 2
P (x 3 | x 2 )P (o 2 | x 2 )g 1 (x 2 )
x 3
P (o 3 | x 3 )
x 2
P (x 3 | x 2 )α 2 (x 2 )
x 3
P (o 3 | x 3 )g 2 (x 3 )
x 3
α 3 (x 3 ),
We can also offer the following graphical view:
β 2 (x 2 ) = P (o 3 , o 4 |x 2 )
Complexity. How expensive are the forwards and backward algorithms? For both algorithms, the initialization and finishing steps are O(n) for n possible hidden states. Meanwhile, the loop is performed O(T ) times for T time periods. At each step in the loop, an O(n) computation is performed for each hidden state, and thus the total cost is O(n^2 T ).
So far this is all a bit abstract. We have this idea of a forward and backward pass, to compute these alpha and beta messages. But see that from the above, we have
P (O 1 = o 1 , O 2 = o 2 , O 3 = o 3 ) =
x 3
α 3 (x 3 ) =
x 3
α 3 (x 3 )β 3 (x 3 ) (13)
P (O 1 = o 1 , O 2 = o 2 , O 3 = o 3 ) =
x 1
P (O 1 = o 1 | X 1 = x 1 )P (X 1 = x 1 )β 1 (x 1 ) =
x 1
α 1 (x 1 )β 1 (x 1 ) (14)
More generally, we have
αt(xt)βt(xt) = P (o 1 ,... , ot, xt)P (ot+1,... , oT | xt) = P (o 1 ,... , ot | xt)P (xt)P (ot+1,... , oT | xt) = P (o 1 ,... , oT | xt)P (xt) = P (o 1 ,... , oT , xt)
and we see that
P (O 1 = o 1 ,... , OT oT ) =
xt
αt(xt)βt(xt), (15)
for any t ∈ { 1 ,... , T }. Therefore, we can use forward-backwards to compute the probability of a sequence of observations given a HMM. We can also perform smoothing, since
P (Xt = xt | O 1 = o 1 ,... , OT = oT ) =
P (O 1 = o 1 ,... , OT = oT , Xt = xt) P (O 1 = o 1 ,... , OT = oT )
∝ αt(xt)βt(xt) (16)
As a special case, we can perform filtering, since
P (XT = xT | O 1 = o 1 ,... , OT = oT ) ∝ αT (xT )βT (xT ) (17)
We can also perform prediction, with P (OT +1 = oT +1 | O 1 = o 1 ,... , OT = oT ) = ∑
xT
xT +
P (oT +1, xT , xT +1 | o 1 ,... , oT )
xT
xT +
P (oT +1 | xT , xT +1, o 1 ,... , oT )P (xT +1 | xT , o 1 ,... , oT )P (xT | o 1 ,... , oT )
xT
xT +
P (oT +1 | xT +1)P (xT +1 | xT )αT (xT )
One thing to notice about this is that αT (xT ) encapsulates all of the relevant information about the past observations o 1 ,... , oT for the purpose of prediction. Another useful calculation that we can perform with the alpha and beta values is
P (Xt− 1 = xt− 1 , Xt = xt | O 1 = o 1 ,... , OT = oT ) (18)
= P (o 1... , oT | xt− 1 , xt)P (xt− 1 , xt) P (o 1... , oT )
=
P (o 1 ,... , ot− 1 | xt− 1 )P (ot | xt)P (ot+1,... , oT | xt)P (xt | xt− 1 )P (xt− 1 ) P (o 1... , oT )
= αt− 1 (xt− 1 )P (ot | xt)P (xt | xt− 1 )βt(xt) P (o 1... , oT ) ∝ αt− 1 (xt− 1 )P (ot | xt)P (xt | xt− 1 )βt(xt) This will be used in the Baum-Welch algorithm for expectation-maximization to train a HMM given observation data (but unobserved hidden states.)
We now step through a numerical example, considering the weather domain and having observed sequence R, R (i.e., rain and then rain.) We run the forward and then the backward algorithm. Forward. First, α 1 (x 1 ) = P (o 1 | x 1 )P (x 1 ) and so we have X 1 P (R | X 1 ) P (X 1 ) α 1 (X 1 ) 1 0.75 0.7 0. 2 0.4 0.3 0. Then, we compute α 2 (x 2 ) = P (o 2 | x 2 )
x 1 P^ (x^2 |^ x^1 )α^1 (x^1 ) as X 1 X 2 P (X 2 | X 1 ) P (R | X 2 ) α 1 (X 1 ) ⊗ 1 1 0.8 0.75 0.525 0. 1 2 0.2 0.4 0.525 0. 2 1 0.1 0.75 0.12 0. 2 2 0.9 0.4 0.12 0. and then summing out x 1 , we obtain X 2 α 2 (X 2 ) 1 0.315+0.009=0. 2 0.042+0.0432=0. Backward. First β 2 (x 2 ) = 1. Then, β 1 (x 1 ) =
x 2 P^ (x^2 |^ x^1 )P^ (o^2 |^ x^2 )β^2 (x^2 ) and we compute X 1 X 2 P (X 2 | X 1 ) P (R | X 2 ) ⊗ 1 1 0.8 0.75 0. 1 2 0.2 0.4 0. 2 1 0.1 0.75 0. 2 2 0.9 0.4 0.
that led to an accident. We want to determine the most likely sequence of hidden states that may have produced the result. Since
P (x 1 ,... , xT | o 1 ,... , oT ) =
P (x 1 ,... , xT , o 1 ,... , oT ) P (o 1 ,... , oT )
and the denominator does not depend on x 1 ,... , xT , the problem is equivalent to finding the x 1 ,... , xT that maximizes the joint probability P (x 1 ,... , xT , o 1 ,... , oT ). We will solve this form of the problem. There is a direct analogy to the task solved by the forward-backward algorithm. There, we wanted to solve ∑
x 1 ,...,xT
P (x 1 ,... , xT , o 1 ,... , oT ) (22)
Here we want to solve
max x 1 ,...,xT P (x 1 ,... , xT , o 1 ,... , oT ) (23)
This “most likely explanation” task is solved using a dynamic programming algorithm called the Viterbi algorithm. We describe the algorithm here in its forward form. There is also a backward Viterbi algorithm. The basic idea is the same as for sum-product, except now we work by moving around a “max” operator rather than a “sum” operator. So, this is really a max-product algorithm (and we ultimately take logs to give numerical robustness, making it a max-sum algorithm.) For this, we return to the earlier example with three observations, and look to compute maxx 1 ,x 2 ,x 3 P (X 1 = x 1 , X 2 = x 2 , X 3 = x 3 , O 1 = o 1 , O 2 = o 2 , O 3 = o 3 ), which simplifies to:
max x 3 P (o 3 | x 3 ) max x 2 P (x 3 | x 2 )P (o 2 | x 2 ) max x 1 P (o 1 | x 1 )P (x 1 )P (x 2 | x 1 )
= max x 3 P (o 3 | x 3 ) max x 2 P (x 3 | x 2 )P (o 2 | x 2 )gmax 1 (x 2 )
= max x 3 P (o 3 | x 3 ) max x 2 P (x 3 | x 2 )v 2 (x 2 )
= max x 3 P (o 3 | x 3 )gmax 2 (x 3 )
= max x 3 v 3 (x 3 ),
where we see that v 2 (x 2 ) = P (o 2 | x 2 ) maxx 1 P (o 1 | x 1 )P (x 1 )P (x 2 | x 1 ) and v 3 (x 3 ) = P (o 3 | x 3 ) maxx 2 P (x 3 | x 2 )v 2 (x 2 ). Generalizing, we define the recursion for the forward Viterbi algorithm for HMMs:
vt+1(xt+1) = P (ot+1 | xt+1) max xt P (xt+1 | xt)vt(xt), (24)
for 1 ≤ t < T , and with v 1 (x 1 ) = P (o 1 | x 1 )P (x 1 ). Now, vt(xt) is passed forward from Xt to Xt− 1 for all xt ∈ { 1 ,... , n}. Note again that this message can be readily computed with local information to that variable. For t > 1, the value vt(xt) is computing:
vt(xt) = max x 1 ,...,xt− 1 P (x 1 ,... , xt, o 1 ,... , ot), (25)
and the likelihood of the sequence of observations up to and including time t, under the best possible expla- nation, if the hidden state at time t is xt. At time 1, there are no prior observations, and so the special meaning of v(x 1 ) is the likelihood of the observation at time t = 1 if the hidden state at time 1 is x 1. In order to finally reconstruct the sequence of states that is most likely, it is also important to store the best possible previous state, denoted zt− 1 (xt), given that the current state is xt:
zt− 1 (xt) = arg max xt− 1 P (xt | xt− 1 )vt− 1 (xt− 1 ) (26)
for t > 1. Note: the best state in period t is NOT that which simply maximizes vt(xt) because this ignores the coupling due to P (xt+1 | xt) between now and the future. Based on this, once we have looped forwards, computing vt(xt) and zt− 1 (xt) for periods 1 to T (skipping zt− 1 (xt) for period t = 1), we can reconstruct the solution x∗ 1 ,... , x∗ T. First, we can determine the state in the final period that is part of the most likely state sequence. This is the state with the highest probability, given that the best possible explanation is chosen for the previous states, and is exactly
x∗ T = arg max xT vT (xT ) (27)
Given x∗ T , we can loop backward towards the head of the HMM, using the stored z functions to choose the best possible previous state given the best possible current state; i.e., for t = T − 1 to 1, we set
x∗ t = zt(x∗ t+1) (28)
We can again visit our weather example to understand how the Viterbi algorithm plays out. Consider a three period example, in which the observed sequence is NR, NR, R. We would like to compute the most likely explanation. To initialize, we have v 1 (x 1 ) = P (o 1 | x 1 )P (x 1 ) and X 1 P (NR | X 1 ) P (X 1 ) v 1 (X 1 ) 1 0.25 0.7 0. 2 0.6 0.3 0. Now, v 2 (x 2 ) = P (o 2 | x 2 ) maxx 1 P (x 2 | x 1 )v 1 (x 1 ), and X 1 X 2 P (NR | X 2 ) P (X 2 | X 1 ) v 1 (X 1 ) ⊗ 1 1 0.25 0.8 0.175 0. 1 2 0.6 0.2 0.175 0. 2 1 0.25 0.1 0.18 0. 2 2 0.6 0.9 0.18 0. From this, we solve and find X 2 v 2 (X 2 ) z 1 (X 2 ) 1 max(0. 035 , 0 .0045) = 0. 035 1 2 max(0. 021 , 0 .0972) = 0. 0972 2 Then, v 3 (x 3 ) = P (o 3 | x 3 ) maxx 2 P (x 3 | x 2 )v 2 (x 2 ), and X 2 X 3 P (R | X 3 ) P (X 3 | X 2 ) v 2 (X 2 ) ⊗ 1 1 0.75 0.8 0.035 0. 1 2 0.4 0.2 0.035 0. 2 1 0.75 0.1 0.0972 0. 2 2 0.4 0.9 0.0972 0. and solving, we find X 3 v 3 (X 3 ) z 2 (X 3 ) 1 max(0. 021 , 0 .00729) = 0. 021 1 2 max(0. 0028 , 0 .035) = 0. 035 2 Now, reading off the solution, we have x∗ 3 = arg maxx 3 ∈S v 3 (x 3 ) = 2, x∗ 2 = z 2 (x∗ 3 ) = 2 and x∗ 1 = z 1 (x∗ 2 ) =
The initialization of parameters should be done randomly, but ensuring that no parameters are zero (and making them correct probabilities so the right things sum to one.) Going through the E → M → E → M →
... loop, the likelihood of the data weakly monotonically increases every EM cycle. As always the M-step is easy, with the estimated statistics Nˆi,j , Nˆi,i′ , and Nˆ (^) i(1) used to determine θnew by adopting them in place of the direct counts that are used in the maximum-likelihood algorithm. These parameters become θold^ for the next loop. To explain the E-step, it is helpful to define the so-called gamma values, which are the probabilities
γt(i) = P (Xt = i | O 1 = o 1 ,... , OT = oT ) (32) γt− 1 ,t(i, i′) = P (Xt− 1 = i, Xt = i′^ | O 1 = o1 ,... , OT = oT ) (33)
For the current θold^ , these probabilities can be computed for every training sequence o^ = (o 1 ,... , o`T ) via the forward-backward algorithm! These are exactly provided by Eqs. (17) and (18). So, in every iteration of the E-step, we run forward-backward over the HMM given the current parameters. Given this, the expected statistics are then computed as
Nˆi,j = E[Ni,j | D, θold^ ] =
`=
t:o`t =j
γt` (i), (34)
which is the expected number of times in the training data that j is output in state i, given θold^ , and
Nˆi,i′ = E[Ni,i′ | D, θold^ ] =
`=
t=
γt`− 1 ,t(i, i′), (35)
which is the expected number of times in the training data that a transition from i to i′^ occurs, given θold^ , and
i =^ E[N^
(1) i |^ D, θ
old (^) ] =
`=
γ` 1 (i), (36)
which is the expected number of times in the training data that the initial state is i, given θold^. For computational complexity, recall that the forward-backward algorithm requires O(n^2 T ) computation for each pass. Since the E-step of the EM algorithm requires an O(n^2 ) computation on each of the O(n^2 ) training examples, the running time is therefore O(n^4 ) for just a single iteration of EM. Not only that, but EM may take many more iterations to converge when there are many hidden states. Overall, the running time as a function of the number of hidden states can be quite expensive.
One problem that occurs with both the Viterbi algorithm and the forward-backward algorithm is that the v, α and β numbers can get very small. For this reason it is normal to introduce normalization and/or use logs to make the algorithms numerically stable. For Viterbi this can be done by taking logs, since
arg max x 3 ,x 2 ,x 1 P (o 3 | x 3 )P (x 3 | x 2 )P (o 2 | x 2 )P (o 1 | x 1 )P (x 1 )P (x 2 | x 1 )
= arg max x 2 ,x 2 ,x 1 log P (o 3 | x 3 ) + log P (x 3 | x 2 ) + log P (o 2 | x 2 ) + log P (o 1 | x 1 )
and the recursions can all be written in terms of summations and logs rather than the current products.
For the forward-backward algorithm, it is typical to introduce a scaling factor, so that we work with a normalized version of α,
αˆt(xt) = P (Xt = xt | O 1 = o 1 ,... , Ot = ot) =
αt(xt) P (O 1 = o 1 ,... , Ot = ot)
which is a probability distribution over n state variables for any t. A similar re-scaling can be done for β and then pushed through the forward-backward algorithm. See Bishop (13.2.4) for details.
The above explanation of EM assumed that the number of hidden states n was given. But in general we should not expect this to be the case, unless there is somehow a natural number of hidden states (e.g., the number of phonemes that go into a particular word, or standard intuition about the kinds of weather patterns that are possible.) We would like to use the data to determine how many hidden states to adopt, and thus how complex of a HMM to train. The issue is the same as we have seen before. With too few hidden states, the HMM may be unable to model all the domain activity that is producing the data. With too many hidden states, the HMM is prone to over-fitting (unless there is enough training data). In general, the amount of data needed to learn an HMM increases in proportion to the number of parameters. We know that the number of parameters is O(n^2 ), for n hidden states. A good approach to determine how many hidden states to adopt is to use validation. We can have a training set and a validation set, and vary the number of hidden states, where for each n, a model is trained and then evaluated on the validation set. The problem set will ask you to investigate this approach on some weather data.
Let’s revisit the weather domain. Suppose that the training data consists of two sequences, o^1 = (R, R) and o^2 = (NR, NR, R). Initialize θold^ as in the earlier example, so that we have parameters 0. 75 , 0. 4 , 0. 8 , 0. 2 , 0. 1 , 0. 9 ,
and 0.7 for θ 1 ,R, θ 2 ,R, θ 1 , 1 , θ 1 , 2 , θ 2 , 1 , θ 2 , 2 , and θ(1) 1 respectively. We wish to run one loop of EM. From earlier, for sequence o^1 we have (recall that the γ values come from taking the product of α and β and normalizing),
X 1 α 1 (X 1 ) β 1 (X 1 ) γ^11 (X 1 ) 1 0.525 0.68 0. 2 0.12 0.435 0. and also X 2 α 2 (X 2 ) β 2 (X 2 ) γ^12 (X 2 ) 1 0.324 1 0. 2 0.0852 1 0.
We can also compute γ^112 (X 1 , X 2 ) for o^1 , with X 1 X 2 α 1 (X 1 ) P (R | X 2 ) P (X 2 | X 1 ) β 2 (X 2 ) ⊗ γ 121 (X 1 , X 2 ) 1 1 0.525 0.75 0.8 1 0.315 0. 1 2 0.525 0.4 0.2 1 0.042 0. 2 1 0.12 0.75 0.1 1 0.009 0. 2 2 0.12 0.4 0.9 1 0.0432 0. Turning to o^2 , we run forward-backward to obtain α and β values. X 1 P (NR | X 1 ) P (X 1 ) α 1 (X 1 ) 1 0.25 0.7 0. 2 0.6 0.3 0.
X 3 α 3 (X 3 ) β 3 (X 3 ) γ^23 (X 3 ) 1 0.03256 1 0. 2 0.04571 1 0. We also compute the γ^2 t,t′ values for state transitions. For o^2 , we have X 1 X 2 α 1 (X 1 ) P (NR | X 2 ) P (X 2 | X 1 ) β 2 (X 2 ) ⊗ γ^212 (X 1 , X 2 ) 1 1 0.175 0.25 0.8 0.68 0.0238 0. 1 2 0.175 0.6 0.2 0.435 0.0091 0. 2 1 0.18 0.25 0.1 0.68 0.0031 0. 2 2 0.18 0.6 0.9 0.435 0.0423 0. X 2 X 3 α 2 (X 2 ) P (R | X 3 ) P (X 3 | X 2 ) β 3 (X 3 ) ⊗ γ 232 (X 2 , X 3 ) 1 1 0.0395 0.75 0.8 1 0.0237 0. 1 2 0.0395 0.4 0.2 1 0.00316 0. 2 1 0.1182 0.75 0.1 1 0.0089 0. 2 2 0.1182 0.4 0.9 1 0.0426 0. We can now computed the expected counts, as E[N 1 ,R] = γ^11 (1) + γ^12 (1) + γ^23 (1) = .872 + .792 + .416 = 2. 08 E[N 2 ,R] = γ^11 (2) + γ^12 (2) + γ^23 (2) = .128 + .208 + .584 = 0. 92 E[N 1 ,NR] = γ^21 (1) + γ^22 (1) = 0.421 + 0.343 = 0. 764 E[N 2 ,NR] = γ^21 (2) + γ^22 (2) = 0.579 + 0.657 = 1. 236 E[N 1 , 1 ] = γ^112 (1, 1) + γ^212 (1, 1) + γ^223 (1, 1) = .77 + .304 + 0.303 = 1. 377 E[N 1 , 2 ] = γ^112 (1, 2) + γ^212 (1, 2) + γ^223 (1, 2) = .103 + .116 + 0.040 = 0. 259 E[N 2 , 1 ] = γ^112 (2, 1) + γ^212 (2, 1) + γ^223 (2, 1) = .022 + .040 + 0.113 = 0. 175 E[N 2 , 2 ] = γ^112 (2, 2) + γ^212 (2, 2) + γ^223 (2, 2) = .105 + .54 + 0.544 = 1. 189 E[N (1) 1 ] =^ γ 1 1 (1) +^ γ 2 1 (1) =^ .872 + 0.421 = 1.^293 E[N (1) 2 ] =^ γ 1 1 (2) +^ γ 2 1 (2) =^ .128 + 0.579 = 0.^707 Finally (and thank goodness for computers!), we can compute the new parameters via an application of the M-step to these parameters, and obtain:
θ 1 ,R =
θ 2 ,R =
θ 1 , 1 =
θ 1 , 2 = 1 − θ 1 , 1 = 0. 158
θ 2 , 1 =
θ 2 , 2 = 1 − θ 2 , 1 = 0. 872
θ(1) 1 =
The parameters were initially { 0. 75 , 0. 4 , 0. 8 , 0. 2 , 0. 1 , 0. 9 , 0. 7 }, and so we see that the data (R, R) and (NR, NR, R) has caused a small adjustment in all parameters, so that this new model increases the likelihood of the observed data. If we were a computer we would now repeat...
We would like to establish that the recursion constructed for α does indeed compute P (o 1 ,... , ot, xt). For this, we have
xt− 1
P (o 1 ,... , ot, xt− 1 , xt)
xt− 1
P (ot | o 1 ,... , ot− 1 , xt− 1 , xt)P (xt | o 1 ,... , ot− 1 , xt− 1 )P (o 1 ,... , ot− 1 , xt− 1 )
= P (ot | xt)
xt− 1
P (xt | xt− 1 )αt− 1 (xt− 1 )
which is exactly our recursion, and base case
α 1 (x 1 ) = P (o 1 | x 1 )P (x 1 ) = P (o 1 , x 1 )
Similarly, we would like to establish that the recursion constructed for β does indeed compute P (ot+1,... , oT | xt). For this, we have
xt+
P (ot+1,... , oT , xt+1 | xt)
xt+
P (ot+1,... , oT | xt, xt+1)P (xt+1 | xt)
xt+
P (ot+1,... , oT | xt+1)P (xt+1 | xt)
xt+
P (ot+2,... , oT | xt+1)P (ot+1 | xt+1)P (xt+1 | xt)
xt+
P (xt+1 | xt)P (ot+1 | xt+1)βt+1(xt+1),
which is exactly our recursion and with base case βT (xT ) = 1 we can check,
βT − 1 (xT − 1 ) =
xT
P (xT | xT − 1 )P (oT | xT )
xT
P (xT | xT − 1 )P (oT | xT , xT − 1 )
xT
P (xT , oT | xT − 1 ) = P (oT | xT − 1 )