Big data of the road HMM series

Source: Internet
Author: User

One: Hmm decoding problem

(1) given an observation sequence O=o1o2 ... OT, and Model μ= (a,b,π), how to quickly and effectively select the "optimal" state sequence q=q1q2...qt in a certain sense, so that the state best interprets the observation sequence.

(2) The most probable sequence of hidden states (finding most probable sequence of hidden states); For a special hidden Markov model (HMM) and a corresponding observation sequence, We often hope to find the most probable sequence of hidden states to generate this sequence.

Two: examples

(1) Assuming that the 3-day continuous observation of seaweed humidity is (dry,damp,soggy), the most probable weather conditions for the three days. There are only three types of weather (sunny,cloudy,rainy), and seaweed humidity and weather have a certain relationship.

Known:
1. Hidden state: Sunny,cloudy, Rainy, seaweed humidity There are four classes {Dry,dryish,damp,soggy}
2. Observe the status sequence: {Dry, damp, soggy};
3. Initial state sequence: Sunny (0.63), cloudy (0.17), Rainy (0.20);

4. State transition Matrix

Sunny Cloudy Rainy
Sunny 0.5 0.375 0.125
Cloudy 0.25 0.125 0.625
Rainy 0.25 0.375 0.375

Cloudy ( yesterday )->sunny ( today ) the probability is 0.25;

Sunny ( yesterday )->rainy ( today ) the probability is 0.125.

5. Confusion matrix (algae humidity and weather correlation):

Dry Dryish DampSoggy
Sunny 0.6 0.2 0.150.05
Cloudy 0.25 0.25 0.25 0.25
Rainy 0.05 0.10 0.35 0.50

(2) Calculation method:

According to Hmm, the weather of Day2 depends only on the weather of Day1;day3 and only on the weather of Day2.

Step1: Day1 because it is the initial state, we separately seek

P (Day1-sunny) =0.63*0.6;
P (day1-cloudy) =0.17*0.25;
P (Day1-rain) =0.20*0.05;
Choose max{P (day1-sunny), P (day1-cloudy), P (day1-rainy)}, get P (day1-sunny) maximum, the probability of the 1th day Sunny is the largest.

Step2: The weather in Day2 depends on the weather conditions of the Day1 and is also influenced by the Day2 observed by the algae.

P (day2-sunny) = max{p (day1-sunny) *0.5, P (day1-cloudy) *0.25, P (day1-rainy) *0.25} *0.15;
P (day2-cloudy) = max{p (day1-sunny) *0.375, P (day1-cloudy) *0.125, P (day1-rainy) *0.625} *0.25;
P (day2-rainy) = max{p (day1-sunny) *0.125, P (day1-cloudy) *0.625, P (day1-rainy) *0.375} *0.35;
choosemax{p (Day2-sunny), P (day2-cloudy), P (day2-rainy)}, get the largest p (day2-rainy), the probability of the 2nd day Rainy is the largest.
Therefore {Sunny,rainy} is the largest possible weather sequence for the previous two days.

Step3: The weather in Day3 depends on the weather conditions of the Day2 and is also influenced by the DAY3 observed by the algae.

P (day3-sunny) = max{p (day2-sunny) *0.5, P (day2-cloudy) *0.25, P (day2-rainy) *0.25} *0.05;
P (day3-cloudy) = max{p (day2-sunny) *0.375, P (day2-cloudy) *0.125, P (day2-rainy) *0.625} *0.25;
P (day3-rainy) = max{p (day2-sunny) *0.125, P (day2-cloudy) *0.625, P (day2-rainy) *0.375} *0. 05;
choosemax{p (Day3-sunny), P (day3-cloudy), P (day3-rainy)}, get the largest p (day3-rainy), the probability of the 3rd day Rainy is the largest.

(3) Code implementation

#include <stdio.h> #include <stdlib.h> #include <string.h>/* title Description: Given an observation sequence O=o1o2 ... OT, and Model μ= (a,b,π), how to quickly and effectively select the "optimal" state sequence q=q1q2...qt in a certain sense, so that the state best interprets the observation sequence.  The following is a state transition matrix; B is the emission matrix, and the list is the observation sequence; */const int hid_statuses = 3;        Number of hidden states const int vis_st = 4;             The number of actual all possible cases (States) observed is const int N = 3; Number of days to observe (sequence length) int main () {float A[hid_statuses][hid_statuses] = {{0.5,0.375,0.125},{0.25,0.125,0.625},{ 0.25,0.375,0.375}};//State transfer matrix float B[hid_statuses][vis_st] = {{0.6,0.2,0.15,0.05},{0.25,0.25,0.25,0.25,},{    0.05,0.10,0.35,0.50,}};//b is the emission matrix float ini[hid_statuses] = {0.63,0.17,0.20};//initial float result[n][hid_statuses];  int List[n] = {0,2,3};//The observed state sequence of the test, 4 days of observation, because there are 2 observation states, so with//0 and 1, the actual should be input, and the number of days to observe is also input or read file int    Max[n][hid_statuses];    float tmp;    int i,j,k; Step1:initialization, where {0.2,0.4,0.4} is πfor (i=0;i(4) Operation result:




Big data of the road HMM series

Related Article

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.