Python interface to CmdStan
Project description
CmdStanPy
CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to do Bayesian inference given a probability model written as a Stan program and data. Under the hood, CmdStanPy uses the CmdStan command line interface to compile and run a Stan program.
Goals
-
Clean interface to Stan services so that CmdStanPy can keep up with Stan releases.
-
Provide access to all CmdStan inference methods.
-
Easy to install,
- minimal Python library dependencies: numpy, pandas
- Python code doesn't interface directly with c++, only calls compiled executables
-
Modular - CmdStanPy produces a MCMC sample (or point estimate) from the posterior; other packages do analysis and visualization.
Docs
See https://cmdstanpy.readthedocs.io/en/latest/index.html
Source Repository
CmdStan's source-code repository is hosted here on GitHub.
Licensing
The CmdStanPy, CmdStan, and the core Stan C++ code are licensed under new BSD.
Example
::
import os
from cmdstanpy import cmdstan_path, CmdStanModel
# specify locations of Stan program file and data
bernoulli_stan = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_data = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.data.json')
# instantiate a model; compiles the Stan program by default
bernoulli_model = CmdStanModel(stan_file=bernoulli_stan)
# obtain a posterior sample from the model conditioned on the data
bernoulli_fit = bernoulli_model.sample(chains=4, data=bernoulli_data)
# summarize the results (wraps CmdStan `bin/stansummary`):
bernoulli_fit.summary()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for cmdstanpy-0.9.63-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 852a67d5937548efcff5dd57ae9de3647718b14924e03a6a7f20bf5cfc851360 |
|
MD5 | 1b651d524055bdb683fc130ce6cc2cf8 |
|
BLAKE2b-256 | 8e056e055c71d2ddcc48bc5496364e193dd023a75a4aebe6c373f28dd2add6d8 |