Skip to main content
added 64 characters in body; edited title
Source Link
chl
  • 54.3k
  • 23
  • 227
  • 388

Posterior probability vs. Viterbi algorithm

I was reading HMM rworking through HMM R package and used posterior as well as viterbi algo -Viterbi algorithm:

R> hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2),
+       emissionProbs=matrix(c(.6,.4,.4,.6),2))

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

# Calculate posterior probablities of the states
R> posterior = posterior(hmm,observations)
R> 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



R> viterbi = viterbi(hmm,observations)
R> print(viterbi)
[1] "A" "A" "A" "A"

So in the above example if I would consider posterior results and take sequence of hidden states according to highest probability at each position, then I willwould get -

"A" "A" "B" "B"

but viterbithe Viterbi algorithm tells me that the sequence is -

"A" "A" "A" "A"

My question is which sequence should I trust and why?

Thanks in advance,

Vikas

Posterior probability vs Viterbi

I was reading HMM r package and used posterior as well as viterbi algo -

R> hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2),
+       emissionProbs=matrix(c(.6,.4,.4,.6),2))

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

# Calculate posterior probablities of the states
R> posterior = posterior(hmm,observations)
R> 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



R> viterbi = viterbi(hmm,observations)
R> print(viterbi)
[1] "A" "A" "A" "A"

So in the above example if I would consider posterior results and take sequence of hidden states according to highest probability at each position, then I will get -

"A" "A" "B" "B"

but viterbi tells me that sequence is -

"A" "A" "A" "A"

My question is which sequence should I trust and why?

Thanks in advance,

Vikas

Posterior probability vs. Viterbi algorithm

I was working through HMM R package and used posterior as well as Viterbi algorithm:

R> hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2),
+       emissionProbs=matrix(c(.6,.4,.4,.6),2))

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

# Calculate posterior probablities of the states
R> posterior = posterior(hmm,observations)
R> 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



R> viterbi = viterbi(hmm,observations)
R> print(viterbi)
[1] "A" "A" "A" "A"

So in the above example if I would consider posterior results and take sequence of hidden states according to highest probability at each position, then I would get

"A" "A" "B" "B"

but the Viterbi algorithm tells me that the sequence is

"A" "A" "A" "A"

My question is which sequence should I trust and why?

Source Link
Vikas
  • 227
  • 2
  • 7

Posterior probability vs Viterbi

I was reading HMM r package and used posterior as well as viterbi algo -

R> hmm = initHMM(c("A","B"), c("L","R"), transProbs=matrix(c(.8,.2,.2,.8),2),
+       emissionProbs=matrix(c(.6,.4,.4,.6),2))

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

# Calculate posterior probablities of the states
R> posterior = posterior(hmm,observations)
R> 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



R> viterbi = viterbi(hmm,observations)
R> print(viterbi)
[1] "A" "A" "A" "A"

So in the above example if I would consider posterior results and take sequence of hidden states according to highest probability at each position, then I will get -

"A" "A" "B" "B"

but viterbi tells me that sequence is -

"A" "A" "A" "A"

My question is which sequence should I trust and why?

Thanks in advance,

Vikas