Natural Language Processing 2-Hidden Markov Model (HMM)-Forward Algorithm (Forward Algorithm) and Viterbi (Viterbi algorithm)

Source: Internet
Author: User
Document directory
  • 1. Hidden Markov Model (HMM)
1. Hidden Markov Model (HMM)

Instance:

Hidden status: Sunny, cloudy, and rainy

Observed status: dry, dryish, damp, soggy

Initial Vector

Status transition matrix ('A ')

Weather
Yesterday

Weather today

 

Sunny

Cloudy

Rainy

 

Sunny

0.500

0.375

0.125

 

Cloudy

0.250

0.125

0.625

 

Rainy

0.250

0.375

0.375

 

Note: The sum of each row is 1.

Confusion matrix ('B ')

Hidden
States

Observed states

 

Dry

Dryish

Damp

Soggy

 

Sunny

0.60

0.20

0.15

0.05

 

Cloudy

0.25

0.25

0.25

0.25

 

Rainy

0.05

0.10

0.35

0.50

 

Note: The sum of each row is 1.

1. Forward Algorithm

Definition

Use forward algorithm to calculate the probability of appearance


T = 1 hour


T = 2,..., T


Last


Note: At + 1 (j) indicates the partial probability of State J at the time t + 1; the probability of bjk confusion matrix; the probability of AIJ transfer matrix, indicates the initial probability of status J.

 

 

Pr (dry, damp, soggy | hmm)

T = 1

A1 (Sunny) = 0.63*0.6 = 0.37800002

A1 (cloudy) = 0.17*0.25 = 0.0425

A1 (rainy) = 0.2*0.05 = 0.010000001

T = 2

A2 (Sunny) = (0.37800002*0.5 + 0.0425*0.250 + 0.010000001*0.250) * 0.15

A2 (cloudy) = (0.37800002*0.375 + 0.0425*0.125 + 0.010000001*0.375) * 0.25

A2 (rainy) = (0.37800002*0.125 + 0.0425*0.625 + 0.010000001*0.375) * 0.35

T = 3

A3 (Sunny) = (A2 (Sunny) * 0.5 + A2 (cloudy) * 0.250 + A2 (rainy) * 0.250) * 0.05

A3 (cloudy) = (A2 (Sunny) * 0.375 + A2 (cloudy) * 0.125 + A2 (rainy) * 0.375) * 0.25

A3 (rainy) = (A2 (Sunny) * 0.125 + A2 (cloudy) * 0.625 + A2 (rainy) * 0.375) * 0.50

Pr (dry, damp, soggy | hmm) = A3 (Sunny) + A3 (cloudy) + A3 (rainy)

1.2.viterbi Algorithm

Calculate PR (observed sequence | hidden state combination), that is, Calculation

Pr (dry, damp, soggy | sunny, sunny, sunny ),

Pr (dry, damp, soggy | sunny, sunny, cloudy ),

Pr (dry, damp, soggy | sunny, sunny, rainy ),

....

The maximum values in PR (dry, damp, soggy | rainy, rainy, and rainy) to obtain the most likely sequence for occurrence of dry, damp, and soggy.

T = 1 hour

When t = 2,..., T; and I = 1,..., n

Find the maximum value in T (I)

When T = t-1,..., 1, find the maximum probability state sequence using the Backtracking Method.

T = 1 hour


T = 2 hours

 

T = 3 hours

 

Therefore, the most likely sequence of occurrence of dry, damp, and soggy is sunny, cloudy, and rainy.

 

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.