Skip to main content

Python interface to Stan, a package for Bayesian inference

Project description

Stan logo

pypi version travis-ci build status appveyor-ci build status pypi download statistics

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 and its modeling language, see the Stan User’s Guide and Reference Manual at http://mc-stan.org/.

Similar projects

Detailed Installation Instructions

Detailed installation instructions can be found in the installation_beginner.md file

Quick Installation

NumPy and Cython (version 0.22 or greater) are required. matplotlib is optional.

PyStan and the required packages may be installed from the Python Package Index 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

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

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]}

fit = pystan.stan(model_code=schools_code, 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()

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 Distributions

pystan-2.11.0.0.zip (31.3 MB view details)

Uploaded Source

pystan-2.11.0.0.tar.gz (16.9 MB view details)

Uploaded Source

Built Distributions

pystan-2.11.0.0-cp35-cp35m-win_amd64.whl (39.1 MB view details)

Uploaded CPython 3.5m Windows x86-64

pystan-2.11.0.0-cp35-cp35m-win32.whl (39.0 MB view details)

Uploaded CPython 3.5m Windows x86

pystan-2.11.0.0-cp35-cp35m-manylinux1_x86_64.whl (71.0 MB view details)

Uploaded CPython 3.5m

pystan-2.11.0.0-cp35-cp35m-manylinux1_i686.whl (70.7 MB view details)

Uploaded CPython 3.5m

pystan-2.11.0.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (51.7 MB view details)

Uploaded CPython 3.5m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

pystan-2.11.0.0-cp34-cp34m-manylinux1_x86_64.whl (71.0 MB view details)

Uploaded CPython 3.4m

pystan-2.11.0.0-cp34-cp34m-manylinux1_i686.whl (70.7 MB view details)

Uploaded CPython 3.4m

pystan-2.11.0.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (51.7 MB view details)

Uploaded CPython 3.4m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

pystan-2.11.0.0-cp27-cp27mu-manylinux1_x86_64.whl (71.0 MB view details)

Uploaded CPython 2.7mu

pystan-2.11.0.0-cp27-cp27mu-manylinux1_i686.whl (70.7 MB view details)

Uploaded CPython 2.7mu

pystan-2.11.0.0-cp27-cp27m-manylinux1_x86_64.whl (71.0 MB view details)

Uploaded CPython 2.7m

pystan-2.11.0.0-cp27-cp27m-manylinux1_i686.whl (70.7 MB view details)

Uploaded CPython 2.7m

pystan-2.11.0.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (51.7 MB view details)

Uploaded CPython 2.7m macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

File details

Details for the file pystan-2.11.0.0.zip.

File metadata

  • Download URL: pystan-2.11.0.0.zip
  • Upload date:
  • Size: 31.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pystan-2.11.0.0.zip
Algorithm Hash digest
SHA256 9ea7313c0bf51ea6c8a62979e62b20b2e1343363e1dac38e2a175dc7e8703a62
MD5 54927e973a83f4412223bc482de40d29
BLAKE2b-256 e619f4857fb7aa42bba9da1611fb367cd06880195627d74dbd672847161abb6e

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0.tar.gz.

File metadata

  • Download URL: pystan-2.11.0.0.tar.gz
  • Upload date:
  • Size: 16.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pystan-2.11.0.0.tar.gz
Algorithm Hash digest
SHA256 c4ffd1437d0341d8eb7d9d62e0b3dd80fc8a9386d105192f50a397221c0dbcdd
MD5 4c7e37bb0bca65467226959891d9ff7a
BLAKE2b-256 30300f513035224c05328a01354bf24438565df203b5e798e8fb8754264e9cf5

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp35-cp35m-win_amd64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 123b4e4fefb100402dc112b20a0a01994a8939de2023eb2d0d30a0c8a9483103
MD5 7ae9911feeb95fe35f2efcbd1d00dbc8
BLAKE2b-256 fd4bdb82851cc2c4126ed100d74c64d91f0d68e82f7910182ca37ed1db4abd7f

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp35-cp35m-win32.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 e38810c54215b500c069aff105cc185b631efd3780cb913ebb806815a0bc7f0b
MD5 bdf563d90dbf2fc26ca817d54baf4d4c
BLAKE2b-256 59aabacc9d0dbcb6a01ef4c104fc3723054a3cb57e34654cee303fd4933db8bd

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 4c8357754f0ce1d71f71f49db3a4a13871298aa5518174cdab01cebda90e17aa
MD5 a5cbf19a85f2485688be7ce8882358c2
BLAKE2b-256 911f6ed2ea63ed80d00ca6eadf613fa0a161c27d275ae7351d174e791443a6a5

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7a2c0f4a21a2e6f9190afbd1da99e413fae3aae935718978f19a59517dec19d5
MD5 e95236a6676773d94eacbfe9fea2a59d
BLAKE2b-256 3e2cba4daefa2388f6cef2460ac932647587d6fb1b8483d26051c954751fd0fa

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 6f95949e48f150b11382a3964a5605e0190a4409c9379bd062abf195b1ba5195
MD5 1892a24d2a2104e0ae6d2871e405863c
BLAKE2b-256 03eb879ea4c6fa9d8620adf99d6cd3ff4149aa195a0bf0bf317c477e529eaf1b

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp34-cp34m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0a14a2b367a09fb26f27c62f2eafaeea37077b678fc492fd42cb2c34403be67e
MD5 822028bc05138e77bdcafa4030bb873c
BLAKE2b-256 18c04b339b4eaa7aadef3119d6de3bc0eaafed01dd0dfbcec07a22f7285ea7bf

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp34-cp34m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 e7d86d7462bff837306c90d44d66cba448d363c23c46b54fb999562dc392c1ec
MD5 0051fa7c32409174fd5c0860f00de76f
BLAKE2b-256 b559a0cf0fb92aebbcfd89f44614ce3ea7317a4dc91074a5653b7d6ece70f3b1

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp34-cp34m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 8ef83c6102746405da5125368c4bf8d50a384251765ffa8ebf744a189941c849
MD5 cc05c352d79e2fc986127ef36bed7f2d
BLAKE2b-256 516a168803304283fddac03233bc0891f752332fbcbc7327aac13f85e20aa111

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp27-cp27mu-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ce61ec5c59af5ce0f373dc0eb633e42684a3c09dd9d6efa2e85c19a10c679e84
MD5 c1c174108c3c830cc75328ab75eda97c
BLAKE2b-256 98033e63433081823407fe523e210ece2b04f675f57fbea24671cb7c68d7e550

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp27-cp27mu-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0829661d609699989316eb638001dfaf279ecd725655dc8590f8cc4e1f4f39d1
MD5 85318486672e4a95d1caf70d7dff9c06
BLAKE2b-256 873fa9ee7563105dedef4ae5c8ab682903870e429e6750651a2b5066ff596e1a

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp27-cp27m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 d140f44f56a51547a3baa471258ce2f40a9de7741b962e72d25c9256f2b4694d
MD5 03efbec06c3cbbde1535ac5a2f3e3e2b
BLAKE2b-256 b71f9185f2c570fbea3a701dbba5d9b38ca3ed7dd3737ab32cc3f91e686debf2

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp27-cp27m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a42a44fed306b6eeb37da7c1609d6cc905eab8b65331f8ab5a80dc6552e9631a
MD5 f14207c6d6ccc75b0f543aca531efdac
BLAKE2b-256 15314e6e9daa5e06b0d1c2848e7f14c46703882d47343fc32aa952124fecd52c

See more details on using hashes here.

File details

Details for the file pystan-2.11.0.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.11.0.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 743694ea0269ecd6f96481085e38f6ec5a3a248ed2ec24221e093f79ae62de8d
MD5 8ece60f11f3c3b3325924d693bb99212
BLAKE2b-256 fa416b4580ef3acff471d2548fd0d03fc206f8c43d38b30e8236a852f0f2c691

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page