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 Distribution

pystan-2.10.0.0.tar.gz (16.7 MB view details)

Uploaded Source

Built Distributions

pystan-2.10.0.0-cp35-cp35m-win_amd64.whl (38.6 MB view details)

Uploaded CPython 3.5m Windows x86-64

pystan-2.10.0.0-cp35-cp35m-win32.whl (38.5 MB view details)

Uploaded CPython 3.5m Windows x86

pystan-2.10.0.0-cp35-cp35m-manylinux1_x86_64.whl (69.9 MB view details)

Uploaded CPython 3.5m

pystan-2.10.0.0-cp35-cp35m-manylinux1_i686.whl (69.7 MB view details)

Uploaded CPython 3.5m

pystan-2.10.0.0-cp34-cp34m-manylinux1_x86_64.whl (69.9 MB view details)

Uploaded CPython 3.4m

pystan-2.10.0.0-cp34-cp34m-manylinux1_i686.whl (69.7 MB view details)

Uploaded CPython 3.4m

pystan-2.10.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 (60.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.10.0.0-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 (60.3 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.10.0.0-cp27-cp27mu-manylinux1_x86_64.whl (69.9 MB view details)

Uploaded CPython 2.7mu

pystan-2.10.0.0-cp27-cp27mu-manylinux1_i686.whl (69.6 MB view details)

Uploaded CPython 2.7mu

pystan-2.10.0.0-cp27-cp27m-manylinux1_x86_64.whl (69.9 MB view details)

Uploaded CPython 2.7m

pystan-2.10.0.0-cp27-cp27m-manylinux1_i686.whl (69.6 MB view details)

Uploaded CPython 2.7m

pystan-2.10.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 (60.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.10.0.0.tar.gz.

File metadata

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

File hashes

Hashes for pystan-2.10.0.0.tar.gz
Algorithm Hash digest
SHA256 8156cb0e3d9a74c489eabb2915b32f3f219e450c31ee0c5d6dc8e3e8ce59de77
MD5 e71054e703f2e1ca0c7be347ebd8c05c
BLAKE2b-256 3edf015807edf4a0501aadebce7891eeaa08f2fdfa16ac5e382e07778cc59d42

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp35-cp35m-win_amd64.whl
Algorithm Hash digest
SHA256 6cf8d2839290d9a0c89a5dd2be24bef67d73b87ed425173b042c54edeb3f0186
MD5 5ccf4d58c3eae48f90410910c018f072
BLAKE2b-256 d676202177a2eb3a1fc178e15e6971a576dfa81565304cd867054da6f4dd3e55

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp35-cp35m-win32.whl
Algorithm Hash digest
SHA256 90126d5468155f55a6cfcdb52b8c683729d61f9270207466fc57511c1d579902
MD5 3b5c484ad00bb0b527d5fbc309749eea
BLAKE2b-256 1ec10aa23a4e19088794110905938e08e113cb81d6c9bb0ccdd9b18550d19892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 ed71bc441f3d344ee9894a3ecfa041008d08cda16a684d682c4403f0df53b470
MD5 762fca085b5f642d7786152680f41f3e
BLAKE2b-256 cdbf57022acec73ad3e2855c83185e6918b66f322bd4c86beded20ee6336f382

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 6163fed1b8fdd88b12c214d6578f522ae03a330a6e622a61060f1c0677ce4658
MD5 658bb15e28c65be83d41d25a6c37ae3a
BLAKE2b-256 e76b8ec40ad5fccf9feeb76825278b707cfea17790f07d424bc479457f35eb2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp34-cp34m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 e6535cefa1a6698408a20b6308431d598d6ad3d129497191da641e15f70c96ea
MD5 0d9714a1f4500e36e68fa7696727460a
BLAKE2b-256 e0891ffd526c707d7c9a1192e94b7d5b1c72b54a4e3948d1a23c417da6c631c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp34-cp34m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 7a863b589faa26d5b91cfa15f6d99d9ed0288529992389ab5f24359dfb108507
MD5 5bcc4a10e583922864f3d5c56aa88e9b
BLAKE2b-256 9d04abca713e0ef159dfda07cce36dc5317598c614270fcf89e865cc72a0bea0

See more details on using hashes here.

File details

Details for the file pystan-2.10.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.10.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 35778405a49b6636c23ecd01bc37e8f0833de83aa272fc6c1517cbde099a8ddf
MD5 3a91417987b4dd20a9c1a6f1d7491ed2
BLAKE2b-256 dee62b41725128562d03a67d100a4bbe7af0dac3cc9463a444f45bb2f8a5c977

See more details on using hashes here.

File details

Details for the file pystan-2.10.0.0-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.10.0.0-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 e589b2041f99b67dffc3aace8c3dd1316d9f65097910f709c86443393aeb5c0c
MD5 92efeab84b291a0cb1d5fceab5d186cd
BLAKE2b-256 d8ea66d05db606e49fcd5938f68e59b1c91928b3047c1f90ef11490e20392962

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 5753263050b3221df39a0b099b0e03a275e86a93123bceeb843b1a76298ad6fb
MD5 e8021dd550758ed74d082af7a4cf3842
BLAKE2b-256 039e40394a6625ffca6def383a22eb951b844d5176085c838138076aec33ef7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm Hash digest
SHA256 0fb888f8ab1b1a03820f8dcd4aa9fb3e641be8a593ad61385f670a01bcbe0f03
MD5 8dfcd2802e31f92877df69b0feea5e6e
BLAKE2b-256 1e6ad42098de648fc82f1d39a8582d384f510628b23db1b13e6d71d45557f4ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0270c2a732de6f78c67fbba0cba07a3f4cc38f20a3bc70d551b1d2237477298a
MD5 377cc5b85f57fc238954c7e31e78ab7d
BLAKE2b-256 9b9157b7ba7c2f4c4561962e8c9236526e02f22f8575a91db03698dc511b5f3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pystan-2.10.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 31ea5dd793a96b2b275e32f17798ae7509bc8624979646a63fe3c4cfd4b35f95
MD5 6190af4c70c9724dff174537145d6431
BLAKE2b-256 86608bf6cc949dad28a12601cf5c460f9ff1e22b77378340f5d1f993f391c62f

See more details on using hashes here.

File details

Details for the file pystan-2.10.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.10.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 50a0ba88c05755a27992fcc7acae8cfec3ccc1b87cd178103579a1161f13d2cf
MD5 091e9dd031e838216529bc4fd758722e
BLAKE2b-256 71ff6c68e289aab44a6354e2d4152efd592360abd7dc7a6b24193b9eda67c51f

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