Skip to main content

Python interface to CmdStan

Project description

CmdStanPy

codecov

CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to do Bayesian inference given a probability model written as a Stan program and data. Under the hood, CmdStanPy uses the CmdStan command line interface to compile and run a Stan program.

Goals

  • Clean interface to Stan services so that CmdStanPy can keep up with Stan releases.

  • Provides complete control - all sampler arguments have corresponding named argument for CmdStanPy sampler function.

  • Easy to install,

    • minimal Python library dependencies: numpy, pandas
    • Python code doesn't interface directly with c++, only calls compiled executables
  • Modular - CmdStanPy produces a sample from the posterior, downstream modules do the analysis.

Docs

See https://cmdstanpy.readthedocs.io/en/latest/index.html

Source Repository

CmdStan's source-code repository is hosted here on GitHub.

Licensing

The CmdStanPy, CmdStan, and the core Stan C++ code are licensed under new BSD.

Example

::

import os
from cmdstanpy import CmdStanModel, cmdstan_path

# specify Stan file, create, compile CmdStanModel object
bernoulli_path = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_model = CmdStanModel(stan_file=bernoulli_path)


# specify data, fit the model
bernoulli_data = { "N" : 10, "y" : [0,1,0,0,0,0,0,0,0,1] }
bernoulli_fit = bernoulli_model.sample(chains=5, cores=3, data=bernoulli_data)

# summarize the results (wraps CmdStan `bin/stansummary`):
bernoulli_fit.summary()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cmdstanpy-0.9.1.tar.gz (45.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cmdstanpy-0.9.1-py3-none-any.whl (37.6 kB view details)

Uploaded Python 3

File details

Details for the file cmdstanpy-0.9.1.tar.gz.

File metadata

  • Download URL: cmdstanpy-0.9.1.tar.gz
  • Upload date:
  • Size: 45.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0

File hashes

Hashes for cmdstanpy-0.9.1.tar.gz
Algorithm Hash digest
SHA256 b188da9a2f75ea5d8238e16813630e4652950adf0a4d1b709045f08667e42e26
MD5 28988183e5e5746f4a07be460dc280c7
BLAKE2b-256 1f1d977be6b76af67c2bcf065e8c2f2d07c000ef4221817999c4d1d0dad8e456

See more details on using hashes here.

File details

Details for the file cmdstanpy-0.9.1-py3-none-any.whl.

File metadata

  • Download URL: cmdstanpy-0.9.1-py3-none-any.whl
  • Upload date:
  • Size: 37.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.0

File hashes

Hashes for cmdstanpy-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ce615e4c3a5b4928a11019fa90919766d8d3b711e775fbe5cdc9f4a52d14252e
MD5 46d3f962137acdbba2885ec7bfc4ee74
BLAKE2b-256 e7ea5e89bc03f02c492a51ab04cac1c505dda3f268433a09eae3ee95ddb22ca8

See more details on using hashes here.

Supported by

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