Bnlearn:预测多个节点值

Bnlearn: Predicting multiple node values

我正在使用 r-package "bnlearn" 来处理我构建的贝叶斯网络:

bn.gs <- gs(x = dat, cluster = NULL, whitelist = wl, blacklist = bl, test = NULL, alpha = 0.05, B = NULL, debug = FALSE, optimized = TRUE, strict = FALSE, undirected = FALSE)

它给了我一个很好的情节,一切似乎都很顺利。所有变量都是连续的,并且在 -1 和 1 之间。喂养变量(没有 parents 的变量)生成如下(N = 1000):

A <- runif(N, min=-1, max=1)

假设我的变量是 A、B、... Z,并且我知道 C、G 和 M 的值。现在我想预测其余节点的值(A、B , D, ...) 给定 C、G 和 M。就我而言,predict() 一次适用于一个节点。

是否有同时预测多个节点的方法,或者我是否应该通过对每个节点应用 predict() 来最终获得正确的值?给定 "C":

的值,我已经尝试预测节点 "A" 的值
predict(bn.gs, node = "A", testdata, debug = TRUE)

其中 testdata 是这种形式的数据框:

A    B    C    D    E    ...
0.0  0.0  0.7  0.0  0.0  ...

但我明白了:

* predicting values for node A.
  > prediction for observation 1 is nan with predictor:
    (0.000000) + (0.000000) * (nan) + (0.000000) * (nan)
[1] NA

我确定我在这里做错了什么。在我的网络中有弧线 C -> S -> A。"nan"s 也很奇怪,因为我的网络应该定义明确。

谢谢你了:)。

以防万一其他人也可能寻找答案,我确实使用 rbmn 包解决了这个问题。使用 bnlearn 创建 bn 对象后,我做了以下操作:

my.bn.par <- bn.fit(x = bn.gs, data = dat)

library("rbmn")

my.bn.par.rbmn <- bnfit2nbn(my.bn.par)
print8nbn(my.bn.par.rbmn)
my.bn.par.mn <- nbn2mn(my.bn.par.rbmn)

# This is the names vector for my nodes:
names <- c("A","B","C","D","E")

# Names of given variables
obsnames <- c("C","E")

# Values for given variables
obsval <- c(0.51,-0.24)

# Names of variables to be predicted
prednames <- setdiff(names, obsnames)

# Then predict all the unknown variables
print8mn(condi4joint(my.bn.par.mn, par = prednames, pour = obsnames, x2 = obsval))

Marco Scutari 的书中介绍了该方法 "Bayesian Networks"。