Skip to main content

Make normally distributed parameters non-centered in Stan programs.

Project description

decentralise

Build Status codecov

Make (some) Stan programs non-centered automatically.

Inspired by reading this paper.

Installation

Requires python 3.6+. Install with pip:

pip install decentralise

Example

This package provides a command line tool: decentralise, which is used as follows:

decentralise <input-file> <output-destination>

It will take any normally distributed parameters that have variances that are themselves parameters, and reparameterise them to make them non-centered. For example, the canonical eight schools code is:

data {
  int<lower=0> J; // number of schools
  vector[J] y; // estimated treatment effects
  vector<lower=0>[J] sigma; // s.e. of effect estimates
}
parameters {
  real mu;
  real<lower=0> tau;
  vector[J] theta;
}
model {
  theta ~ normal(mu, tau);
  y ~ normal(theta, sigma);
}

Once decentralise is applied, this program becomes

data {
  int<lower=0> J; // number of schools
  vector[J] y; // estimated treatment effects
  vector<lower=0>[J] sigma; // s.e. of effect estimates
}
parameters {
  real mu;
  real<lower=0> tau;
  vector[J] theta_std;
}
transformed parameters {
  vector[J] theta = mu + theta_std * tau;
}
model {
  theta_std ~ normal(0, 1);
  y ~ normal(theta, sigma);
}

I wrote this tool for fun, and have not thoroughly tested it. For example, it will fail for any parameters whose sampling statements are not vectorised. e.g.:

x ~ normal(mu, tau);

will work, but

for i in (1:n) {
    x[i] ~ normal(mu, tau);
}

will not. There are probably a ton of other cases where it will break that I have not anticipated, as well!

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

decentralise-0.0.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

decentralise-0.0.1-py2.py3-none-any.whl (5.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file decentralise-0.0.1.tar.gz.

File metadata

  • Download URL: decentralise-0.0.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for decentralise-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3b791d798a6da86aa0971f58ff6ebd6d6f385a58bd0c965937da7c573d63cfac
MD5 b16caa4b2460134d8e5940bd4a386114
BLAKE2b-256 d42ea091da9ec70d8dacaea91be8aac0f64d03f55d21cbd86d77ccacb08a7336

See more details on using hashes here.

File details

Details for the file decentralise-0.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: decentralise-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for decentralise-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fcf3f3bd6d2099d1159eb4691324fdfdcc94ad7ed2da0705ea085666229a86e2
MD5 082f2bd8bcd5a61f330e4ed944f62e6b
BLAKE2b-256 dc8149be6aba7250c93124ba449218974c439e58a69384e249edf942c7790b3f

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