Add a function for generating initial values from a CmdStanMCMC object, csv files or a draws object #930
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Submission Checklist
Summary
I initially built these functions for another package I'm working on last week. But yesterday I saw #876, so I decided to share them. I did see @SteveBronder is already working on it, but since I had them ready, here's a PR for them - if you decide to go with the other approach, no worries!
This PR adds a generic method
generate_inits
which creates a lists of lists that can be used to pass to the init argument for sampling.There are three specific methods for generating inits from CmdStanMCMC object, a vector of csv files with draws output, or a draws object.
The methods each takes as arguments:
draws
with options "last", "sampling", "all". If the argument is "last", it uses a new function I wroteread_last_draws
which retrieves the last draw recorded from the csv files. This does not use the builting read_cmdstan_csv function, but a similar method. This can be useful for very large fits - it takes 0-2 seconds regardless of the size of the filesThe general logic is that for each chain, it:
All the methods are documented, and include unit tests.
Examples
inits from a CmdStanMCMC object
inits from a vector of file paths
inits from a draws object
warmup and then use the final draws for the inits of a separate sampling stage
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):
Vencislav Popov
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: