Dear Community,
I have to split up my code in order to use the sample/optmize procedure and the generate quantities procedure separately.
Thus, I am using cmdstan and cmdstanpy in order to achieve this goal (standalone generated quantities procedure).
- 8.8 Program block: generated quantities | Stan Reference Manual
- 27.7 Stand-alone generated quantities and ongoing prediction | Stan User’s Guide
- https://mc-stan.org/cmdstanpy/examples/Run%20Generated%20Quantities.html
Furthermore, I will write a lot of different models that share many similarities and thus, I will make extensive use of the include statement
Description of the problem
If I use my stan file with cmdstan while copying all program blocks together, including the generated_quantities block, the output is fine and can be obtained in a single run. Nevertheless, I have to split it up.
In more detail, this works!
/*
* file: fit_alltogether.stan
*/
#include models/larson_miller_lognormal.stan
#include data_block.stan
#include generic/qr_decomposition.stan
#include parameter_block.stan
#include generic/qr_transformed_parameter.stan
#include generic/model_block.stan
// this should be moved into a separate file!
#include generic/generated_quantities_plugin_prediction.stan
I run this via:
fit_alltogether method=optimize algorithm=lbfgs tol_grad=1e-8 tol_param=1E-8 tol_rel_grad=1e-4 tol_obj=1E-12 tol_rel_obj=1E-8 history_size=6 iter=100000 data file=mytempfilename.json output file=output.csv
Nevertheless, if I split this file up into two files, say:
- fit_alone.stan
- gq.stan
it does not work anymore.
/*
* file: fit_alone.stan
*/
#include models/larson_miller_lognormal.stan
#include data_block.stan
#include generic/qr_decomposition.stan
#include parameter_block.stan
#include generic/qr_transformed_parameter.stan
#include generic/model_block.stan
// no generated quantities here
and the gq_file
/*
* file: gq.stan
*/
#include models/larson_miller_lognormal.stan
#include data_block.stan
#include generic/qr_decomposition.stan
#include parameter_block.stan
#include generic/qr_transformed_parameter.stan
#include generic/model_block.stan
#include generic/generated_quantities_plugin_prediction.stan
I run the fit program in the first place while runnig gq as standalone afterwards. Nothing is changed within the included program blocks.
fit_alone method=optimize algorithm=lbfgs tol_grad=1e-8 tol_param=1E-8 tol_rel_grad=1e-4 tol_obj=1E-12 tol_rel_obj=1E-8 history_size=6 iter=100000 data file=mytempfilename.json output file=output.csv
gq generate_quantities fitted_params=output.csv data file=mytempfilename.json output file=gq_out.csv
The invocation of gq leads to the error:
...
Mismatch between model and fitted_parameters csv file "output.csv"
...
Expected result:
I would expect to see no issues at allow, since it worked previously (see fit_alltogether), nevertheless of the implemented details in the includes statement.
If you need more details, please let me know and I will provide these as soon as possible.
Thanks in advance.