DarrenRhodes
DarrenRhodes

Reputation: 1503

cpquery result varies wildly

The following code, when queried with cpquery gives wildly varying results. It only does this for the case when info == "False", all other cases give expected results. Further, removing the Boolean & from the cpquery just to leave info == "False" returns varying results. Any thoughts?

library(bnlearn)
library(Rgraphviz)

info_npt <- matrix(c(0.98, 0.02), nrow= 1, ncol = 2,
                   dimnames = list(NULL, c("True", "False")))
spec_npt <- matrix(c(0.98, 0.02), nrow = 1, ncol = 2,
                   dimnames = list(NULL, c("True", "False")))

feasible_npt <- array(c(0.98, 0.02,
                            0.02, 0.98,
                            0.90, 0.10,
                            0.02, 0.98),
                          dim = c(2,2,2),
                          dimnames = list(feasible = c("True", "False"),
                                          info = c("True", "False"),
                                          spec = c("True", "False")
                          )
)


feasible_net <- model2network(paste0("[feasible|info:spec]",
                                         "[info][spec]"))
feasible_fit <- custom.fit(feasible_net,
                               dist = list(feasible = feasible_npt,
                                           info = info_npt,
                                           spec = spec_npt)
)

## plotting

graphviz.plot(feasible_net, shape = "ellipse")

graphviz.chart(feasible_fit, type = "barprob", grid = TRUE,
               bar.col = "darkgreen", strip.bg = "lightskyblue")

## query

round(100 * 
        cpquery(feasible_fit,
                event = (feasible == "True"),
                evidence = (info == "False" & spec == "False"),
                n = 1e6),
      2)

Upvotes: 0

Views: 37

Answers (0)

Related Questions