【发布时间】:2017-09-10 15:21:23
【问题描述】:
我正在使用 R 中的 gRain 包创建贝叶斯网络。尝试编译条件概率表时,出现错误“表尺寸不匹配”。有问题的表格采用 A|B 的形式,其中 A 可以取三个可能的值,B 可以取两个。根据六种可能的组合,我在 cptable 定义中总共输入了 12 个值。任何帮助将不胜感激,因为我已经检查和研究无济于事并且看不到出了什么问题。这是我的代码。
# define levels
lh <- c("low", "high")
lmh <- c("low", "medium", "high")
# specify the conditional probability tables
eh <- cptable(~eh, values=c(0.2, 0.8), levels=lh)
inf.oil.eh <- cptable(~inf | oil:eh, values = c(0.9, 0.1, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99), levels=lh)
bp.oil <- cptable(~bp | oil, values=c(0.9, 0.1, 0.1, 0.9, 0, 1, 0.1, 0.9, 0.4, 0.6, 0.5, 0.5), levels=lmh)
oil.eh <- cptable(~oil | eh, values=c(0.9, 0.1, 0.05, 0.95), levels=lh)
rt.inf.eh <-cptable(~rt | inf:eh, values=c(0.9, 0.1, 0.1, 0.9, 0.1, 0.9, 0.01, 0.99), levels=lh)
# compile the tables
plist <- compileCPT(list(eh, oil.eh, inf.oil.eh, bp.oil, rt.inf.eh))
错误如下:
Error for v,pa(v): bp, oil
List of 2
$ bp : chr [1:3] "low" "medium" "high"
$ oil: chr [1:2] "low" "high"
num [1:12] 0.9 0.1 0.1 0.9 0 1 0.1 0.9 0.4 0.6 ...
Error in compileCPT(list(eh, oil.eh, inf.oil.eh, bp.oil, rt.inf.eh)) :
Table dimensions do not match!
【问题讨论】: