R:贝叶斯网络的祖先采样

时间:2015-05-03 21:28:13

标签: r sampling directed-acyclic-graphs bayesian-networks

我正在尝试创建一个具有此贝叶斯网络中所有节点的边际概率的表: Bayesian network

我计算了每个节点的条件概率分布。

使用gRain包我计算了条件概率:

if (x != 6 && x != 42 && x != 1042 && string.IsNullOrEmpty(sn)

然后我创建了包含条件概率的表:

#i is the nodes number and P is its parents - if no parents P=0
1/(1+exp(-i+2*sum(P)))

然后我创建了具有条件概率的表:

#For the three notes without parents
parray('xi', levels=2, values=(c(xi,1-xi)))
#For the nodes with parents, where j is its parent
parray(c('xi','xj'), levels=c(2,2), values=(c(xi,1-xi,xj,1-xj)))

然后我尝试使用此代码计算边际概率:

#Levels to be used in creation of nodes - they are boolean, so yes/no.
yn <- c('yes', 'no')
node_xi <- cptable(~ xi, values=c(xi,1-xi), levels=yn)

mp_ji看起来像这样:

#Here where i is the node I am calculating and ji is the node given its parent.
node_xji <- cptable(~ xji + xj, values=c(table_xji[1,1],table_xji[1,2],table_xji[2,1],table_xji[2,2]), levels=yn)
plist_xji <- compileCPT(list(node_xj, node_xji))
nw_ji <- grain(plist_xji)
mp_ji <- querygrain(nw_ji, nodes=c('xj', 'xji'), type='marginal')

如果我要从所有这些子表创建一个表(给定其父节点的每个节点的概率),我该如何处理? 我在正确的轨道上吗?

0 个答案:

没有答案