Python interface to Stan, a package for Bayesian inference
Project description
====================================
.. image:: https://raw.githubusercontent.com/stan-dev/logos/master/logo.png
:alt: Stan logo
:scale: 50 %
|pypi| |travis| |appveyor| |zenodo|
**PyStan** provides a Python interface to Stan, a package for Bayesian inference
using the No-U-Turn sampler, a variant of Hamiltonian Monte Carlo.
For more information on `Stan <http://mc-stan.org>`_ and its modeling language,
see the Stan User's Guide and Reference Manual at `http://mc-stan.org/
<http://mc-stan.org/>`_.
Important links
---------------
- HTML documentation: https://pystan.readthedocs.org
- Issue tracker: https://github.com/stan-dev/pystan/issues
- Source code repository: https://github.com/stan-dev/pystan
- Stan: http://mc-stan.org/
- Stan User's Guide and Reference Manual (pdf) available at http://mc-stan.org
Related projects
----------------
- ArviZ: `Exploratory analysis of Bayesian models with Python <https://github.com/arviz-devs/arviz>`_ by @arviz-devs
- Prophet: `Timeseries forecasting <https://facebook.github.io/prophet/>`_ by @facebook
- Scikit-learn integration: `pystan-sklearn <https://github.com/rgerkin/pystan-sklearn>`_ by @rgerkin.
- BAMBI: `BAyesian Model-Building Interface <https://github.com/bambinos/bambi>`_ by @bambinos
- Jupyter tool: `StanMagic <https://github.com/Arvinds-ds/stanmagic>`_ by @Arvinds-ds
- Jupyter tool: `JupyterStan <https://github.com/janfreyberg/jupyterstan>`_ by @janfreyberg
Similar projects
----------------
- PyMC: http://pymc-devs.github.io/pymc/
PyStan3 / Stan3
---------------
The development of PyStan3 with updated API can be found under `stan-dev/pystan-next <https://github.com/stan-dev/pystan-next>`_
Detailed Installation Instructions
----------------------------------
Detailed installation instructions can be found in the
`doc/installation_beginner.md <doc/installation_beginner.rst/>`_ file.
Windows Installation Instructions
---------------------------------
Detailed installation instructions for Windows can be found in docs under `PyStan on Windows <https://pystan.readthedocs.io/en/latest/windows.html>`_
Quick Installation (Linux and macOS)
------------------------------------
`NumPy <http://www.numpy.org/>`_ and `Cython <http://www.cython.org/>`_
(version 0.22 or greater) are required. `matplotlib <http://matplotlib.org/>`_
is optional. ArviZ is recommended for visualization and analysis.
PyStan and the required packages may be installed from the `Python Package Index
<https://pypi.python.org/pypi>`_ using ``pip``.
::
pip install pystan
Alternatively, if Cython (version 0.22 or greater) and NumPy are already
available, PyStan may be installed from source with the following commands
::
git clone --recursive https://github.com/stan-dev/pystan.git
cd pystan
python setup.py install
To install latest development version user can also use ``pip``
::
pip install git+https://github.com/stan-dev/pystan
If you encounter an ``ImportError`` after compiling from source, try changing
out of the source directory before attempting ``import pystan``. On Linux and
OS X ``cd /tmp`` will work.
Example
-------
.. code-block:: python
import pystan
import numpy as np
import matplotlib.pyplot as plt
schools_code = """
data {
int<lower=0> J; // number of schools
real y[J]; // estimated treatment effects
real<lower=0> sigma[J]; // s.e. of effect estimates
}
parameters {
real mu;
real<lower=0> tau;
real eta[J];
}
transformed parameters {
real theta[J];
for (j in 1:J)
theta[j] = mu + tau * eta[j];
}
model {
eta ~ normal(0, 1);
y ~ normal(theta, sigma);
}
"""
schools_dat = {'J': 8,
'y': [28, 8, -3, 7, -1, 1, 18, 12],
'sigma': [15, 10, 16, 11, 9, 11, 10, 18]}
sm = pystan.StanModel(model_code=schools_code)
fit = sm.sampling(data=schools_dat, iter=1000, chains=4)
print(fit)
eta = fit.extract(permuted=True)['eta']
np.mean(eta, axis=0)
# if matplotlib is installed (optional, not required), a visual summary and
# traceplot are available
fit.plot()
plt.show()
# updated traceplot can be plotted with
import arviz as az
az.plot_trace(fit)
.. |pypi| image:: https://badge.fury.io/py/pystan.png
:target: https://badge.fury.io/py/pystan
:alt: pypi version
.. |travis| image:: https://travis-ci.org/stan-dev/pystan.png?branch=master
:target: https://travis-ci.org/stan-dev/pystan
:alt: travis-ci build status
.. |appveyor| image:: https://ci.appveyor.com/api/projects/status/49e69yl5ngxkpmab?svg=true
:target: https://ci.appveyor.com/project/pystan/pystan
:alt: appveyor-ci build status
.. |zenodo| image:: https://zenodo.org/badge/10256919.svg
:target: https://zenodo.org/badge/latestdoi/10256919
:alt: zenodo citation DOI
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 Distributions
File details
Details for the file pystan-2.19.1.1.tar.gz
.
File metadata
- Download URL: pystan-2.19.1.1.tar.gz
- Upload date:
- Size: 16.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa8bad8dbc0da22bbe6f36af56c9abbfcf10f92df8ce627d59a36bd8d25eb038 |
|
MD5 | c5fb08d162381073b6bebe2ffb17e5f2 |
|
BLAKE2b-256 | 109fdcecf31ac08842a675ec337a14439b37d75f6da42f034b1fd5eb90b10b84 |
File details
Details for the file pystan-2.19.1.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 79.8 MB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d8c2ae05d1dca854a55b2ae9276af5866e473fb8264d03d5267abadb3c602da |
|
MD5 | 1fbad4855f9b1bc7a82f4664d4d17ca2 |
|
BLAKE2b-256 | e37bba001a1e29e297a033c6a110ab80914bc4a2ed0a1aaec4c0224d56dfbbfe |
File details
Details for the file pystan-2.19.1.1-cp38-cp38-win32.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp38-cp38-win32.whl
- Upload date:
- Size: 55.7 MB
- Tags: CPython 3.8, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0.post20191030 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f16c399da3d9d72e9661b131c23d51a59c789416598885714813fcb552234c83 |
|
MD5 | 6b49974c1b092933e80364b7949e86c6 |
|
BLAKE2b-256 | 50083e7a39ac73b7e0b43941e09c09e78dd256254df44e026beb207e7836d785 |
File details
Details for the file pystan-2.19.1.1-cp38-cp38-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp38-cp38-manylinux1_x86_64.whl
- Upload date:
- Size: 62.6 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8e0924c318a0ea67260167a74f040078a4ce0d3fd4a7d566aa76f7752a85fab |
|
MD5 | 268d4280cffce8b681099b9e6be76dac |
|
BLAKE2b-256 | 0502cab8f6c9c171eae62b74049fce07d431c2033e9d6d7b068695d2ca7d7f3d |
File details
Details for the file pystan-2.19.1.1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 37.4 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 837a62976b32e4fd2bd48fee3b419c651e19747280e440d5934bea3822b22115 |
|
MD5 | b5856f9b723a001f696758178fa29974 |
|
BLAKE2b-256 | 58668b4f649d61871f9e7c8ea0e2bf1851c5c3fe5135dabbbf401607bdd66e96 |
File details
Details for the file pystan-2.19.1.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 79.8 MB
- Tags: CPython 3.7m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3622520b2e55d2ce70a3027d9910b6197a8bc2ef59e01967be9c4e607a48a9c1 |
|
MD5 | 2e67c76a66483fe2c002d9fc3f671eff |
|
BLAKE2b-256 | 16f9fd70954890d5110a663139d8cb015a9ead713798db06cc2dc784635bb9f0 |
File details
Details for the file pystan-2.19.1.1-cp37-cp37m-win32.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp37-cp37m-win32.whl
- Upload date:
- Size: 55.7 MB
- Tags: CPython 3.7m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ef9031dfbd65757828e2441cb9a76c9217fb5bb93817fee2550722e7a785b3 |
|
MD5 | 4c6cbbd844a3fa671e42a249b438e56c |
|
BLAKE2b-256 | d655dcbe7b3a3c67e5de5577d3bcc5eda3545b33c01b4553180a18a1d956ffb6 |
File details
Details for the file pystan-2.19.1.1-cp37-cp37m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp37-cp37m-manylinux1_x86_64.whl
- Upload date:
- Size: 67.3 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b44502aaa8866e0bcc81df1537e7e08b74aaf4cc9d4bf43e7c8b168f3568ca6 |
|
MD5 | 00b4ef621089a485aed9b23eb78ad9b6 |
|
BLAKE2b-256 | 9fcc4e88a34a015aa7aa459220bd18429f3ac6b15c703465fc7c411989f04ccc |
File details
Details for the file pystan-2.19.1.1-cp37-cp37m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp37-cp37m-macosx_10_6_intel.whl
- Upload date:
- Size: 39.1 MB
- Tags: CPython 3.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b67008f5780c7cf0f3fbad5bc54bc9919efc9655d63e0314dc013e85c7a0f14 |
|
MD5 | 5f88649098ee7118af743dd6fb436a18 |
|
BLAKE2b-256 | 66cecacc6174b65d9e059725ccf8bb6b9653fb7174048a759de7fe639d9a7171 |
File details
Details for the file pystan-2.19.1.1-cp36-cp36m-win_amd64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp36-cp36m-win_amd64.whl
- Upload date:
- Size: 79.8 MB
- Tags: CPython 3.6m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc1193f52bc6c6419dd753bcb0b6958b24fe588dc3da3c7f70bd23dcbda6ec2a |
|
MD5 | c8c2d39c1611061c23eea1d5430c4c1a |
|
BLAKE2b-256 | 7c8bb008aed4988f8eefbf1f5bbbdabcf4cd8ca4e9965d55121e755303ed5d82 |
File details
Details for the file pystan-2.19.1.1-cp36-cp36m-win32.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp36-cp36m-win32.whl
- Upload date:
- Size: 55.7 MB
- Tags: CPython 3.6m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61340356889547e29e2e6db7ef28f821b91e73fee80a888e81a794a24a249987 |
|
MD5 | 30f7bfda49e11cdd4d57849481fc79c6 |
|
BLAKE2b-256 | 2b8d11454c8251f950e8e354c91a5aff93183e0d19ff4aa2b52a7c78958967fa |
File details
Details for the file pystan-2.19.1.1-cp36-cp36m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp36-cp36m-manylinux1_x86_64.whl
- Upload date:
- Size: 67.3 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5020ac3ca3a840f428f090fc5fe75412e2a7948ac7e3de59f4bbfd7a4539c0ef |
|
MD5 | 5c961b6b020947a0bc0300ea2ac2be3e |
|
BLAKE2b-256 | b997a613a98b72090e36b3bc5edc56977596038986cd224a2ae651c4c6a688b3 |
File details
Details for the file pystan-2.19.1.1-cp36-cp36m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp36-cp36m-macosx_10_6_intel.whl
- Upload date:
- Size: 37.4 MB
- Tags: CPython 3.6m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9fbbf10dfc0ef8e7343ee4a3e17fd5c214fb12fc42615673e14908949b410e4 |
|
MD5 | 9b54139ddec0edcf3223d0a18fa25955 |
|
BLAKE2b-256 | 6bed54937aeb274a73807588100127609fbc3e6f7cc2453ae5e4704b2858181a |
File details
Details for the file pystan-2.19.1.1-cp35-cp35m-win_amd64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp35-cp35m-win_amd64.whl
- Upload date:
- Size: 79.8 MB
- Tags: CPython 3.5m, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c87bd98db2b5c67fa08177de04c98b46d1fcd68ae53dbe55ffc5187868068002 |
|
MD5 | 9574a1b4ec2a6db2906863022d8e9c2a |
|
BLAKE2b-256 | 8a59551cddce4f4b9014f150c443a14843f6e76e3d0f131086339d88a463da12 |
File details
Details for the file pystan-2.19.1.1-cp35-cp35m-win32.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp35-cp35m-win32.whl
- Upload date:
- Size: 55.7 MB
- Tags: CPython 3.5m, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6580cec2f5ed1bdb44eab83d54fe87b11e673ed65d6c2064d8d9f76265ce049 |
|
MD5 | 02c1c8464cdbeed4af9f69a5b6e1e7fa |
|
BLAKE2b-256 | 98a35a81eb82c002105ff5268f6fe4719c46f45c8c49cd862f8d8ddabf08d429 |
File details
Details for the file pystan-2.19.1.1-cp35-cp35m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp35-cp35m-manylinux1_x86_64.whl
- Upload date:
- Size: 67.2 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43fdd98561f0cba0637f1fa343ed7d5adc885d04a655ab6302dbfd08f016105d |
|
MD5 | 23be1b1e5bed2d5bae9bfad1ab3d2c27 |
|
BLAKE2b-256 | 54a67b76455318c958b30c31fd5dc16fb29ab148d80884418283a942f65eb217 |
File details
Details for the file pystan-2.19.1.1-cp35-cp35m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp35-cp35m-macosx_10_6_intel.whl
- Upload date:
- Size: 37.4 MB
- Tags: CPython 3.5m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1127522641533a6ccb7684d4008d06c092cbe6f3ee7d44679a87937ee39093ab |
|
MD5 | 4cbb46f6200cdd9dc1c87b8ad8d514ff |
|
BLAKE2b-256 | d074c6e6d5f46dc8f51f10f848785ddc72e0c2e233f094d0787abba42c8c6b93 |
File details
Details for the file pystan-2.19.1.1-cp27-cp27mu-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp27-cp27mu-manylinux1_x86_64.whl
- Upload date:
- Size: 67.2 MB
- Tags: CPython 2.7mu
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c4bbbb0a59144135d9821f2b9c308bfdf70aa61befdc7dc435f4c86bfb4457e |
|
MD5 | 60e343593f1cb8ef9ed1a62795600a14 |
|
BLAKE2b-256 | f367983a2de85fe82b7c2813fe01801edca19c6f193db8cc5903e684f77ce870 |
File details
Details for the file pystan-2.19.1.1-cp27-cp27m-manylinux1_x86_64.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp27-cp27m-manylinux1_x86_64.whl
- Upload date:
- Size: 67.2 MB
- Tags: CPython 2.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2baa4106ddc7fb90712bd0e5ab8693ce130b001c6166839247511326edc6d0ba |
|
MD5 | beeb445ef9854f31fdd6bd401332e681 |
|
BLAKE2b-256 | cebd449fb3b6d5a04cc908c343d3546e425e00a829a13c185c9a627a9f0e8bd3 |
File details
Details for the file pystan-2.19.1.1-cp27-cp27m-macosx_10_6_intel.whl
.
File metadata
- Download URL: pystan-2.19.1.1-cp27-cp27m-macosx_10_6_intel.whl
- Upload date:
- Size: 37.4 MB
- Tags: CPython 2.7m, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.1.0 requests-toolbelt/0.8.0 tqdm/4.19.5 CPython/3.6.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a0820df5fcd13c7a4cae75d59809adee72d1135a604dc2b5f068d4ac8ca349e |
|
MD5 | e041810130f3bee313a133bcb6352cb2 |
|
BLAKE2b-256 | 58ef51902e2bbdb8ea2aa7f1d97c78bc08348b5e4b70dd9659ec8231c0500b6a |