Fix saving and loading ulam() models when using cmdstanr; Fix log likelihood bugs for multi_normal outcome variables#425
Fix saving and loading ulam() models when using cmdstanr; Fix log likelihood bugs for multi_normal outcome variables#425timjzee wants to merge 7 commits intormcelreath:masterfrom
Conversation
|
I also fixed issues that arise when specifying The second issue turned out to be an indexing issue specific to multivariate outcomes, see this explanation for full details, including example model. I made sure that my fix did not break anything for models with a single outcome variable. Paging @rmcelreath , as these issues (including the temporary file issue) are likely to affect other users and my fixes are small enough to quickly check. |
|
Hello! Could you potentially clarify this edit - from a student at their wits end with this issue :') I run my model and everything finishes fine. So do I immediately run the stanfit <- as_cmdstan_fit(cmdstanfit$output_files()) line of code afterwards? I tried doing that and running the line of code exactly as shown, but it gives me the error "Error: object 'cmdstanfit' not found. I replaced cmdstanfit with the name of my model and it give me the error of "Error in ModelName$output_files : $ operator not defined for the s4 class." Any help would be greatly appreciated cause this issue has been a huge set back and I've tried to understand all the coding behind the scenes but can't make any sense of it. Thank you! |
|
Hi @FishModeler , Basically what you have to do is replace your current install of the rethinking package with my version of the rethinking package. To do that, open up R and do the following:
That should be it! |
|
Thank you so much for your quiet reply! Your help has relieved so much stress. |
|
No problem! I need a little more information to help you with your new error. Why don't you edit your issue #443 and include the code you're trying to run and the full error message. |
By default, cmdstanr saves model output in temporary files and only loads that data into memory when it is required. This means that when a fitted model is written to a file, a lot of data is not included in that file. So when the current R session is exited, the temporary files are deleted, and the fitted models can no longer be fully loaded. See example code below:
The fix consists of two lines of code, and was inspired by these relevant pages:
https://discourse.mc-stan.org/t/error-in-read-cmdstan-csv-assertion-on-files-failed/30150
https://mc-stan.org/cmdstanr/reference/read_cmdstan_csv.html
https://mc-stan.org/cmdstanr/reference/fit-method-save_output_files.html
Using
stanfit <- as_cmdstan_fit(cmdstanfit$output_files())we assign the data from the temporary files tostanfitand store the data inside the ulam object.Using this fix, the example code works:
This was tested on: