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.
-
Provides complete control - all sampler arguments have corresponding named argument for CmdStanPy sampler function.
-
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 sample from the posterior, downstream modules do the analysis.
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 CmdStanModel, cmdstan_path
# specify Stan file, create, compile CmdStanModel object
bernoulli_path = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_model = CmdStanModel(stan_file=bernoulli_path)
# specify data, fit the model
bernoulli_data = { "N" : 10, "y" : [0,1,0,0,0,0,0,0,0,1] }
bernoulli_fit = bernoulli_model.sample(chains=5, cores=3, 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.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ed0fdcbe0c8dade59078bae0ec149844f6ba37644fe58194fc9071fb9442ada |
|
MD5 | c7c420d77736ebb85050bd0286b64d15 |
|
BLAKE2b-256 | 24e74932951239f629844f4b658185f49a15b0a6a813430c95efaa2a0a0e936e |