Python interface to CmdStan
Project description
pycmdstan
Python interface to CmdStan.
Install
Pycmdstan is a pure-Python package which can be installed from the Git repo
pip install -e git+https://gitlab.thevirtualbrain.org/tvb/pycmdstan
or (eventually) from PyPI
pip install 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);
}
''')
base_data = {'x': np.random.randn(20) + 5.0}
loo = []
for mu in np.r_[1.0, 3.0, 5.0, 7.0, 9.0]:
data = {'mu': mu}
data.update(base_data)
run = Run(
model,
'sample',
data,
method_args={
'num_warmup': 200,
'num_samples': 200
})
loo.append(run['loo'])
loo = np.array(loo)
a notable goal is to be able to inspect warmup while it's running.
Roadmap (wishlist)
- preprocess & compile Stan model with support for
#include
s - run model w/ multiple chains
- invoke summary or other executables
- read/write Rdump format (modulo a bug somewhere)
- read sample & summary CSV format
- model comparison, at least PSIS LOO
- common visualizations (trace, pairs, rhat hist)
- coordinators
opt_to_init
,sim_fit
which can sequence model invocations for common cases - typical makefile suspects
invoke_stanc
,compile_model
, etc - bind standalone funcs via ctypes
- bind density functions + jupyter widgets to tune dist params interactively
- auto get cmdstan sources & build
Dev
Use YAPF to format the code. The Dockerfile can ease local development,
docker build -t pycmdstan .
docker run --rm -it -v `pwd`:/opt/pycmdstan pycmdstan python -m unittest discover
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.1.tar.gz
(12.7 kB
view details)
Built Distribution
pycmdstan-0.1-py3-none-any.whl
(13.2 kB
view details)
File details
Details for the file pycmdstan-0.1.tar.gz
.
File metadata
- Download URL: pycmdstan-0.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ef05f15a8603e2556f1c72fe96bc7e08b06258a69e06a90b101dabd014636ce |
|
MD5 | d396a81c0a40f6cf4d29bef9d43bf5b5 |
|
BLAKE2b-256 | 92c07bbe418badb377b74777e48074901932c4f180239a62ba4cc960cb1db860 |
File details
Details for the file pycmdstan-0.1-py3-none-any.whl
.
File metadata
- Download URL: pycmdstan-0.1-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 222f8176c8335e0c41e2d7d2dd3167439af49f0342129c697e8b6123df34ca67 |
|
MD5 | 364f1af7d3cce7566595c90cf477f2ee |
|
BLAKE2b-256 | 720454861088f9b73cd84269cbca9b2e4194b4cf77e8dc10019e61f095745920 |