bebi103.hmc.sample_cmdstanpy
- bebi103.hmc.sample_cmdstanpy(stan_file=None, sample_kwargs={}, remove_sample_files=True, no_logging=True)
Compile and sample out of a Stan file.
- Parameters:
stan_file (str) – Name of file containing stan code.
sample_kwargs (dict, default {}) – kwargs to be passed to the sample() method of a cmdstanpy.CmdStanModel instance.
remove_sample_files (bool, default True) – If True, remove CSV files of samples generated by CmdStan.
no_logging (bool, default False) – If True, disable logging from Stan.
- Returns:
samples – Dictionary of expectands and HMC diagnostics. Each item is a 2D Numpy array. The first dimension indexes the Markov chains and the second indexes the sequential states within each chain.
- Return type:
dict
Notes
We only pass in a Stan file and not a cmdstanpy.CmdStanModel instance because cmdstanpy will check for a compiled executable by default and will not recompile. So, when doing multiprocessing, we can pass strings denoting Stan files, which are far easier to pickle than cmdstanpy.CmdStanModel instances.