integrated-inferences/CausalQueries

stan sampling fails when specifying censored types

Closed this issue · 10 comments

minimal working example

This works:

stanfit <- CausalQueries:::stanmodels$simplexes

model <-  make_model("X->Y") 

data_compact <- 
  collapse_data(
  data.frame(X=c(1,1), Y=c(1,1)), 
  model)

stan_data_0 <- 
  CausalQueries:::prep_stan_data(
    model, data_compact)

updated <- rstan::sampling(stanfit, stan_data_0, refresh = 1)

This fails:

stan_data_1 <- 
  CausalQueries:::prep_stan_data(
    model, data_compact,
    censored_types = c("X1Y0", "X0Y0", "X0Y1"))

stan_data_1$parmap

# This blows up
bad <-  rstan::sampling(stanfit, stan_data_1, refresh = 1, iter = 10000)

diagnosis thus far

This issue is unrelated to normalization with censored types as initially expected

I'll try adding a tiny offset to the multinomial inputs asap today and test.

Great that it works, but yeah, sort of a dodgy fix. Does it cause any numerical stability issues?

What if we just specify initial values for this case? If the problem are the 0s evaluating to -inf when the mcmc tries to start sampling in log space then that could maybe work right?

Something vaguely related to this popped up on the Stan forum 5 years ago

https://discourse.mc-stan.org/t/error-occurred-during-calling-the-sampler-sampling-not-done/6061

The thing that gets me about this though is that everything worked fine until the update. And the changes to the code (except the new array syntax) don't look massive.

I wonder: did we just always get some sort of floating point voodoo with the old version that prevented things from evaluating exactly to 0?

Since the fix is merged I'll test the previous CRAN test failure and close the issues.