Skip to main content

Quadratic approximation for PyMC3

Project description

pymc3-quap

The quadratic approximation is a very fast method to approximate the posterior with a multivariate normal.

NOTE: The quadratic approximation only works well if the posterior is uni-modal and roughly symmetrical.

Example

import numpy as np
import pymc3 as pm
import arviz as az
from quap import quap
y = np.array([2642, 3503, 4358]*10)

# Normal with unknown mean and log-variance, with uniform priors 
with pm.Model() as m: 
  logsigma = pm.Uniform("logsigma", -100, 100)
  mu = pm.Uniform("mu", -10000, 10000) 
  yobs = pm.Normal("y", mu=mu, sigma=pm.math.exp(logsigma), observed=y)
  idata, posterior = quap([mu, logsigma])

az.plot_posterior(idata)

Approximate posterior

idata is an arviz.InferenceData with samples from the approximate posterior for compatibility with the Arviz ecosystem.

posterior is the exact approximate posterior scipy.stats.multivariate_normal

True and quadratic approximation of posterior

True posterior and quadratic approximation for the example above.

Install

pip install pymc3-quap

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

pymc3-quap-1.0.2.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

pymc3_quap-1.0.2-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file pymc3-quap-1.0.2.tar.gz.

File metadata

  • Download URL: pymc3-quap-1.0.2.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11

File hashes

Hashes for pymc3-quap-1.0.2.tar.gz
Algorithm Hash digest
SHA256 940953073b275ac54cf80212fd46849086c8a9b7a016fc47ef6b1e71d20326e4
MD5 9ec6bceff3f2ded9311a7216ce211d63
BLAKE2b-256 79543db7c7e36ba77d22d95e61fbd07cae4c7e679d7346b5696901255326ad41

See more details on using hashes here.

File details

Details for the file pymc3_quap-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pymc3_quap-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.11

File hashes

Hashes for pymc3_quap-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 852b4d2d4d94d5bbbbd640b54848b3e7a3bead36a0216bf66c453ca9a99fe783
MD5 79ecfced7edbc47a1dd4e1c124a0fe16
BLAKE2b-256 3ec5249d8aba331a19a1aa6b028594897fa656b401e8ec9be74dc3395d6df951

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