Skip to main content

Adaptive Markov Chain Monte Carlo (MCMC) algorithms

Project description

Adaptive-MCMC

Adaptive Markov Chain Monte Carlo (MCMC) algorithms

Install

pip install adaptive-mcmc

Examples

import numpy as np
from adaptive_mcmc.mala import ESJDMALA
from scipy.stats import multivariate_normal

dim = 20
cov = 0.5 * np.eye(dim) + 0.5
inv_cov = np.linalg.inv(cov)


def logp(x):
    return multivariate_normal.logpdf(x, mean=np.zeros(dim), cov=cov)


def grad_logp(x):
    return -inv_cov @ x


mala = ESJDMALA(logp, grad_logp, initial_sample=np.zeros(dim), eps0=0.5)
samples, acc, eps_hist, esjd_hist = mala.run(20_000)
print(f"Acceptance: {acc:.3f}, Final epsilon = {eps_hist[-1]:.4f}")

pmala = PrecondESJDMALA(logp, grad_logp, initial_sample=np.zeros(dim), initial_covariance=np.eye(dim), eps0=0.5)
samples, acc, eps_hist, esjd_hist = pmala.run(20_000)
print(f"Acceptance: {acc:.3f}, Final epsilon = {eps_hist[-1]:.4f}")

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

adaptive_mcmc-0.1.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

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

adaptive_mcmc-0.1.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file adaptive_mcmc-0.1.2.tar.gz.

File metadata

  • Download URL: adaptive_mcmc-0.1.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.3

File hashes

Hashes for adaptive_mcmc-0.1.2.tar.gz
Algorithm Hash digest
SHA256 414f41ef30836ea62f4aa15fcaa90a505e758d618d26a2b0b835ac7e0fba974f
MD5 1a7cf5aa802c49e2e5c59130ed92ea0c
BLAKE2b-256 967ab50b258e0b5376ab49a7a58da5c3e97914593a216806e5e52abe1a5d5ae9

See more details on using hashes here.

File details

Details for the file adaptive_mcmc-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for adaptive_mcmc-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 73dce830f80f284018aab3555d7ba26450d7827294044db7b7c1bbae7d4e3238
MD5 d081b10fb064e6e89f81b19ee523c62c
BLAKE2b-256 a459e0d3f27aca67f4215438abb3ec67d914f99fb47b02480fa9918be6f99ae0

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