[ML] [hmm] Introduction to Hidden Markov Model (HMM)

Source: Internet
Author: User

Introduction to Hidden Markov Model (HMM)

From: http://xiaofeng1982.blog.163.com/blog/static/315724582009824103618623/

Please take a deep breath ...... Call ......

Start ......

(1) A Huang is a respected police officer. He is cheerful and strong, and is a healthy model in everyone's mind.

However, in the past month, a Huang's health condition has become abnormal: his mood is out of control. Sometimes I can't help but laugh, sometimes I frown, Sometimes tears, sometimes furious ......

For example, what is the cause of this impermanence of emotional out-of-control? According to Yong Nan, a colleague from the police team, he experienced insomnia and other symptoms due to the trouble of not turning off the lights and multimedia homework in the dormitory during the examination, A Huang has recently logged on to a website called "Xiaonei" very frequently. After further diagnosis, the doctors did not get out of control because others experienced the same test pressure and irregular schedules. In addition, many other users logged on to Xiaonei, therefore, we can basically eliminate them as the cause of emotional runaway. Huang sir's illness was once deadlocked ......

Recently, a Huang's illness has a new eye: according to a witch who is very proficient in learning and divination, A Huang asked her to diagnose her illness in private. After observation and analysis, we finally found that a yellow's illness was being controlled by three gods lurking in his body! They are: King Shura, Ashura, and the God of robrake.

It is learned that these three kinds of gods are the natural gods formed by the intensification of emotional accumulation. They are mutually compatible and are spiritual products beyond the individual consciousness and can play a dominant role in human emotions. Every day, there will be a kind of emotion for the Lord aliyun. In addition, different gods may cause different emotions to suddenly show up. However, the current level of technology cannot help us diagnose, Which of the following is the dominant god? What's worse, different gods (3) and different emotions (4) there is no obvious one-to-one correspondence.

So at first glance, a Huang's illness is deadlocked again ......

How can we grasp the laws of Huang's emotional changes?

How can we speculate on the changing laws of the god serving in a Huang's body through his emotional changes?

Keywords: two statuses:

Emotional status (observed status): laugh, frown, tears, And furious

Sever status (hidden state): King Shura, Asura, and raybrake

(2) A Huang's illness has attracted a lot of caring people. This is unrelated to the sincere and kind character of Alibaba Cloud.

With regard to the characteristics of Shen Shi, the overlord and many good-hearted people have found a lot of valuable information. After a period of observation and record, many people found the internal law between God and emotion behind seemingly irregular data !! After multiple observations, they built on a large amount of data and showed a macro internal connection!

Most of these people are from Tongji University. Therefore, such a rule is called a statistical rule. These people are called statisticians (orz is too earthy )............

The specific rules are summarized as follows:

1. Every day, which of the following God is in great relation to who is the god of the previous day! That is, the probability that the previous sever affects the appearance of the next Sever.

The probability of conversion between the three sub-gods is as follows:

To facilitate the computation of some people called mathematicians, we are used to writing matrices:

2. When each God serves as the Dominator, the corresponding emotions also have a certain pattern: When a God serves, the appearance of emotions has a certain regularity. For example, if today's God is the king of Shura, then the probability of a Huang's laughter is the probability that different gods correspond to different emotions. We also summarize them in a table:

It is easy to calculate and can also be written into the matrix format.

3. because the daily God-serving status and emotional status all depend on the previous day, it is possible to deduce the following days only when you know the initial emotional status of porn, the changes in God and emotion in the body of porn.

We assume that the probability of the first appearance of the God in ALI govice satisfies the following table.

Shura owner Ashar

[0.63 0.17 0.20 〕

So far, we have mastered all the information about the laws of Huang's mood changes, including:

There are two types of States: Shen Shi and emotion.

Three relationships: the Conversion Relationship between the gods, the relationship between the gods and emotions, and the initial state of the gods

It is easy to calculate. We use mathematical languages to define it for future computation.

Shura owner Ashar

Initial State Matrix: Medium = (0.64 0.17 0.20 〕

Status transition matrix:

A =

Two-State hybrid matrix (describe the ing between the sever status and the emotional status)

(3)

What can we do after we know the information about porn?

I. estimate the probability of "Laughter"-"Tears"-"Furious:

"Laugh"-"Tears"-"Furious" is a very dangerous combination! If, within three days, a Huang experienced a sudden emotional change like a burst of laughter, which could cause severe mental damage !! So what is the probability of such a combination of emotions?

It seems quite troublesome, because "Laughter" can correspond to three kinds of God-serving; the other two can also. Three days, three kinds of gods, all may be 3*3*3 = 27.

According to the full probability formula: So:

P (smile-tears-anger) = P (smile-tears-anger | Shura owner-Shura owner) + P (smile-tears-anger | Shura owner-Ashura) + P .................. + P (Laugh-tears-anger | rochelavideo-rochelavideo)

A total of 27 items are added to calculate all possibilities!

It can be imagined that such computing is disastrous.

Of course, in computer computing, recursive methods can be used to simplify computing and reduce complexity.

① We Will concatenate the emotional states of a Huang every day and form a sequence of States for multiple days. The status on the day t is ykt.

② When calculating the probability of a State in a sequence, it is expressed by the sum of all paths that may reach the state.

For example, at t = 2, the probability that the state is ashboard can be calculated using the following path:

The partial probability of the final observed State indicates the probability of all possible paths in these states. For example:

③ Use α T (j) to represent the partial probability of State J at time t. The calculation method is as follows:

α T (j) = P (observe emotion | Shi Shen is j) * P (all channels to J at t time)

The first item in the multiplication of the two items is obtained by the two-state hybrid matrix:

Next, we need to determine the result of the previous one. This also shows that the state of each hmm link is characteristic of the state of the previous link.

④ If each link depends on the previous link, how can we calculate the initial link, that is, the initial state?

Very simple. The initial state failover comes in handy.

For example, on the first day, a Huang burst into laughter:

A1 (shura Wang) = 0.63 × 0.6 = 0.378

A1 (Asura) = 0.17 × 0.25 = 0.0425

A1 (raybrake) = 0.20x0.05 = 0.01

Mathematical formula:

⑤ As we said, the last day is the decision of the day before. Now, if we know at (J), we should know at + 1 (j) in the next day. How to calculate at + 1 (j?

Too boring ~ Continue with the above example.

For example, when T = 2, the mood is tears, And the god is ashboard, then:

A2 (ashboard) = P (the probability of tears when reading) × P (all probabilities of arriving at ashboard)

Where:

P (all probabilities of arriving at axura)

= A1 (shura Wang) × P (shura Wang → Ashura) + A1 (Asura) × P (Asura → Ashura) + A1 (Rochela God) × P (Rochela God → Ashura)

= 0.378 × 0.25 + 0.0425 × 0.125 + 0.01 × 0.675

In this way, we know A1, the relationship between at and at + 1, iteration, iteration, and iteration ...... In the end, you will find the probability of the desired state.

(In addition, iteration can reduce the complexity of the algorithm During computation. You don't know much about it ......)

Finally, answer the question of the probability of "laughter-tears-Furious"

The three probabilities of each day correspond to the three gods.

Day 1: laugh

(0.63 × 0.6) = 0.37800002

(0.17 × 0.25) = 0.0425

(0.2 × 0.05) = 0.010000001

Day 2: tears

(0.37800002 × 0.5) + (0.0425*0.375) + (0.010000001*0.125) * 0.15) = 0.03092813

(0.37800002*0.25) + (0.0425*0.125) + (0.010000001*0.675) * 0.25) = 0.026640628

(0.37800002*0.25) + (0.0425*0.375) + (0.010000001*0.375) * 0.35) = 0.039965626

Day 3: furious

(0.03092813*0.5) + (0.026640628*0.375) + (0.039965626*0.125) * 0.05) = 0.0015225002

(0.03092813*0.25) + (0.026640628*0.125) + (0.039965626*0.675) * 0.25) = 0.009509727

(0.03092813*0.25) + (0.026640628*0.375) + (0.039965626*0.375) * 0.5) = 0.01635469

Therefore, the probability of "laughter-tears-Furious" is

0.0015225002 + 0.009509727 + 0.01635469 = 0.027386917

Huang sir can rest assured for the time being.

(4)

What other applications?

2. The largest potential hidden state is estimated by the observed state,

That is, the changes in the body of the god are inferred from the changes in the yellow mood.

1. Use the exhaustive method.

In short, the change is limited, the probability is known, each step is measurable, the size is comparable ......

In comparison, we can always find the most possible path.

However, as the number of days increases and the number of servers increases, the computing complexity increases exponentially, which is very negative.

It's boring ~ Another example:

For example, a Huang experienced a sudden emotional change in three days: "laughter-tears-Furious.

We really want to know: what kind of God-serving combination is most likely to lead to this kind of emotion?

The best combination should be:

Max {P (Laugh-tears-anger | Shura-Shura), P (Laugh-tears-anger | Shura-axura ), P (smile-tears-anger | Shura owner-raybrake ),.................., P (Laugh-tears-anger | robrake-robrake )}

The 27 are more likely than the one with the highest probability ~

2. For Program Computing, we use recursive methods to reduce computational complexity:

We know that there is only one optimal path for the change of the secret God, which may be like this:

Each part of the Optimal Path corresponds to an association probability-partial probability (equivalent to the previous intermediate probability ). Different from the previous one, it is the probability that a path is most likely to reach this state.

① We define: Delta (I, T) is the maximum probability of terminating with state I at the T moment in all sequences. Of course, the path corresponding to it is part of the optimal path. Delta (I, T) exists for each I, T. In this way, we can find the optimal path of the entire sequence in the last state of the sequence.

② So what is the optimal path of the initial state (t = 1? We still need to rely on the Initial State Matrix begin

This is the same as the previous algorithm.

Delta (King Shura, 1) = 0.378

Delta (Asura, 1) = 0.0425

Delta (raybrake, 1) = 0.01

③ How can we find the partial probability (the Optimal Path) of the intermediate state with time t?

For another example, there may be three ABC paths that reach the X state at the t time.

The figure shows that the optimal path to X is one of the following three:

(Status sequence),..., A, X

(Status sequence),..., B, X

(Status sequence),..., C, X

We need to compare:

P (Optimal Path to a) × P (probability of a reaching X)

P (Optimal Path to B) × P (probability of B reaching X)

P (Optimal Path to C) × P (probability of C reaching X)

Multiply by the observed state (emotion) corresponding to p (x) to calculate the probability of a State.

④ Then, the probability of corresponding observation state at t time is recorded as delta T (I ).

On the first day, because there is no pilot, the two-state transition matrix can only be used for calculation:

Day t:

Delta T (I) = max {delta T-1 (j) × P (J state → I state) × probability of corresponding observation state under I state}

Mathematical formula:

In this way, we can iterate over the generation without being exhausted ~

Finally, let's calculate the most likely combination of "laughter-tears-Furious:

Day 1: laugh

Shaluo King (0.63*0.6) = 0.37800002

Asura (0.17*0.25) = 0.0425

Robrakes (0.2*0.05) = 0.010000001

Day 2: tears

Shura Wang max (0.37800002*0.5), (0.0425*0.375), (0.010000001*0.125) * 0.15 = 0.028350003

Asura max (0.37800002*0.25), (0.0425*0.125), (0.010000001*0.675) * 0.25 = 0.023625001

Max (0.37800002*0.25), (0.0425*0.375), (0.010000001*0.375) * 0.35 = 0.033075

Day 3: furious

Shura Wang max (0.028350003*0.5), (0.023625001*0.375), (0.033075*0.125) * 0.05 = 0.000708750

Asura max (0.028350003*0.25), (0.023625001*0.125), (0.033075*0.675) * 0.25 = 0.00558140

Max (0.028350003*0.25), (0.023625001*0.375), (0.033075*0.375) * 0.5 = 0.006201562

It can be seen that on the first day, Mr. shura was the most likely to dominate porn;

The next day, from King shura to the god of robrake, the greatest possibility of a Huang's tears;

On the third day, Alibaba Cloud continues to be dominated by the God of robrakes, causing the greatest possibility of anger.

Therefore, the combination of "Laugh-tears-Furious" is the most likely combination of the gods: The king of Shura-the god of robrakes

Conclusion

1. After learning about this story, we have a rough understanding of the composition of hidden Markov models. It includes two states and three relationships: Initial State (initial state) A (State Transfer Matrix) B (mixed state matrix)

Ii. Here is a preliminary understanding of the HMM model. Its main functions include:

1. Find the probability of an observed sequence based on known hmm. (Calculate the probability of a certain emotional combination)

2. Find the most likely hidden state sequence based on the observed sequence (derived from the sentiment combination)

3. Obtain hmm from the observed sequence (this is the most difficult hmm application. That is, a triple HMM (hidden, a, B) is generated based on the observed sequence and its hidden state ). So that the triple can best describe a symptom we see. Limited by level, not discussed)

3. In the above application, 1 is designed to the forward algorithm, 2 is designed to the Viterbi algorithm, and you can view the information, which can be implemented in the program.

4. There are many hmm-related applications in biological information. This model is used in the construction of the protein domain description and molecular tree. In fact, similar: what we can see is the observed state: sequence (emotion), and the hidden states hidden behind the current sequence: such as genes ...... (King Shura, Asura, and the God of robrake ......). We cannot directly observe the evolution of genes, but we can use the application 3-to obtain hmm from the observed sequence and train with known sequences, generate an HMM model that contains the actual sequence information, and then manually annotate the gene through the existing sequence (probably this idea, ft)

5. Thanks to the website:

Www. Comp. Leeds. ac. uk/Roger/hiddenmarkovmodels/html_dev/main.html

It is helpful to provide a large number of introductions, Data, charts, and applets.

I would like to express my special thanks to Cui xiaoyuan for his detailed translation and explanation. The idea of this article is attributed to his translation work.

6. Thank you for your support, understanding, and encouragement from the name of the hero.

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.