Skip to main content

reddemcee

reddemcee light

reddemcee dark

Adaptive Parallel Tempering MCMC Ensemble Sampler, made for the exoplanet finder algorithm EMPEROR. This sampler works as a stand-alone program, so the community might find it useful.

Overview

reddemcee is an Adaptive Parallel Tempering MCMC implementation based on the excellent emcee code, and a modified version of the Vousden et al. implementation.

It's coded in such a way that minimal differences in input are required compared to emcee (v. 3.1.3). Make sure to check reddemcee's documentation, as this readme might not be updated.

Dependencies

This code makes use of:

tqdm is used to display progress bars on the terminal. emcee is used for calculating the autocorrelation times.

Installation

Pip

In the console type

pip install reddemcee

From Source

In the console type

git clone https://github.com/ReddTea/reddemcee
cd reddemcee
python -m pip install -e .

Usage

For a complete tutorial please refer to the documentation's tutorial or the test file in the tests folder.

import numpy as np
import reddemcee

def log_like(x, ivar):
    return -0.5 * np.sum(ivar * x ** 2)

def log_prior(x):
    return 0.0

ndim = 2
ntemps, nwalkers, nsweeps, nsteps = 5, 50, 100, 2

ivar = 1. / np.random.rand(ndim)
p0 = np.random.randn(10, nwalkers, ndim)
sampler = reddemcee.PTSampler(nwalkers,
                             ndim,
                             log_like,
                             log_prior,
                             ntemps=ntemps,
                             loglargs=[ivar],
                             )
                             
sampler.run_mcmc(p0, nsweeps, nsteps)  # starting coords, nsweeps, nsteps

Configuring the Sampler

When setting up PTSampler, you can use the arguments:

Arg Type Description
ntemps int The number of temperatures. If None, determined from betas.
betas list The inverse temperatures of the parallel chains.
pool Pool A pool object for parallel processing.
loglargs list Positional arguments for the log-likelihood function.
loglkwargs list Keyword arguments for the log-likelihood function.
logpargs list Positional arguments for the log-prior function.
logpkwargs list Keyword arguments for the log-prior function.
backend Backend A backend object for storing the chain.
smd_history bool Whether to store swap mean distance history.
tsw_history bool Whether to store temperature swap history.
adapt_tau float Halflife of adaptation hyper-parameter.
adapt_nu float Rate of adaptation hyper-paramter.
adapt_mode 0-4 Mode of adaptation.

The adaptation modes try to equalise the following quantity:

Mode Description
SAR Uniform Swap acceptance rate
SMD Swap Mean Distance
SGG Specific Heat
GAO dE/sig
ETL Thermodynamic Length

Additional Functions

Additional functions on the sampler include:

Function Description
get_evidence_ti Calculates evidence by Thermodynamic Integration
get_evidence_ss Calculates evidence by Stepping Stones
get_evidence_hybrid Calculates evidence by Stepping Stones
get_evidence_mbar All-temperature MBAR normalizing-constant fit
get_autocorr_time Auto-correlation time.
get_betas Returns beta history
get_chain Returns chain
get_log_like Returns log likelihoods
get_logprob Returns log posteriors

Estimate log evidence from equilibrated, frozen-ladder production draws:

logz, mcse, diagnostics = sampler.get_evidence_mbar(
    discard=100, return_diagnostics=True,
)

MBAR uses saved log likelihoods, requires a normalized prior and both beta=0 and beta=1 for absolute evidence, and reports correlation-aware Monte Carlo uncertainty and overlap diagnostics. The MBAR guide shows warmup, freezing, settling, production, and standalone array input with from reddemcee import get_mbar.

Sample-retrieval functions accept these arguments:

Arg Description
flat Flatten the walkers.
thin Take one every thin samples.
discard Drop the first discard steps in samples.

For example, the previous chain would have shape (5, 200, 50, 2), for 5 temperatures, 200 steps (nsweeps*nsteps), 50 walkers, and 2 dimensions.

sampler.get_chain(discard=100)

Would return the samples with shape (5, 100, 50, 2). Dropping the first 100 for every walker.

sampler.get_chain(discard=100, flat=True)

Would return the samples with shape (5, 5000, 2), 'linearising' the walkers.

Metadata

Release files for reddemcee 1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for reddemcee 1.1
File Size Uploaded Provenance Actions
reddemcee-1.1.tar.gz 60.1 kB Without provenance Details for reddemcee-1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for reddemcee 1.1
File Interpreter ABI Platform Actions
reddemcee-1.1-py3-none-any.whl Python 3 none any Details for reddemcee-1.1-py3-none-any.whl

Total release size: 104.0 kB

Release files / reddemcee-1.1.tar.gz

Download URL reddemcee-1.1.tar.gz
Size 60.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0ca237caa8c0fd9f85bb8b6b5dd0b85b7edd5283cac441434bfce1896420b0e5
BLAKE2b-256 checksum
How to use checksums
799e401d0aeae6db2551b78596324080f555dbf24c6b03b9fa3adb3f0c21c88b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / reddemcee-1.1-py3-none-any.whl

Download URL reddemcee-1.1-py3-none-any.whl
Size 44.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0853c49d3b9870c264dabe1a3e9d008df518990ad255ef9f440827b8f586e515
BLAKE2b-256 checksum
How to use checksums
e984100b5da0985eb6bce4c40c46afe0468c7797ff2cac599548460f36a80b0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for reddemcee 1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page