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.

  • Provide access to all CmdStan inference methods.

  • 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 MCMC sample (or point estimate) from the posterior; other packages do analysis and visualization.

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 cmdstan_path, CmdStanModel

# specify locations of Stan program file and data
bernoulli_stan = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_data = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.data.json')

# instantiate a model; compiles the Stan program by default
bernoulli_model = CmdStanModel(stan_file=bernoulli_stan)

# obtain a posterior sample from the model conditioned on the data
bernoulli_fit = bernoulli_model.sample(chains=4, 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.62.tar.gz (50.3 kB view details)

Uploaded Source

Built Distribution

cmdstanpy-0.9.62-py3-none-any.whl (40.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cmdstanpy-0.9.62.tar.gz
  • Upload date:
  • Size: 50.3 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.46.0 CPython/3.7.0

File hashes

Hashes for cmdstanpy-0.9.62.tar.gz
Algorithm Hash digest
SHA256 1599f5fe94af7a3763374bb81f79ad2dcac6bbbd763d6806342c5f2abecda969
MD5 0dfb191df924a97df3b5f5a78a531849
BLAKE2b-256 fc44e54de817f207bfb513a40573806feb97f10162fa47af209c25df79db7003

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cmdstanpy-0.9.62-py3-none-any.whl
  • Upload date:
  • Size: 40.4 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.46.0 CPython/3.7.0

File hashes

Hashes for cmdstanpy-0.9.62-py3-none-any.whl
Algorithm Hash digest
SHA256 98bbbe043b11727723ec11d94595cc17eed0f9954dd08d053d96fb1e76c2d106
MD5 2be17a63df79c67f1b1a7b56c0471a0d
BLAKE2b-256 7029c1b5a9696b40b5649af9b31e30091a205bc89d6ddbfb914b7e39d96bbfbf

See more details on using hashes here.

Supported by

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