Skip to main content

HTTP-based interface to Stan, a package for Bayesian inference.

Project description

HTTP interface to Stan, a package for Bayesian inference.

An HTTP 1.1 interface to the Stan C++ package, httpstan is a shim that allows users to interact with the Stan C++ library using a Web API. The package is intended for use as a universal backend for frontends which know how to make HTTP requests. The primary audience for this package is developers.

In addition to providing all the functionality of the command-line interface to Stan (CmdStan) over HTTP 1.1, httpstan provides:

  • Automatic caching of compiled Stan Programs and samples from programs.
  • Parallel sampling.

Important Disclaimer

httpstan is experimental software. This software is not intended for general use.

httpstan currently requires Python 3.6 as it uses asynchronous generators (PEP525). Support for Python 3.5 may emerge at some point. No older versions of Python will be supported.

Background

httpstan is a shim allowing clients speaking HTTP to call functions in the Stan C++ package’s stan::services namespace. httpstan was originally developed as a “backend” for a Python interface to Stan, PyStan.

Install

python3 -m pip install httpstan

Usage

After installing httpstan, running the module will begin listening on localhost, port 8080:

python3 -m httpstan

In a different terminal, make a POST request to http://localhost:8080/v1/programs with a Stan Program to compile the program:

curl -X POST -H "Content-Type: application/json" \
    -d '{"program_code":"parameters {real y;} model {y ~ normal(0,1);}"}' \
    http://localhost:8080/v1/programs

This request will return a program id similar to the following:

{"program": {"id": "8137474d19926b0aa8efd4f1d3944131d59269d97a7bd8dab8e79d667eb314df"}}

(The program id will be different on different platforms and with different versions of Stan.)

To draw samples from this model using default settings, we make the following request:

curl -X POST -H "Content-Type: application/json" \
    -d '{"type":"hmc_nuts_diag_e_adapt"}' \
    http://localhost:8080/v1/programs/8137474d19926b0aa8efd4f1d3944131d59269d97a7bd8dab8e79d667eb314df/actions

This request will return samples from the normal distribution. The output is taken more or less directly from the output of the relevant function defined by the Stan C++ package (in the stan::services namespace). Consult the Stan C++ documentation for details.

Contribute

Contribution guidelines are described in CONTRIBUTE.rst.

License

ISC License.

Project details


Download files

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

Files for httpstan, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size httpstan-0.1.0.tar.gz (18.0 MB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page