4

I need some help on this error. I am trying build a HMM module using the HMM package in R. I am not able to understand what's wrong with my code. Error is in training HMM using the Baum-Welch algorithm

lathmm = initHMM(c("S","M1","M2","M3","M4","E"),c("m","i"),c(1,0,0,0,0,0),
+ matrix(c(   0,0,0,0,0,0,  
+             1,0,0,0,0,0,
+             0,1,0,0,0,0,
+             0,0,1,0,0,0,
+             0,0,0,1,0,0,
+             0,0,0,0,1,1
+             ),6,6), 
+  matrix(c(0,.5,.5,.5,.5,.5,  
+           0,.5,.5,.5,.5,.5  
+           ),6,2))
> 
> print(lathmm)
$States
[1] "S"  "M1" "M2" "M3" "M4" "E" 

$Symbols
[1] "m" "i"

$startProbs
 S M1 M2 M3 M4  E 
 1  0  0  0  0  0 

$transProbs
    to
from S M1 M2 M3 M4 E
  S  0  1  0  0  0 0
  M1 0  0  1  0  0 0
  M2 0  0  0  1  0 0
  M3 0  0  0  0  1 0
  M4 0  0  0  0  0 1
  E  0  0  0  0  0 1

$emissionProbs
      symbols
states   m   i
    S  0.0 0.0
    M1 0.5 0.5
    M2 0.5 0.5
    M3 0.5 0.5
    M4 0.5 0.5
    E  0.5 0.5

-> No issues in Initializing the HMM.

Baum-Welch training:

> prot = sample(c(rep("m",100),rep("m",300)))
>  bw = baumWelch(lathmm,prot,10)
Error in if (d < delta) { : missing value where TRUE/FALSE needed

-> This is the error.

Can anyone help me on this. I am not sure what's wrong with this module.

rcs
  • 67,191
  • 22
  • 172
  • 153
datta ram
  • 41
  • 4
  • Did you solve this? None of the answers below seem to apply to solution desired. I am experiencing the same problem with my data, too. – lrthistlethwaite Mar 08 '17 at 21:56

2 Answers2

1

Just try have a look at your initialization part for the obs. prob. matrix. if you change the first two probs (for state "S") to other than zeros, baumwelch algo works just fine. I run it using RStudio.

almaysa
  • 11
  • 1
1

That happens when one or more of the symbols, defined in 'initHMM', do not appear in the observations.

In your case you define the symbols "i" and "m" but your observation only contains "m"s.

Either add some "i"s before you call 'baumWelch' or delete the symbol in the call to 'initHMM'.

jboi
  • 11,324
  • 4
  • 36
  • 43