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 doc/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 Distribution

pystan-2.14.0.0.tar.gz (18.4 MB view details)

Uploaded Source

Built Distributions

pystan-2.14.0.0-cp36-cp36m-manylinux1_x86_64.whl (62.2 MB view details)

Uploaded CPython 3.6m

pystan-2.14.0.0-cp36-cp36m-manylinux1_i686.whl (61.4 MB view details)

Uploaded CPython 3.6m

pystan-2.14.0.0-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (44.4 MB view details)

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

pystan-2.14.0.0-cp35-cp35m-win_amd64.whl (42.3 MB view details)

Uploaded CPython 3.5m Windows x86-64

pystan-2.14.0.0-cp35-cp35m-win32.whl (42.2 MB view details)

Uploaded CPython 3.5m Windows x86

pystan-2.14.0.0-cp35-cp35m-manylinux1_x86_64.whl (62.2 MB view details)

Uploaded CPython 3.5m

pystan-2.14.0.0-cp35-cp35m-manylinux1_i686.whl (61.4 MB view details)

Uploaded CPython 3.5m

pystan-2.14.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 (44.4 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.14.0.0-cp34-cp34m-manylinux1_x86_64.whl (62.2 MB view details)

Uploaded CPython 3.4m

pystan-2.14.0.0-cp34-cp34m-manylinux1_i686.whl (61.4 MB view details)

Uploaded CPython 3.4m

pystan-2.14.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 (44.4 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.14.0.0-cp27-cp27mu-manylinux1_x86_64.whl (62.2 MB view details)

Uploaded CPython 2.7mu

pystan-2.14.0.0-cp27-cp27mu-manylinux1_i686.whl (61.4 MB view details)

Uploaded CPython 2.7mu

pystan-2.14.0.0-cp27-cp27m-manylinux1_x86_64.whl (62.2 MB view details)

Uploaded CPython 2.7m

pystan-2.14.0.0-cp27-cp27m-manylinux1_i686.whl (61.4 MB view details)

Uploaded CPython 2.7m

pystan-2.14.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 (44.4 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.14.0.0.tar.gz.

File metadata

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

File hashes

Hashes for pystan-2.14.0.0.tar.gz
Algorithm Hash digest
SHA256 3bed255ca7d35bbd4ed0d5f30470744d9a71b06c1fa8b88281053dd430b0b1b2
MD5 ab3bc05a6f05411bc2a85e4d877351b3
BLAKE2b-256 799651a8857564e68f92ee33b2c53baee5435fcd5569dd9778f3e0efc67dae6e

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.0.0-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 17d819da2b3303ecc329ab81c18e0b3e4906a1d02009daaf2a34d3c4613f6c1a
MD5 7c39f93ad19dde45e3a20fe9b41baf4b
BLAKE2b-256 02bd8ec85d7c0bc6db429006ffaf92f5515c2cf7487c13d5178e4831bab0b447

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.0.0-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 b6a732264113ac1fe43b15a1549e81eda0ef135a1de27114048d23314b8c4ff2
MD5 f818e639678c2066404b9315c3dd74a1
BLAKE2b-256 2317f3ead8865dd18830ce060d36629684ee80e570d4fd124b56c398382db45b

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.0.0-cp36-cp36m-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.14.0.0-cp36-cp36m-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 734e6945a21d86c309e7ae06e57d980af6bd7d965c076ad162458d7b1a4c6f5e
MD5 1ca52a269a8dc6d64e8d13709828fb76
BLAKE2b-256 ea1338beec6f7a311725dcac2f8eb5ecca733312d43c67e4a2baecde03ba3c5b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 75799e3db4da90594e554040ef80059267eafda90b17dd08856f52e8acb0a57a
MD5 d6f3757357e13f2630949b84243e1a60
BLAKE2b-256 b141375fe0f09480e8308f97a138ca37ac7cbb0ce37595c38ab319c3e308b59b

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 a98661e9f8905740f72096d58d0dc157dc91e421c5eb2395dd63582c11129b1c
MD5 0c26e743b7004c884d4ee04d78f1fe61
BLAKE2b-256 584b0f3fb7f8cd9b5d571518629ac6e89accd802f740f22e8f2a63078020dfee

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 357fc266efd8135938830920a97a12113a20e28045c6a86d1908916d27b5fa0e
MD5 e181e96b52bf566c6c770aed8323f3dc
BLAKE2b-256 ec7cdce3326c4c47c7b25bd09f0e2d13938fe9be71932920e225978928e9dfd5

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 a83246a6552b9faee6de3b8596086a5c612d612584cc6b78029cc9c5b10689c6
MD5 033a5afd429c86e599b268d8f86a926d
BLAKE2b-256 5c3b17db4187a028187d4190a8671500124a45f1320f4ea4fb57469823fae4c6

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.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.14.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 c7b0cb1cdc1fdf76d44a7dfddc393afa5e51d3928f7a39103ede60e7bde39834
MD5 7b4e3a771659b5db866d252ec8825cc4
BLAKE2b-256 44927a48eb7a093bdcb1ecbda1703a344d54373a8e84fe57f9dc7c2ec14d202d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 c4ca0ef9ac5720d265abf48dd50d5b2ad6df14f2442ef1eb0db3215c8021ed3a
MD5 1fdcbed2047451868c93806d4af85ac7
BLAKE2b-256 3e3870c1a8f56c20992aba6fbb24911d316d47a3ed8f805df5bbf3ede3512d5d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 8f662640f413423b92c60d8a6d8f4efc42df94ecc2bd4e7ae9b7cb63027743bb
MD5 9379257c6f77527609092976d2f45a6d
BLAKE2b-256 9acba05a8b1b245ec91b8aab06b2a4ba5c4478f4b61bd2f46f3c2d6780b881bd

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.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.14.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 ace764b58cd4b64379be220b4371f0a271576c4f5789f9930af1e88fe9a820b1
MD5 1d23a5d0266ad832dae2c0c9ed7e87e1
BLAKE2b-256 d432eea8916c1407a348c1bdf835698ede947f5d5d1569949cba70300342b0ef

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 a713a42bc35036ffd0889e056fee2587b692fa500e89b7a1ae35cc74c2206506
MD5 a4abdecd4c5f6e2052172d79a41945ee
BLAKE2b-256 49f214971f6a7d1e512cf95fa94017e75a60a589c274dfe296a206e3ed80051e

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7cf81b6781c87fd3c20f27f3985a16a4912de899e384a7b582b47d978f2f5c31
MD5 75b6ddbd21e7c918124ea6f2d8f7cd9d
BLAKE2b-256 d95cd25cf71d5408276bddf96026bb4a22bbc93d374aec979a6a7400a0623e9d

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 eb6ca0a7c5cb6aff9bae6121cffdb5bcd8117560fd7a1c085789abe98341c22a
MD5 acea5b37e5f0b6f058246061373e7edf
BLAKE2b-256 72b6fca68856547276a2cb628c18689a0f86a215b889daab6879a70bf2ba735f

See more details on using hashes here.

Provenance

File details

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

File metadata

File hashes

Hashes for pystan-2.14.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 87ab9ba4530257fcaff05824cc36ec5bd2ae33be2fd3f2a8484c25e84db6e5c4
MD5 76f768d631b402b7d375e6b5b1419494
BLAKE2b-256 876876893f851461c61770aaeaf5d1f1f0d6483d8f9cd9be05b6198f8bd391d0

See more details on using hashes here.

Provenance

File details

Details for the file pystan-2.14.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.14.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 1b7d4dedc73acf278bf8c017c95ff7dd3b58d66252719e9b19fd62acb1ae849e
MD5 16ad05d61d929ab1dcb3ce9bc1aac42b
BLAKE2b-256 4986d3bb601ee10de16314f9566afc09d49bb8deffba16dea79b7d212114fe4a

See more details on using hashes here.

Provenance

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