Automatic Parallel Tempering Markov Chain Monte Carlo with Nii-C

Sheng Jin, Wenxin Jiang, Dong-Hong WuarXiv 2024 · DOI

Abstract

Due to the high dimensionality or multimodality that is common in modern astronomy, sampling Bayesian posteriors can be challenging. Several publicly available codes based on different sampling algorithms can solve these complex models, but the execution of the code is not always efficient or fast enough. The article introduces a C language general-purpose code, Nii-C, that implements a framework of Automatic Parallel Tempering Markov Chain Monte Carlo. Automatic in this context means that the parameters that ensure an efficient parallel tempering process can be set by a control system during the initial stages of a sampling process. The auto-tuned parameters consist of two parts, the temperature ladders of all parallel tempering Markov chains and the proposal distributions for all model parameters across all parallel tempering chains. In order to reduce dependencies in the compilation process and increase the code's execution speed, Nii-C code is constructed entirely in the C language and parallelised using the Message-Passing Interface protocol to optimise the efficiency of parallel sampling. These implementations facilitate rapid convergence in the sampling of high-dimensional and multi-modal distributions, as well as expeditious code execution time.

Introduction

In modern astronomy and physics, Bayesian inference is a cornerstone for fitting complex models to observational data. However, researchers frequently encounter "posterior distributions" that are difficult to navigate due to high dimensionality—often involving dozens of parameters—and multimodality, where the distribution contains multiple local optima. Standard Markov Chain Monte Carlo (MCMC) samplers often become trapped in these local peaks, leading to biased or incomplete results.

Parallel Tempering (PT) offers a solution by running multiple chains at different "temperatures," allowing "hotter" chains to explore the parameter space more freely and jump between modes. However, PT is notoriously difficult to configure, requiring manual tuning of "temperature ladders" and step sizes. Nii-C is a high-performance C-based tool designed to automate this "black art." By automatically tuning these parameters during an early phase, Nii-C enables efficient sampling of complex distributions with significantly higher speed and less manual intervention than existing frameworks.

Methods

Nii-C is implemented entirely in pure C and parallelized using the Message-Passing Interface (MPI) protocol. Its primary innovation is an integrated Automatic Tuning Stage that stabilizes the sampling process before the final production run.

Flowchart of the Nii-C automatic parallel tempering process, illustrating the iterative tuning of temperature ladders and proposal distributions.

The workflow consists of two main phases:

  1. Automatic Temperature Ladders: The system monitors the swap rate between adjacent chains. If the swap frequency is insufficient, it dynamically adjusts temperatures to ensure efficient information flow from exploratory "hot" chains to the "cold" target chain.
  2. Automatic Proposal Distributions: The code adjusts the step size (standard deviation) for every parameter in every chain to achieve an optimal acceptance rate, typically around 23.4%.
  3. Production Sampling: To maintain the Markov property and ensure mathematical rigor, tuning is locked once parameters stabilize. The sampler then proceeds to the "production" phase to generate the final posterior distribution.

Performance and Validation

The performance of Nii-C was evaluated using both synthetic benchmarks and real-world astronomical datasets.

Benchmarking and Speed

By utilizing pure C and avoiding the overhead of interpreted languages like Python, Nii-C achieves substantial performance gains. In comparative tests, Nii-C demonstrated execution speeds up to 117 times faster than the popular Python-based PTMCMCSampler. This efficiency allows researchers to perform millions of iterations in minutes rather than hours; for instance, a complex hierarchical model with 10 million iterations was sampled in approximately 1,200 seconds on a standard laptop.

Robustness to Multimodality

The code's ability to handle extreme multimodality was tested using the 5D Rastrigin function and the "Eggbox" distribution. While standard MCMC configurations often fail on these non-convex optimization tests, Nii-C’s automatic tuning successfully mapped the distributions. This proves that the automated features are critical for reliably sampling complex landscapes without expert-level manual configuration.

Real-World Application

Nii-C was applied to real data from the NASA Exoplanet Archive to model the hierarchical radius relationship of "hot Jupiters" and to simulated astrometric data for a 15-parameter two-planet system. In the latter, Nii-C accurately retrieved all 15 parameters, including masses and orbital periods, matching the simulated "true" values within tight margins.

Conclusion and Future Directions

Nii-C provides a robust, high-speed framework for Bayesian inference in high-dimensional spaces. Its minimal dependency on external libraries makes it highly portable for high-performance computing (HPC) environments.

Current limitations include a fixed number of parallel chains, which must be specified at initialization. Future development aims to allow the dynamic addition or removal of chains based on real-time complexity assessments. Additionally, the authors plan to incorporate more advanced algorithms, such as the Langevin algorithm, to leverage gradient information for even more efficient sampling. While the C-based nature of the tool requires users to modify and recompile template files, the resulting performance gains and automated tuning capabilities offer a significant advantage for large-scale astronomical data analysis.

Summary updated

BibTeX
@misc{jin2024automatic,
  author = {Sheng Jin and Wenxin Jiang and Dong-Hong Wu},
  title = {{Automatic Parallel Tempering Markov Chain Monte Carlo with Nii-C}},
  year = {2024},
  eprint = {2407.09915},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.09915},
}
Figure