-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
Minor issues with new log_prob, expose_functions and other new methods #720
Comments
In fact, one of the purposes of CmdStanR is to avoid making a lot of mistakes that we made with RStan ;) |
This is why I have refrained from making a minor release for all this new stuff. |
Thanks. I finally have a bit more time now! |
Oh excellent catch, thanks Jonah! I'll update the examples and draft some vignettes for the model methods and expose-functions over the next few days. In terms of simplifying the approach compared to fit_mcmc <- cmdstanr_example("logistic", method = "sample")
fit_mcmc$init_model_methods()
upars <- fit_mcmc$unconstrain_pars(pars=list("alpha"=0.1, "beta"=c(-0.8, -0.2, 0.3)))
fit_mcmc$log_prob(upars = upars) I think this would be a bit more intuitive if the cpars <- list("alpha"=0.1, "beta"=c(-0.8, -0.2, 0.3))
upars <- fit_mcmc$unconstrain_pars(pars = cpars)
# The following should return identical values
fit_mcmc$log_prob(pars = cpars)
fit_mcmc$log_prob(pars = upars) How does that sound? |
Awesome, thanks!
I like the idea of So I like that you added a way to just get the "skeleton", but what if the skeleton thing were its own method instead of just an argument to fit_mcmc <- cmdstanr_example("logistic", method = "sample")
fit_mcmc$init_model_methods()
skel <- fit_mcmc$constrain_pars(skeleton_only = TRUE)
skel$alpha <- 1
skel$beta <- rep(1, 3)
upars <- fit_mcmc$unconstrain_pars(skel)
fit_mcmc$log_prob(upars) Maybe instead calling Anyway, just an idea, I'm definitely open to other options. |
I've been using these new methods a fair amount lately for implementing cmdstanr support in the iwmm package. In addition to extending a big thanks to @andrjohns for these methods, I thought I'd add one thought on the interface: A common task in the iwmm package that could be easier is to unconstrain / constrain all the draws from a fitted model. Currently (I think) this requires a fair amount of wrapping code, see here. I imagine there are other cases in which (un)constraining all draws is something that is useful. So I was wondering if this is something that could be implemented on the cmdstanr side, considering that the interface does not need to match rstan's unconstrain_pars / |
Good ideas all! I completely agree @jgabry and @n-kall, I'll make those updates @mitzimorris the |
Sorry for coming to this somewhat late, but in the Just FYI, we then pass new samples of unconstrained parameters to |
Closing since I think these things were implemented in various PRs. Feel free to reopen if we're still missing anything. |
@andrjohns A few things about the awesome new methods you added (sorry I didn't have a chance to comment on these during the review of the PRs, I was overloaded with other work at the time and am only having a chance to really play around with these now):
Errors in examples
The examples in the doc for
log_prob
,grad_log_prob
,constrain_pars
, andunconstrain_pars
all result in errors:So I think we need to insert a line calling
init_model_methods()
, right?For the
grad_log_prob
example I also get:Convenience of
log_prob
interfaceI also think we need to provide some examples of how to use these methods together in a more realistic setting because users won't be able to just type in numbers for
upars
, they'll need to create structured input forunconstrain_pars
and then pass the result ofunconstrain_pars
tolog_prob
, etc. Or can we provide some easier interface that combines these steps automatically or some other helper functions to make it smoother? People have always complained about how hard the methods in RStan are to use, so we don't necessarily need to copy those exactly here, we could wrap them in something more convenient if that's possible.Documentation for
expose_functions
I mentioned this in #590 (comment) but I think we're missing documentation on how users can access the functions from the functions block that get compiled when
compile_standalone=TRUE
(i.e., viamod$functions
). I also don't thinkexpose_functions
is documented anywhere.Thanks again for implementing these and sorry for the slow feedback!
The text was updated successfully, but these errors were encountered: