Posterior probability using forward backward algorithm in R

For one of my projects I need to find posterior probability of visiting a state S and emitting a symbol. I have built a HMM in R and later I get one observation sequence. But, I am not able to interpret the output.

> # Sequence of observations
> observations = c("L","L","R","R")
> # Calculate posterior probablities of the states
> posterior = posterior(hmm, observations) ## ---> hmm is hidden markov model
> print(posterior)
index
states         1       2       3         4
A 0.6037344 0.56639 0.43361 0.3962656
B 0.3962656 0.43361 0.56639 0.6037344

How do I interpret this? This matrix gives output w.r.t time. But, I need posterior probability of visiting a state S and emitting a symbol say A. How can I get it?

Thanks for the response.The description says it combines forward and backward probabilities to get posterior details...But,as i have read in papers, the forward-backward algorithm gives the probability of being in a state say A and emitting a symbol say L.. which i do not see here. Here is all the details of HMM - # Initialise HMM # init HMM format: A and B are hidden states,L and R are observations,transprob: initial # transition probabilities and emissionprobs IS EMISSION probability hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2), emissionProbs=matrix(c(.6,.4,.4,.6),2)) print(hmm)

Sequence of observations

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

Calculate posterior probablities of the states

posterior = posterior(hmm,observations) print(posterior)

Description of POSTERIOR: This function computes the posterior probabilities of being in state X at time k for a given sequence of observations and a given Hidden Markov Model.

Details The posterior probability of being in a state X at time k can be computed from the forward and backward probabilities: Ws(X_k = X | E_1 = e_1, ... , E_n = e_n) = f[X,k] * b[X,k] / Prob(E_1 = e_1, ... , E_n = e_n) Where E_1...E_n = e_1...e_n is the sequence of observed emissions and X_k is a random variable that represents the state at time k.

But,in general how can we calculate posterior probability without using this algo

migrated from stackoverflow.comMay 26 '12 at 14:37

This question came from our site for professional and enthusiast programmers.

• Thank you for the detail! I do not understand why you would like to calculate the posterior probabilities without the Foward-Backward (FB) algorithm, because the FB is the algorithm to get the posterior probabilities. – gui11aume Jun 1 '12 at 15:29