. An easy-to-understand hmm example

Source: Internet
Author: User

Original article URL:
Http://www.52nlp.cn/hmm-concrete-example-on-wiki/

Alice and Bob are good friends, but they are far away from each other. Every day, they call each other to learn what they did that day. bob is only interested in three activities: walking in the park, shopping, and cleaning up his room. he chooses what to do based only on the weather of the day. alice doesn't know the weather conditions of Bob's place, but she knows the general trend. based on what Bob tells Alice every day, Alice wants to guess the weather conditions of Bob's location.

Alice thinks that the weather is like a Markov chain. there are two states: "Rain" and "clear", but they cannot be directly observed, that is, they are hidden for Alice. every day, Bob has a certain probability to perform the following activities: "Walking", "shopping", or "cleaning ". because Bob will tell Alice his activities, these activities are Alice's observation data. this entire system isHidden Markov Model Hmm.

Alice knows the general weather trends in this region and knows what Bob will do at ordinary times. That is to say, the parameters of this hidden Markov model are known. You can write them down in the programming language (Python:

// Number of statuses, two statuses: Rain or clear
States = ('rainy', 'sunny ')
// Possible observed values in each status
Observations = ('Walk ', 'shop', 'clean ')
// Probability distribution of the initial state space
Start_probability = {'rainy': 0.6, 'sunny ': 0.4}
// Time-independent state transfer probability matrix
Transition_probability = {
'Rainy': {'rainy': 0.7, 'sunny ': 0.3 },
'Sunny ': {'rainy': 0.4, 'sunny': 0.6 },
}
// Observed value probability distribution and emission probability in a given State
Emission_probability = {
'Rainy': {'walk ': 0.1, 'shop': 0.4, 'clean': 0.5 },
'Sunny ': {'walk': 0.6, 'shop ': 0.3, 'clean': 0.1 },
}

In these code, start_probability represents Alice's uncertainty about the weather conditions when Bob called her for the first time (Alice knows that it rains more on average ). here, the specific probability distribution is not balanced, and the equilibrium probability should be close to (given the probability of change) {'rainy': 0.571, 'sunny ': 0.429 }. Transition_probability indicates the weather changes under the Markov chain. In this example, if it rains today, the probability of a sunny day is only 30%. the Code emission_probability indicates Bob's probability of doing something every day. if it rains, 50% of the probability is that he is cleaning the room; if the weather is fine, 60% of the probability is that he is walking outside.
Alice and Bob called for three days and found Bob went for a walk on the first day. He went shopping the next day and cleaned the room on the third day. Alice has two questions: what is the total probability of the observed sequence "walking, shopping, cleaning? (Note: This problem corresponds to one of the basic questions of HMM: how to calculate P (o | λ) when we know the HMM Model λ and the observed sequence o )?) What is the state sequence of this observation sequence (clear/rain? (Note: This problem corresponds to the basic hmm problem 2: Given the observed sequence o = O1, O2 ,... OT and model λ, how to select a corresponding state sequence S = Q1, q2 ,... Qt, which makes s the most reasonable interpretation of the observed sequence o ?)
As for the basic questions of HMM, question 3: how to adjust the model parameters to maximize P (o | λ? In fact, this problem is to give a lot of observation sequence values to train the above parameters.

. An easy-to-understand hmm example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.