我目前正在使用R中的bnstruct包创建一个DBN,每6个时间步骤中有9个变量。我有生物和非生物变量,我想防止生物变量成为非生物变量的父母。我想防止生物变量成为非生物变量的父变量。layering = c(1,1,2,2,2)
在 learn.dynamic.network()
.
但是,动态部分出现了一个问题:我想继续防止生物变量在每个时间步骤中成为非生物变量的父母,同时防止在t+1到t的任何变量之间出现边缘。我想在每个时间步骤中防止生物变量成为非生物变量的父母,同时防止t+1到t之间的任何变量出现边缘。
如果我在 layering =
:
我允许t-1的生物变量来解释t的非生物变量(我不希望这样)。
所以我试了一下。
## 9 variables for 6 time steps
test1 <- BNDataset(data = timedData,
discreteness = rep('d', 54),
variables = colnames(timedData),
node.sizes = rep(c(3,3,3,2,2,3,3,3,3), 6)
# num.time.steps = 6
)
## the 5 first variables are abiotic, the 4 last are biotics
dbn <- learn.dynamic.network(test1,
num.time.steps = 6,
layering = rep(c(1,1,1,1,1,2,2,2,2),6))
所以现在,我没有任何从生物变量到非生物变量的边缘(这很好),但我有从变量_t(n+1)到变量_t(n)的边缘。
我知道在 bnlearn
你可以创建一个你不想看到的边缘的 "黑名单",但我在 bnstruct 中没有看到任何对应的参数。有什么好办法吗?
用 mmhc
算法,您可以使用默认的 layer.struct
参数来指定哪些图层对之间允许有边。layer.struct
取一个二进制矩阵,其中单元格 i,j
是 1
层中的变量是否可以有边来往 i
到层中的变量 j
和 0
否则。
最好的使用方法是与你第一个解决方案的手动指定分层相结合。
完美,这两个参数的组合 layering =
和 layer.struct =
做到了我想要的。
我把我用的东西贴在这里只是为了提供一个例子。
## DBN study
dbn <- learn.dynamic.network(test1,
num.time.steps = 6,
layering = rep(c(1,1,1,1,1,2,2,2,2, # set 2 layers per time step
3,3,3,3,3,4,4,4,4,
5,5,5,5,5,6,6,6,6,
7,7,7,7,7,8,8,8,8,
9,9,9,9,9,10,10,10,10,
11,11,11,11,11,12,12,12,12)),
layer.struct = matrix(c(1,0,0,0,0,0,0,0,0,0,0,0, ## allow certain layers to connect to others by hand
1,1,0,0,0,0,0,0,0,0,0,0,
1,0,1,0,0,0,0,0,0,0,0,0,
1,1,1,1,0,0,0,0,0,0,0,0,
1,0,1,0,1,0,0,0,0,0,0,0,
1,1,1,1,1,1,0,0,0,0,0,0,
1,0,1,0,1,0,1,0,0,0,0,0,
1,1,1,1,1,1,1,1,0,0,0,0,
1,0,1,0,1,0,1,0,1,0,0,0,
1,1,1,1,1,1,1,1,1,1,0,0,
1,0,1,0,1,0,1,0,1,0,1,0,
1,1,1,1,1,1,1,1,1,1,1,1),c(12,12)))
谢谢你的快速回答,还有你的软件包