bnlearn节点的错误尺寸

时间:2015-12-07 06:45:41

标签: r machine-learning bayesian-networks

我正在研究R中的一个简单问题。这是代码:

library(bnlearn)

dag <- model2network("[Location][Quality][Cost|Location:Quality][NoPeople|Location:Cost]")
plot(dag)

quality.values <- factor(c("Good", "Normal", "Bad"))
location.values <- factor(c("Good", "Bad"))
cost.values <- factor(c("High", "Low"))
nopeople.values <- factor(c("High", "Low"))

quality.prob <- array(c(0.3, 0.5, 0.2), dim = 3, dimnames = list(quality = quality.values))
location.prob <- array(c(0.6, 0.4), dim = 2, dimnames = list(location = location.values))
cost.prob <- array(c(0.8, 0.2, 0.6, 0.4, 0.1, 0.9, 0.6, 0.4, 0.6, 0.4, 0.05, 0.95), dim = c(2, 3, 2), dimnames = 
    list(cost = cost.values, quality = quality.values, location = location.values))
nopeople.prob <- array(c(0.6, 0.4, 0.8, 0.2, 0.1, 0.9, 0.6, 0.4), dim = c(2, 2, 2), dimnames = 
    list(NoPeople = nopeople.values, cost = cost.values, location = location.values))

condProbTable <- list(Location = location.prob, Quality = quality.prob, Cost = cost.prob, NoPeople = nopeople.prob)
bn <- custom.fit(dag, condProbTable)

除非我尝试此操作,否则会出现Error in check.dnode.vs.spec(dist[[cpd]], old = fitted[[cpd]]$parents, : wrong dimensions for node Cost错误。我不确定我做错了什么。我对R很陌生,所以任何帮助都会很棒。

作为参考,我正在尝试建立这个:

Bayesian network I'm trying to create

谢谢!

1 个答案:

答案 0 :(得分:1)

事实证明,这是一个大写问题。这样做

dag <- model2network("[location][quality][cost|location:quality][nopeople|location:cost]")

将解决问题。