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

Simulate data based on probabilistic odin compare #412

Open
edknock opened this issue Jul 3, 2023 · 1 comment
Open

Simulate data based on probabilistic odin compare #412

edknock opened this issue Jul 3, 2023 · 1 comment

Comments

@edknock
Copy link
Contributor

edknock commented Jul 3, 2023

Now we have the ability to write probabilistic compare functions within odin, it makes sense to try to use them for not just log-likelihood calculation, but also random generation of data.

Consider a toy model

gen <- odin.dust::odin_dust({
  initial(y) <- 0
  update(y) <- y + rnorm(0, 1)
  
  initial(z) <- 0
  update(z) <- z + rpois(1)
  
  scale_y <- user(1)
  observed_y <- data()
  
  compare(observed_y) ~ normal(y, scale_y)
  
  shape_z <- user(1)
  observed_z <- data()
  
  compare(observed_z) ~ negative_binomial_mu(shape_z, z)
})

We can then simulate from this model, and compare it to some data

np <- 10
mod <- gen$new(list(), 0, np, seed = 1L)
y <- mod$run(50)

data <- data.frame(time = 50, observed_y = 3, observed_z = 4)
mod$set_data(dust::dust_data(data, "time"))
mod$compare_data()

We could perhaps instead want to simulate data based upon the simulation of the model. Something like a mod$simulate_data() function. Maybe there are inputs we would want to use for this, e.g. the time-steps at which we want to simulate data, or which data streams we want to simulate data for (other data streams appearing in the compare could just return NA values).

Welcoming thoughts or flagging up potential issues from those who contributed to previous discussion (mrc-ide/odin.dust#130): @richfitz, @annecori, @MJomaba, @lwhittles, @cwhittaker1000. Feel free to suggest others who would provide useful input.

@edknock
Copy link
Contributor Author

edknock commented Jul 3, 2023

Potential issue - how would distributions where there are two (or more) bits of data be handled? Obvious example is binomial, where the number of trials/tests and number of "successes" might both be treated as data in the odin code. One might want to input the number of tests and simulate the number of "successes"?

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