【问题标题】:conditional probability modification of one node in Bayesian network (R code)贝叶斯网络中一个节点的条件概率修改(R代码)
【发布时间】:2020-11-02 05:03:25
【问题描述】:

在估计贝叶斯网络中的条件概率后, 我问了一个节点(“Inlet_gas_total_pressure”)的概率如下;

bn.mle.before$"Inlet_gas_total_pressure"

节点Inlet_gas_total_pressure的参数(多项分布)

条件概率表:

      no      yes 
0.843127 0.156873 

bn.mle.before$"Inlet_gas_total_pressure"$prob

      no      yes 
0.843127 0.156873 

我想将“是”的概率值从 0.156873 更改为 0.4。
我怎样才能做到这一点 ? 以下是我的试验,但失败了。

bn.mle.before$"Inlet_gas_total_pressure" <- list(prob=c("no"=0.6, "yes"=0.4))

check.fit.dnode.spec(value, node = name) 中的错误: 节点Inlet_gas_total_pressure的条件概率分布必须是表、矩阵或多维数组。

请帮帮我。

【问题讨论】:

  • 错误提示它不应该是一个列表。看看str(bn.mle.before$"Inlet_gas_total_pressure"),看看它是什么类型的对象,甚至是dput(bn.mle.before$"Inlet_gas_total_pressure"),然后用同样的方法构造你的新表

标签: r bayesian-networks


【解决方案1】:

我遇到了同样的问题。 下面是一些玩具示例,将向您展示如何挽救这一天。

library(bnlearn)
Learning.set4=cbind(c("Yes","Yes","Yes","No","No","No"),c("Blue","Green","Blue","Green","Green","Green"),c(9,10,8,3,2,1))
Learning.set4=as.data.frame(Learning.set4)
Learning.set4[,c(3)]=as.numeric(as.character(Learning.set4[,c(3)]))
colnames(Learning.set4)=c("Cause1","Cause2","Cons")
b.network=empty.graph(colnames(Learning.set4))
struct.mat=matrix(0,3,3)
colnames(struct.mat)=colnames(Learning.set4)
rownames(struct.mat)=colnames(struct.mat)
struct.mat[2,3]=1
struct.mat[1,3]=1
bnlearn::amat(b.network)=struct.mat
haha=bn.fit(b.network,Learning.set4)

print(haha$Cause1$prob)

T=haha$Cause1$prob
T[[1]]=0.8
T[[2]]=0.2

haha$Cause1=T
print(haha$Cause1$prob)

我已成功更改节点 Cause1 的概率

干杯

【讨论】:

  • 非常感谢您的帮助。我会试试。祝你有美好的一天!
  • 没问题。我的方法有点笨拙,即使它有效。如果有人有更好的解决方案,我很乐意使用它。干杯
【解决方案2】:
# a similar example

fit=bn.fit(dag,traindata)

# Below I want to set any zero prob to something small

for (i in 1:10) {
  my=fit[[i]]
  idx=which(my$prob==0)
  if (length(idx)>0){
    for (j in idx ) {
      my$prob[[j]]=0.001
      my$prob[[j-1]]=1-0.001
    }
  }
  fit[i]=list(my)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-05-29
    • 1970-01-01
    • 2014-05-13
    • 2013-11-13
    • 2022-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多