-
-
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
laplace method #800
laplace method #800
Conversation
Example usagefile <- file.path(cmdstan_path(), "examples/bernoulli/bernoulli.stan")
mod <- cmdstan_model(file)
mod$print()
stan_data <- list(N = 10, y = c(0,1,0,0,0,0,0,0,0,1))
# pass CmdStanMLE from optimize to 'mode' argument of laplace
fit_mode <- mod$optimize(data = stan_data, jacobian = TRUE)
fit_laplace <- mod$laplace(data = stan_data, mode = fit_mode)
fit_laplace$summary()
fit_laplace$draws("theta")
# can also pass CSV file to 'mode' argument
fit_laplace <- mod$laplace(data = stan_data, mode = fit_mode$output_files())
fit_laplace$summary()
# if mode isn't specified optimize is run internally first
# can pass arguments to optimize via opt_args
fit_laplace <- mod$laplace(data = stan_data, opt_args = list(iter = 200))
fit_laplace$summary() |
Codecov Report
@@ Coverage Diff @@
## master #800 +/- ##
==========================================
+ Coverage 88.19% 88.49% +0.30%
==========================================
Files 12 12
Lines 4218 4347 +129
==========================================
+ Hits 3720 3847 +127
- Misses 498 500 +2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
I think this is ready for review. I've implemented everything that I can think of. Anything I need to do when adding a new method that I'm forgetting? |
Any ideas why everything is passing except with the WSL backend? |
will continue to accept output_samples to not break backwards compatibility
I'm still in progress of testing, but one observation now. The laplace method has argument |
I agree. Those are the names CmdStan uses, but I actually added the |
I guess this should be done in CmdStan, but mentioning now here. It would be nice to be able to be able to parallelize the computation for the draws from the approximation similarly way as |
Here's an example to do resample importance sampling
|
Is it possible to get draws without evaluating |
I agree. But yeah I think this is more of a CmdStan issue than a CmdStanR issue. |
Not by changing anything in CmdStanR unfortunately. All we're doing is providing access to what CmdStan has already computed and written to CSV, so this would need to happen in CmdStan. |
Cool, thanks! Maybe we should put this in the documentation somewhere. |
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.
Looks good. Added one suggestion
@andrjohns When you have time would you be able to check if you can figure out why this is failing on WSL only? Thank you! |
Ack sorry for forgetting about this! I'll have time to dig in on Friday |
No worries, and thanks! |
Just a heads up that I'm still working on this, I'm on an M1 Mac as my daily driver now so I'm just ironing out some kinks on getting WSL running in my windows VM |
Ok thanks for working on this @andrjohns |
@jgabry ended up being a super minor issue of path handling, all good to go now! |
Awesome, thanks @andrjohns! Glad it turned out to be a simple fix. Everything is passing so I'll go ahead and merge. |
Submission Checklist
Summary
Closes #760
Builds off of PR #799
Implements new method
CmdStanModel$laplace()
with new fitted model classCmdStanLaplace
.Follows the design from @WardBrian in #760 (comment).
Copyright and Licensing
Please list the copyright holder for the work you are submitting
(this will be you or your assignee, such as a university or company):
Columbia University
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: