bnlearn package: unexpected cpdist (prediction) behaviour

649 views Asked by At

I encounter a problem that goes beyond my understanding. I have made a simple reproducible example for you to test it out.

Basically I create a Bayesian network with two strongly correlated variables that are linked together. One would expect that if one of them is high, the other one should also be (Since they are directly linked).

library(bnlearn)

Learning.set4 = cbind(c(1,2,1,8,9,9),c(2,0,1,10,10,10))
Learning.set4 = as.data.frame(Learning.set4)
colnames(Learning.set4) = c("Cause","Cons")
b.network = empty.graph(colnames(Learning.set4))
struct.mat = matrix(0,2,2)
colnames(struct.mat) = colnames(Learning.set4)
rownames(struct.mat) = colnames(struct.mat)
struct.mat[1,2] = 1

bnlearn::amat(b.network) = struct.mat
haha = bn.fit(b.network,Learning.set4)

# Here we get a mean that is close to 10    
seems_logic_to_me=cpdist(haha, nodes="Cons", 
                                evidence=list("Cause"=10), method="lw")

# Here I get a mean that is close to 5, so a high value 
# of Cons wouldn't mean anything for Cause?    
very_low_cause_values = cpdist(haha, nodes="Cause",  
                                 evidence=list("Cons"=10), method="lw")

Could anyone enlighten me here on the reason why it doesn't work with the lw method? (You can try with ls and it seems to work fine).

lw stands for likelihood weighting

UPDATE: Got the solution from the maintainer. Adding the following at the end will print the the expected prediction:

print (sum(very_low_cause_values[, 1] * attr(very_low_cause_values, "weights")) / sum(attr(very_low_cause_values, "weights")))

0

There are 0 answers