TOPICS (Click to Navigate)

Pages

Saturday, May 2, 2020

Hidden Markov Model Solved Exercise



Question:
1. Mr. X is happy someday and angry on other days. We can only observe when he smiles, frowns, laughs, or yells but not his actual emotional state. Let us start on day 1 in the happy state. There can be only one state transition per day. It can be either to happy state or angry state. The HMM is shown below;

Assume that qt is the state on day t and ot is the observation on day t. Answer the following questions;

(a) What is P(q2 = Happy)?
(b) What is P(o2 = frown)?
(c) What is P(q2 = Happy | o2 = frown)?
(d) What is P(o1 = frown o2 = frown o3 = frown o4 = frown o5 = frown, q1 = Happy q2 = Angry q3 = Angry q4 = Angry q5 = Angry) if π = [0.7, 0.3]?

Solution:
(a) What is P(q2 = Happy)?
The question is to find the probability of Mr. X is Happy on day 2. It is given that the first day he was Happy. For the second day, we need to find the transition probability P(q2 = Happy | q1 = Happy).
P(q2 = Happy | q1 = Happy) = 0.8

(b) What is P(o2 = frown)?
We need to find the probability of observation frown on day 2. But we don’t know the states whether he is happy or not on day 2 (we know he was happy on day 1). Hence, the probability of the observation is the sum of products of observation probabilities and all possible hidden state transitions.
P(o2 = frown) = P(o2 = frown | q2 = Happy) + P(o2 = frown | q2 = Angry)
            = P(Happy | Happy)* P(frown | Happy) + P(Angry | Happy)* P(frown | Angry)
            = (0.8 * 0.1) + (0.2 * 0.5) = 0.08 + 0.1 = 0.18

(c) What is P(q2 = Happy | o2 = frown)?
Here, we need to find the probability of hidden state on day 2 as Happy given the observation on that day as frown. This conditional probability cannot be calculated directly. Hence, we apply Bayes’ rule to solve as follows;
P(q2 = Happy | o2 = frown) = (P(o2 = f| q2 = H) * P(q2 = H)) / P(o2 = f)
                                                = (P(Happy | Happy)* P(frown | Happy)) / 0.18
[Note: 0.18 is taken from the answer for question (b)]
                                                = (0.8 * 0.1) / 0.18 = 0.08 / 0.18 = 0.4444

(d) What is P(o1 = frown o2 = frown o3 = frown o4 = frown o5 = frown, q1 = Happy q2 = Angry q3 = Angry q4 = Angry q5 = Angry) if π = [0.7, 0.3]?
Here, we need to find the probability of the observation sequence “frown frown frown frown frown” given the state sequence “Happy Angry Angry Angry Angry”. π is the initial probabilities.
P(f f f f f, H A A A A)  
            = P(f|H)*P(f|A)*P(f|A)*P(f|A)*P(f|A)*P(H)*P(A|H)*P(A|H)*P(A|H)*P(A|H)
            = 0.1 * 0.5 * 0.5 * 0.5 * 0.5 * 0.7 * 0.2 * 0.2 * 0.2 * 0.2
            = 0.000007

**************

Related Links:


How to calculate the tranisiton and emission probabilities in HMM from a corpus?

Solved exercise in HMM, Exercise with solutions in hidden markov model, solutions to exercises in natural language processing

Maximum Likelihood Estimate in HMM 

Calculate emission probability in HMM

how to calculate transition probabilities in hidden markov model

how to calculate bigram and trigram transition probabilities solved exercise

solved problems in hidden markov model

No comments:

Post a Comment