-
-
Notifications
You must be signed in to change notification settings - Fork 66
Allow selecting subset of variables when using as_cmdstan_fit()
#1121
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
base: master
Are you sure you want to change the base?
Conversation
|
Still need to add tests |
| if (!is.null(variables)) { | ||
| csv_contents$metadata$variables <- posterior::variables(csv_contents$post_warmup_draws) | ||
| } |
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.
Overriding the metadata$variables is necessary to avoid errors when subsequently calling methods like draws.
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.
Doing csv_contents$metadata$variables <- variables doesn't work because variables can contain names of non-scalar parameters and we need the names of the individual elements (e.g. variables = "beta" but we need metadata$variables = c("beta[1]", "beta[2]"), etc.).
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.
Ideally we would also override metadata$stan_variables and metadata$stan_variable_sizes, but those are bit trickier to get right and I don't think the methods that use those are even available after creating an object just from CSV files (e.g. methods like unconstrain_draws() and others that require calling init_model_methods won't be available if we can't recompile).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1121 +/- ##
==========================================
+ Coverage 87.17% 87.35% +0.17%
==========================================
Files 14 14
Lines 5973 6002 +29
==========================================
+ Hits 5207 5243 +36
+ Misses 766 759 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| metadata$variables <- union(metadata$sampler_diagnostics, metadata$variables) | ||
| if (!user_variables_subset) { | ||
| # because for pathfinder variables and diagnostics are read in together, | ||
| # if user hasn't selected a custom subset of variables we need to include | ||
| # all diagnostics | ||
| variables <- union(metadata$sampler_diagnostics, variables) | ||
| } |
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.
Pathfinder is a special case because diagnostics and variables are read in together (mcmc reads them in separately). So some special handling was needed to subset properly for pathfinder.
Submission Checklist
Summary
Adds
variablesargument toas_cmdstan_fit()to allow creating objects from a subset of variables in the CSV files.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: