2
votes

I'm using an r-package "bnlearn" to work with a bayes net I have constructed:

bn.gs <- gs(x = dat, cluster = NULL, whitelist = wl, blacklist = bl, test = NULL, alpha = 0.05, B = NULL, debug = FALSE, optimized = TRUE, strict = FALSE, undirected = FALSE)

It gives me a nice plot and everything seems to work well. All the variables are continuous and between -1 and 1. The feeding variables (those with no parents) were generated as below (N = 1000):

A <- runif(N, min=-1, max=1)

Let's assume that my variables are A, B, ... Z, and I know the values of C, G and M. Now I would like to predict the values of the rest of the nodes (A, B, D, ...) given C, G and M. As far as I am concerned, predict() works for one node at a time.

Is there a method to predict multiple nodes simultaneously, or should I end up getting right values by applying predict() to each node at time? I already tried to predict the value for node "A", given the value of "C":

predict(bn.gs, node = "A", testdata, debug = TRUE)

where testdata is a data frame in this form:

A    B    C    D    E    ...
0.0  0.0  0.7  0.0  0.0  ...

but I get this:

* predicting values for node A.
  > prediction for observation 1 is nan with predictor:
    (0.000000) + (0.000000) * (nan) + (0.000000) * (nan)
[1] NA

I'm positive that I am doing something wrong here. In my network there are arcs C -> S -> A. Also "nan"s are weird, since my network should be well defined.

Thank you already :).

1
As far as I know, there is no way to predict more than one node at a time in bnlearn. Your options are to use a loop or an apply function in bnlearn or to download Genie (different software). Genie can adjust the probabilities for all nodes at once.Michal

1 Answers

0
votes

Just in case others may look for the answer as well, I did solve this problem by using rbmn package. After creating a bn object using bnlearn, I did following:

my.bn.par <- bn.fit(x = bn.gs, data = dat)

library("rbmn")

my.bn.par.rbmn <- bnfit2nbn(my.bn.par)
print8nbn(my.bn.par.rbmn)
my.bn.par.mn <- nbn2mn(my.bn.par.rbmn)

# This is the names vector for my nodes:
names <- c("A","B","C","D","E")

# Names of given variables
obsnames <- c("C","E")

# Values for given variables
obsval <- c(0.51,-0.24)

# Names of variables to be predicted
prednames <- setdiff(names, obsnames)

# Then predict all the unknown variables
print8mn(condi4joint(my.bn.par.mn, par = prednames, pour = obsnames, x2 = obsval))

The method was presented in Marco Scutari's book "Bayesian Networks".