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

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.12.0.0.zip (31.4 MB view details)

Uploaded Source

pystan-2.12.0.0.tar.gz (16.8 MB view details)

Uploaded Source

Built Distributions

pystan-2.12.0.0-cp35-cp35m-win_amd64.whl (39.2 MB view details)

Uploaded CPython 3.5m Windows x86-64

pystan-2.12.0.0-cp35-cp35m-win32.whl (39.1 MB view details)

Uploaded CPython 3.5m Windows x86

pystan-2.12.0.0-cp35-cp35m-manylinux1_x86_64.whl (58.6 MB view details)

Uploaded CPython 3.5m

pystan-2.12.0.0-cp35-cp35m-manylinux1_i686.whl (58.1 MB view details)

Uploaded CPython 3.5m

pystan-2.12.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 (41.3 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.12.0.0-cp34-cp34m-manylinux1_x86_64.whl (58.6 MB view details)

Uploaded CPython 3.4m

pystan-2.12.0.0-cp34-cp34m-manylinux1_i686.whl (58.1 MB view details)

Uploaded CPython 3.4m

pystan-2.12.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 (41.3 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.12.0.0-cp27-cp27mu-manylinux1_x86_64.whl (58.7 MB view details)

Uploaded CPython 2.7mu

pystan-2.12.0.0-cp27-cp27mu-manylinux1_i686.whl (58.1 MB view details)

Uploaded CPython 2.7mu

pystan-2.12.0.0-cp27-cp27m-manylinux1_x86_64.whl (58.7 MB view details)

Uploaded CPython 2.7m

pystan-2.12.0.0-cp27-cp27m-manylinux1_i686.whl (58.1 MB view details)

Uploaded CPython 2.7m

pystan-2.12.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 (41.3 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.12.0.0.zip.

File metadata

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

File hashes

Hashes for pystan-2.12.0.0.zip
Algorithm Hash digest
SHA256 8abe9e4fc24054a25eb636ce7c36222dd1b244f8b4482d96f1e4858106db0cd3
MD5 a9c3a2e315228e8d672da20a8b06da1e
BLAKE2b-256 321a16411ac9326daddde32e1ef1602561593e83709b6302e29ee6c3ff5a898b

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pystan-2.12.0.0.tar.gz
Algorithm Hash digest
SHA256 7cfeb8694f94e638eff1e625275479336a799610b0940e2eb1fa0ee97bcad0ef
MD5 eb096fc3224db24ffba7cad075116223
BLAKE2b-256 0f3a795bb3e8d94f646fb7740436da2b20848c9bc78d30072c2871ea028c0ee2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 193e0fe99ac4c2d5231328b63c045f19e6737b99fb3455e61b95aabed5820502
MD5 74bd34cba6155ce584dfd00a35d5587c
BLAKE2b-256 c069c125dc23721e7aa6246a8506e428824cea4370dfeee75cad1dacde649ccc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 36122b34e1a4b658d5d2bea546363ab09f698ef21a096f999e5decd8965bf148
MD5 cd606cefbdd4c1d81d294dd669632f62
BLAKE2b-256 53d306498c2ce5dc0e537842904a75ceb3fbc997114714012947efdcd6a2e49f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 96881c3a5f3986909724359f804ca3a2caccaadbae249aab8f19095c52556b53
MD5 f88f7f1b0cd20e5b4f98efc64b9d2540
BLAKE2b-256 d7451b334a2e0e20672c425504e57d7fcd02968dc1dbaa8ca6931c36dc6c1309

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 2344041dc2001c265323d2bda6b55a6d98abbed012f1488a369ab03b0d057a2e
MD5 ffca8e92904ab09022ddaa4d48362741
BLAKE2b-256 564c7f113efc82b47141a9d329b262cca8619cd9a6f35d78d977b5d051d43bcf

See more details on using hashes here.

File details

Details for the file pystan-2.12.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.12.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 770676f95d24a38c5421f0750800fd126c46b3a1adb76ef7b2adbadb4314fdee
MD5 8ec1d67197c31c1c7b14a399531ec1af
BLAKE2b-256 76d38408a8d458c6313ba7e89da8af9b8b6cf24ecbc1cb1d6ab95b9c7b0f3f3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 f28027021ff7483e6b8c8150434c042ef91f8670ce4bdbdeaba17e777d374292
MD5 4f7196621309b04757a50ef7c1a8ca0b
BLAKE2b-256 61f85c77c715972ce8dc814e683ec22099b85be7c3f455f7f9a94d9181a909e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 5ba2b1e8348aa58b706b2f83138e9ca5e9ecada507bab9c6ae202ab03992ab7c
MD5 a00ae980a9c07f3ee0e30b7e7a5930be
BLAKE2b-256 8ff89af2bc335af05a1a2f33bab584302fcd0265f0ded94e08f253eb7b9ed758

See more details on using hashes here.

File details

Details for the file pystan-2.12.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.12.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 615932179ad0427bebaed545dd62021e22ce22fab2defaeeaefa4dbf72fd46bd
MD5 bf6538d772e010a3fbc2725c36f47e95
BLAKE2b-256 4ba1402063de54cb357ccfa7571bfae5b236c7607b036e9e7889b41f80dbb0ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 fd12c6daf11d9290c33655db5f9e9d94fefc5f4862b70ddcbeb484185bebbdea
MD5 9569922d35ab9fde53e7f0838e3bd7c6
BLAKE2b-256 e3bc2c352cbf0e094fe6ff99cebec92fb6506ff9b58f795a36992c3038b68d5c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d72b57639fe784a528cc5a910d3c069169c997b1d82c5f66c7a72855c8cc8f61
MD5 176b124f56dd484172543a06006448a8
BLAKE2b-256 16ab1fe2ef87c875df151e700f934c23435563bdd499847aa272e5140b204159

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e20037d962a8e8dc7ec706057e8d8e8ca6251fdac3a4cd387252f115fd5ff7e3
MD5 3268163ecaaed84d1817aab722d28d9b
BLAKE2b-256 093c91bfcc44ae0a10cf8592250754f2630fbcc1a2345beb845b5ae9f5dea2d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.12.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 c5137eaa1ca6b47ecd13402bf4fbb571d545615f02b203a01ed9f57c053d27c1
MD5 1ad6b946da709454ff470519b24aba86
BLAKE2b-256 9b40df8a8620b93d24de7b196ab96a361b40a734540dfa6395c32f9ae9728364

See more details on using hashes here.

File details

Details for the file pystan-2.12.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.12.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 9b673c7f0c48213b38ce7215a532fa859b6272de992afa9f8013233cae9f89ed
MD5 5cdd2471f12cec906a670ef28bb5f532
BLAKE2b-256 c4d7ff719365fdb2f64314b22ed4d5e030ae1c5083377ba327137acf0ee455db

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