Adaptive Parallel Tempering MCMC Ensemble Sampler
Project description
reddemcee
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_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 |
All these functions accept as 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file reddemcee-1.0.tar.gz.
File metadata
- Download URL: reddemcee-1.0.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e73a4b76b302dc9888170c153f52b0b5428aa2662d2f3a26e15fe6167a2608d
|
|
| MD5 |
24ef7df4ddc80efbfac0470930a38118
|
|
| BLAKE2b-256 |
fb241490a54a399be280fc6bf35ad7796926bbd7c70859575362d77267ef94ab
|
File details
Details for the file reddemcee-1.0-py3-none-any.whl.
File metadata
- Download URL: reddemcee-1.0-py3-none-any.whl
- Upload date:
- Size: 33.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e7eb7b5c81edd25d2f91604182e185484fdd2e13ccdaa4db496b85766667ab5
|
|
| MD5 |
8b974a37b1fc2327556046870d6e72e1
|
|
| BLAKE2b-256 |
1d594759f5516d30e8b1142904dba2e15d151c27e6b8af6b3eb94d69452514ad
|