Reputation: 31
After estimating the conditional probability in Bayesian networks, I asked the probability of one node ("Inlet_gas_total_pressure") as follows;
bn.mle.before$"Inlet_gas_total_pressure"
Parameters of node Inlet_gas_total_pressure (multinomial distribution)
Conditional probability table:
no yes
0.843127 0.156873
bn.mle.before$"Inlet_gas_total_pressure"$prob
no yes
0.843127 0.156873
I want to change the probability value of "yes" from 0.156873 to 0.4.
How can I do that ?
The following was my trial, but fails.
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.
Please help me.
Upvotes: 3
Views: 589
Reputation: 1
# 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)
}
Upvotes: 0
Reputation: 183
I experienced the same problem. Here is some toy example that will show you how to save the day.
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)
I succesfully changed the probabilities for the node Cause1
Cheers
Upvotes: 1