在下面的代码中,我试图创建一个矩阵,该矩阵将使用HMM(Hiden Markov Chain)的transProbes和emissionProbes。在运行循环时,第一个transProbes总是工作的,然后我得到一个emissionProbes的错误。
这就是我犯的错误。
hmm$emissionProbs[state, observation[1]]
中的错误:下标越界**
这是我的代码:
install.packages('HMM')
library(HMM)
hmm=initHMM(c("S1","S2","S3","S4","S5"),c("T1","T2","T3","T4","T5"), transProbs=matrix(c(0.40,0.06,0.13,0,0,0.4,0.68,0.38,0.5,1,0,0.13,0.38,0.25,0,0,0.1,0.13,0,0,0.2,0.03,0,0.25,0),5,5),emissionProbs=matrix(c(0.04,0,0,0,0.04,0.47,0.57,0.54,0.61,0.58,0.38,0.4,0.4,0.33,0.19,0.11,0.02,0.06,0.06,0.12,0,0,0,0,0.08),5,5))
a = sample(c(rep("Ta",100),rep("Tb",100),rep("Tc",100),rep("Td",100),rep("Te",100)))
b = sample(c(rep("Ta",100),rep("Tb",100),rep("Tc",100),rep("Td",100),rep("Te",100)))
observation = c(a,b)
baumWelch(hmm, observation, maxIterations=100, delta=1E-9, pseudoCount=0)
我知道可能为时已晚,但我也遇到了类似的问题。
在initHMM中,您将输出符号定义为"T1"、"T2","T5"。
然后,在你的观察中,你有"Ta","Tb","Te"。
baumWelch可能试图将您观察到的符号与可能的输出符号相匹配,但索引已用完,因此请确保您预期的输出符号与您的观察中的符号相匹配