Skip to main content

Bayesian Quanile Matching Estimation

Project description

Bayesian Quantile Matching Estimation using Order Statistics

BQME is a package that allows users to fit a distribution to observed quantile data. The package uses Order Statistics as the noise model, which is more robust than e.g. Gaussian noise model (mean squared error). The paper describing the theory can be found on arxiv: https://arxiv.org/abs/2008.06423. The notebooks for the experiments in the paper are moved to https://github.com/RSNirwan/BQME_experiments.

Install

Install latest release via pip

pip install bqme

Latest development version can be installes as follows (@todo make develop branch the default). Clone the repository and install via pip

git clone https://github.com/RSNirwan/bqme
cd bqme
pip install .

Install with dev dependencies

git clone https://github.com/RSNirwan/bqme
cd bqme
pip install -e .[dev]

if using ZSH, do the following pip install -e ".[dev]"

Usage

To fit a Normal distribution to observed quantile data, we do the following. Note that the likelihood is not a Normal distribution, but the order statistics of the observed quantiles assuming the underlying distribution is a Normal.

from bqme.distributions import Normal, Gamma
from bqme.models import NormalQM

N, q, X = 100, [0.25, 0.5, 0.75], [-0.1, 0.3, 0.8]

# define priors
mu = Normal(0, 1, name='mu')
sigma = Gamma(1, 1, name='sigma')

# define likelihood
model = NormalQM(mu, sigma)

# sample the posterior
samples = model.sampling(N, q, X)  # returns a stan fit object

# extract samples
mu_samples = samples.extract('mu')['mu']
sigma_samples = samples.extract('sigma')['sigma']

We can also look at the generated stan code and optimize the parameters (MAP) instead of sampling the posterior

mu = Normal(0, 1, name='mu')
sigma = Gamma(1, 1, name='sigma')
model = NormalQM(mu, sigma)

# print generated stan code
print(model.code)

# optimize
N, q, X = 100, [0.25, 0.5, 0.75], [-0.1, 0.3, 0.8]
opt = model.optimizing(N, q, X)

# extract optimized parameters
mu_opt = opt['mu']
sigma_opt = opt['sigma']

(so far) Available distributions (prior) and models

distributions/priors (import from bqme.distributions):

  • Normal(mu:float, sigma:float)
  • Gamma(alpha:float, beta:float)

models (import from bqme.models):

  • NormalQM(mu:distribution, sigma:distribution)

Inputs to the models need to be distributions.

Todos

  • make package available on PyPI
  • tag/release on github
  • add code coverage
  • testing with nox
  • use sphinx as documentation tool
  • add Mixture-model
  • implement fit.ppf(q), fit.cdf(x), fit.pdf(x), ...

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

bqme-0.0.2.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

bqme-0.0.2-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file bqme-0.0.2.tar.gz.

File metadata

  • Download URL: bqme-0.0.2.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for bqme-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fdeb00ef793e2b23fd1e75fb2545b60073f5f5384283c8a6a5110b7e9cfacd8e
MD5 85a20b160f995a29214d1152703e4424
BLAKE2b-256 20e65db80c310bbc1150d2fccb53e917c81b24805f202aa073773f06c2b9028f

See more details on using hashes here.

File details

Details for the file bqme-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: bqme-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.2

File hashes

Hashes for bqme-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6abeca48e78f28b7b1117e005b80a26826f0dfa5cc9401a7d5736faf2e510f2f
MD5 a03ee79a63271034ba2209c6d7763613
BLAKE2b-256 fcd6731b342839eb3f310d70c13b0e82db52938c127cafd89321956c07081737

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