-
Notifications
You must be signed in to change notification settings - Fork 0
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
Support for stochastic models #9
Changes from all commits
7d9df44
c426af1
ab8c95a
5933546
d547962
0dec5fc
14ce6d8
3e1e1ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
##' Create a simple random walk sampler, which uses a symmetric | ||
##' proposal to move around parameter space. | ||
##' proposal to move around parameter space. This sampler supports | ||
##' sampling from models where the likelihood is only computable | ||
##' randomly (e.g., for pmcmc). | ||
##' | ||
##' @title Random Walk Sampler | ||
##' | ||
|
@@ -38,6 +40,9 @@ mcstate_sampler_random_walk <- function(proposal = NULL, vcv = NULL) { | |
"Incompatible length parameters ({n_pars}) and vcv ({n_vcv})") | ||
} | ||
} | ||
if (isTRUE(model$properties$is_stochastic)) { | ||
model$model$set_rng_state(rng) | ||
} | ||
Comment on lines
+43
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this be applied to different samplers? if so perhaps we should put this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. None of the other samplers can cope with stochastic models; they will be throwing errors! |
||
} | ||
|
||
step <- function(state, model, rng) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,3 +30,13 @@ test_that("validate sampler against model on initialisation", { | |
"Incompatible length parameters (1) and vcv (2)", | ||
fixed = TRUE) | ||
}) | ||
|
||
|
||
test_that("can draw samples from a random model", { | ||
set.seed(1) | ||
m <- ex_dust_sir() | ||
vcv <- matrix(c(0.0006405, 0.0005628, 0.0005628, 0.0006641), 2, 2) | ||
sampler <- mcstate_sampler_random_walk(vcv = vcv) | ||
res <- mcstate_sample(m, sampler, 20) | ||
expect_setequal(names(res), c("pars", "density", "details", "chain")) | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have not understood this comment well yet! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, it's out of date now after #10 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (and now it's gone) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would like to definitely chat through this and that sir model on call! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just for clarification, why is this returned as
list(set = model$set_rng_state)
instead of returningmodel$set_rng_state
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I anticipate that later we'll need
get = model$get_rng_state
too for cases where we have a stochastic model that we want to be able to restart