Skip to main content

Python interface to Stan, a package for Bayesian inference

Project description

Stan logo

pypi version travis-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

Installation

NumPy and Cython (version 0.19 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.19 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

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()

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.5.0.2.tar.gz (11.4 MB view details)

Uploaded Source

Built Distributions

pystan-2.5.0.2-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 (46.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.5.0.2-cp33-cp33m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (46.4 MB view details)

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

pystan-2.5.0.2-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (46.4 MB view details)

Uploaded CPython 2.7 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.5.0.2.tar.gz.

File metadata

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

File hashes

Hashes for pystan-2.5.0.2.tar.gz
Algorithm Hash digest
SHA256 8bbd5b4edd14143bde5fc3f2298e77a5ddd41de69e5825532fb9925895f0f356
MD5 1693683f29886fee37c71881abaf15ca
BLAKE2b-256 c8d5187763e9b1ebd4bb931059b735bbd3fbbe1567e1f727ff667a90656efc1c

See more details on using hashes here.

File details

Details for the file pystan-2.5.0.2-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.5.0.2-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 35a8fa1dc0ac260fd089613dc02fbeef8f1efe79bebe946dccda0101c5f55e7b
MD5 b9e027c6f95c6f047db2c7a28ccf4cd7
BLAKE2b-256 0939da2aacd876f04a70e76d4162f839c91aa9890f521ceaf7654ce947000df8

See more details on using hashes here.

File details

Details for the file pystan-2.5.0.2-cp33-cp33m-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.5.0.2-cp33-cp33m-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 7444dbc1ad03aa309879b54d7bda33b8e1312e2bc0e9ca195c2fa1f2822daa2c
MD5 9518304d74387d72d7239422be81a009
BLAKE2b-256 a2a2a6e5f57f17dcb6a6bd5daa0f361651bc92975b0093c3f92802ecd8e3df7e

See more details on using hashes here.

File details

Details for the file pystan-2.5.0.2-cp27-none-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.5.0.2-cp27-none-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 f9962baa083172a9f6b757c4944d74ed742c6e75b759da544fcc24c5e222f5bd
MD5 e74758665537b3931bb76606a3dce179
BLAKE2b-256 c3d9dc32c56ca8e984f623d28ba3c98eb5bf151788d6aa32162c55866c16c659

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