Python interface to CmdStan
Project description
pycmdstan
Python interface to CmdStan.
Install
Pycmdstan is a pure-Python package which can be installed from PyPI
pip install --upgrade pycmdstan
or from sources
pip install -e git+https://gitlab.thevirtualbrain.org/tvb/pycmdstan
Usage
import os
os.environ['CMDSTAN'] = '~/src/cmdstan-2.17.1'
from pycmdstan import Model, Run
model = Model('''
data { vector[20] x; real mu; }
parameters { real sig; }
model { x ~ normal(mu, sig); }
generate quantities {
vector[20] log_lik;
for (i in 1:20) log_lik[i] = normal_lpdf(x[i] | mu, sig);
}
''')
runs = model.sample(
data=dict(mu, **data),
chains=4
)
assert (runs.N_eff / runs.niter) > 0.2
assert runs.R_hat.max() < 1.2
data = {'x': np.random.randn(20) + 5.0}
loo = []
mus = np.r_[1.0, 3.0, 5.0, 7.0, 9.0]
for mu in mus:
run = model.sample(
data=dict(mu=mu, **data), num_warmup=200, num_samples=200)
loo.append(run['loo'])
assert mus[np.argmin(loo)] == 5.0
Contributing
Contributions are welcome, please start in the issue tracker. Use YAPF to format the code. The Dockerfile can ease local development,
docker build -t pycmdstan .
docker run --rm -it pycmdstan pytest -n4 pycmdstan/tests.py
Acknowledgements
- PSIS code is by Aki Vehtari & Tuomas Sivula (BSD licensed, repo here)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pycmdstan-0.2.1.tar.gz
(13.0 kB
view details)
Built Distribution
pycmdstan-0.2.1-py3-none-any.whl
(13.5 kB
view details)
File details
Details for the file pycmdstan-0.2.1.tar.gz
.
File metadata
- Download URL: pycmdstan-0.2.1.tar.gz
- Upload date:
- Size: 13.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81df7cf624a24c66090833c8c0ff375e35642cb07c06d97c27d66ff8a4770e7f |
|
MD5 | 129e668256b011e4c0f4f2afaff6e09c |
|
BLAKE2b-256 | 2ae3da6510b21b0b5b0cb0f6142973556c8aa71d0e4d5b5bff2b6ad916f75f95 |
File details
Details for the file pycmdstan-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: pycmdstan-0.2.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a176f44f5fbaabb1003085e5309a48c96658ece5cfc66de5ee036f378112cc49 |
|
MD5 | e29165b2ed2798d917b2f93fb9c6cddf |
|
BLAKE2b-256 | a6279232c564fcb24e3f0c757e363725f3c1535a556f521181d78692037cb825 |