Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inaccurate HydeSim() predictions with discrete nodes #108

Open
derekpowell opened this issue Sep 13, 2018 · 0 comments
Open

Inaccurate HydeSim() predictions with discrete nodes #108

derekpowell opened this issue Sep 13, 2018 · 0 comments

Comments

@derekpowell
Copy link

I'm finding that HydeNet is giving pretty inaccurate predictions for a very simple completely discrete network. I'm wondering if this is a bug.

Here's a reproducible example for a two node network. The network a single parent and a single "evidence" node child:

node1 --> evid

Where p(node1) = .50, p(evid|node1) = .80 and p(evid|~node1) = .50.

make_custom_cpt <- function(ps, dims, dim_names, data) {
  # makes custom cpt in HydeNet format
  output <- array(ps, dim=dims, dimnames=dim_names)
  attr(output, "model") <- data
  attr(output, "class") <- c("cpt","array")
  
  return(output)
}

set.seed(42)
# first create some easily-calculated CPTs
n1 <- xtabs(~ node1, data = data.frame(node1 = c(rep("Yes",500), rep("No",500))))
n2 <- make_custom_cpt(c(.80, .5, .2, .5), c(2,2), list(node1=c("Yes","No"), evid = c("Yes","No") ), NULL)

mynet <- HydeNetwork(list(n1, n2))

# predict conditioning on no evidence, and observing the evidence
model1 <- compileJagsModel(mynet, data= data.frame(evid=2))

post1 <- HydeSim(model1,
                 variable.names = c("node1"),
                 n.iter = 1e6
)

p_obs_evidence <- mean(as.numeric(post1$node1)) - 1

p_obs_evidence

The result is:

> p_obs_evidence
[1] 0.714207

But this is easy enough to solve analytically by hand, and it should be .615. So HydeSim() is getting P(node1|evidence) pretty seriously wrong. Is this a bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant