Skip to content

Accept cmdstanvb, draws_array or draws_matrix as fitted_params #390

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

Merged
merged 4 commits into from
Dec 8, 2020

Conversation

rok-cesnovar
Copy link
Member

Summary

Fixes #387

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):
Rok Češnovar, Uni. of Ljubljana

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses:

used draws_to_csv in process_fitted_params
added tests
@codecov-io
Copy link

codecov-io commented Dec 8, 2020

Codecov Report

Merging #390 (cf72fe3) into master (1eb251b) will decrease coverage by 1.86%.
The diff coverage is 95.08%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #390      +/-   ##
==========================================
- Coverage   88.22%   86.35%   -1.87%     
==========================================
  Files          12       12              
  Lines        2683     2704      +21     
==========================================
- Hits         2367     2335      -32     
- Misses        316      369      +53     
Impacted Files Coverage Δ
R/model.R 79.56% <ø> (-0.98%) ⬇️
R/data.R 97.56% <95.08%> (-2.44%) ⬇️
R/install.R 43.54% <0.00%> (-8.41%) ⬇️
R/run.R 93.39% <0.00%> (-2.21%) ⬇️
R/utils.R 92.20% <0.00%> (-1.30%) ⬇️
R/read_csv.R 97.56% <0.00%> (-1.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1eb251b...cf72fe3. Read the comment docs.

R/data.R Outdated
Comment on lines 127 to 149
sampler_diagnostic_names <- c("accept_stat__", "stepsize__", "treedepth__", "n_leapfrog__", "divergent__", "energy__")

n <- posterior::niterations(draws)
n_chains <- posterior::nchains(draws)
if (is.null(sampler_diagnostics)) {
# create dummy sampler diagnostics due to CmdStan requirement for all columns in GQ
sampler_diagnostics <- rep(0, n * length(sampler_diagnostic_names) * n_chains)
dim(sampler_diagnostics) <- c(n, n_chains, length(sampler_diagnostic_names))
sampler_diagnostics <- posterior::as_draws_array(sampler_diagnostics)
posterior::variables(sampler_diagnostics) <- sampler_diagnostic_names
}

# the columns must be in order "lp__, sampler_diagnostics, parameters"
variables <- posterior::variables(draws)
# create a dummy lp__ column if it does not exist
if ("lp__" %in% variables) {
lp__ <- NULL
} else {
lp__ <- rep(0, n * n_chains)
dim(lp__) <- c(n, n_chains, 1)
lp__ <- posterior::as_draws_array(lp__)
posterior::variables(lp__) <- "lp__"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, but I think there's a slightly nicer way code it using the posterior::draws_array() constructor. I can do that in a few minutes and push it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be fantastic! Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just pushed it. Let me know if you like it. If not we can revert because what you had definitely also worked.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like it.

@jgabry
Copy link
Member

jgabry commented Dec 8, 2020

I also just update the doc for the fitted_params argument.

@rok-cesnovar
Copy link
Member Author

Oh right, thanks!

@jgabry
Copy link
Member

jgabry commented Dec 8, 2020

I didn't test this on any of my own models but the tests you wrote seem like they cover all the cases, so if you like the coding changes I made to draws_to_csv() then I think this is probably ready to go.

@rok-cesnovar
Copy link
Member Author

Everything looks much nicer! Thanks. Will merge when tests pass.

@jgabry
Copy link
Member

jgabry commented Dec 8, 2020

Looks like all checks are passing so I'm going to go ahead and merge this.

@jgabry jgabry merged commit 9008240 into master Dec 8, 2020
@jgabry jgabry deleted the allow_draws_array_or_matrix_for_fittedparams branch December 8, 2020 22:02
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

Successfully merging this pull request may close these issues.

Allow $generate_quantities() to directly use draws_array objects
3 participants