gpt4 book ai didi

r - 贝叶斯网络中一个节点的条件概率修改(R代码)

转载 作者:行者123 更新时间:2023-12-04 17:57:02 26 4
gpt4 key购买 nike

在估计贝叶斯网络中的条件概率后,我问一个节点(“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

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

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

Error in check.fit.dnode.spec(value, node = name) : the conditional probability distribution of node Inlet_gas_total_pressure must be a table, a matrix or a multidimensional array.

请帮帮我。

最佳答案

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

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 的概率

干杯

关于r - 贝叶斯网络中一个节点的条件概率修改(R代码),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39610572/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com