/cmd_stan_utility

A combination of utilities for PyStan both from Michael Betancourt's and Sean Talts Stan_utility as well as a few of my own

Primary LanguagePythonGNU General Public License v3.0GPL-3.0

stan_utility

Utilities for PyStan for

  • caching model compilation in a smart way
  • caching sampling results in a smart way
  • checking Stan warnings
  • making corner plots of scalar parameters

Build Status PyPI version fury.io PyPI license

Install

$ pip install stan-utility

Usage

import stan_utility

model = stan_utility.compile_model('myscript.stan')
data = dict(mean=1)

results = stan_utility.sample_model(model, data, chains=2, iter=1000)
print(results.posterior)  ## a arviz.InferenceData object

# create mytest_fit_corner.pdf:
stan_utility.plot_corner(samples, outprefix="mytest_fit")

On the second run of this code,

  • compile_model will retrieve the compiled model from cache
  • sample_model will retrieve the results from cache. (change the seed or parameters if you want a fresh run).

Jupyter notebook features

See demos:

Editing the comments, adding and removing lines will not require recompilation of the model, because empty lines and comments are stripped out.

Contributors

Derived originally from Stan_utility by Michael Betancourt and Sean Talts.

  • @grburgess
  • @cescalara
  • @JohannesBuchner

Contributions are welcome.