Need to be answered in R CODE Provide a script for HIDDEN MA

Need to be answered in R CODE

Provide a script for HIDDEN MARKOV MODEL using forward algorithm.

A. Script requires three inputs:
         1) State Transition Matrix (with state names)
         2) Emission Matrix (with symbol names)
         3) Initial State Distribution

B. It requires a sequence of observations vector

C. It output probability of the observations vector given the HMM (specified in A)

    c.1 Using Exhaustive search
    c.2 Using Forward Algorithm

Solution

A. Firstly as per the given problem , the script needs to have three inputs i.e state transition matrix, emission matrix and initial state distribution.

So, the first line of the script which takes the three inputs will be :

require(\'HMM\')

// initialising HMM

where A & B are hidden states and two observations are L & R.

B. Second line requires a sequence of observations vector, so the third line will be :

// sequence of observations

observations = c(\"L\",\"L\",\"R\",\"R\")

C. So, using the forward logarithm which states the below :

\" Let XX be an observation sequence and be a Hidden Markov Model (HMM). Then the forward algorithm determines Pr(X|)Pr(X|), the likelihood of realizing sequence XX from HMM .\"

  logForwardProbabilities = forward(hmm,observations)

Here, forward probabilitiies is a matrix of realizing the observation sequence upto time t and state i.

Hidden states i are in rows and times t are in columns. If we want the probability of the overall sequence, we use column 4 because it is the last timestep. The resulting 2 element row vector contains the probabilities of ending in A and ending in B. Their sum is the total probability of realizing XX.

Kindly comment on the answer if any part is not understandable.

Need to be answered in R CODE Provide a script for HIDDEN MARKOV MODEL using forward algorithm. A. Script requires three inputs: 1) State Transition Matrix (wit

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site