arXiv:2609.07620cond-mat.stat-mechSep 2026

Manuscript Offprint

arXiv:2609.07620

Microcanonical Hamiltonian Monte Carlo and the Helmholtz Theorem

Heinrich von Campe, Bjoern Malte Schaefer

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

The recently proposed Microcanonical Hamiltonian Monte Carlo algorithm has not yet been studied in detail from a thermodynamic point of view; this work aims to fill that gap. We demonstrate how thermodynamical state variables and potentials can be derived and thereby demonstrate that the construction of the algorithm formally represents a microcanonical thermodynamic ensemble. In particular, we demonstrate (analytically and numerically) that the algorithm fulfils the Helmholtz theorem, an alternative formulation of the first law of thermodynamics. Furthermore, we construct a new sampling algorithm that extends the original to lower-dimensional inference problems. Finally, we argue that canonical Markov Chain Monte Carlo algorithms are more natural than Microcanonical Hamiltonian Monte Carlo from the thermodynamic and information-theoretic point of view.

1 Introduction

Markov Chain Monte Carlo (MCMC) methods have been studied from the perspectives of computer science (algorithmic design), statistics (Bayesian inference), mathematics (symplectic geometry) and physics (statistical physics, thermodynamics). At the intersection of Bayesian inference and statistical physics, the notion of partition functions offers a motivation for different algorithms. Bayes' theorem combines the prior information Π(θ)\Pi(\theta) on the parameters θ\theta of a physical model with the likelihood L(y∣θ)\mathcal{L}(y \mid \theta) as the distribution of the data points yy for a given parameter choice θ\theta to yield the posterior distribution

p(θ∣y)=L(y∣θ)Π(θ)p(y)(1)p(\theta \mid y) = \frac{\mathcal{L}(y \mid \theta) \Pi(\theta)}{p(y)} \tag{1}

with the Bayesian evidence

p(y)=∫dnθ  L(y∣θ)Π(θ)(2)p(y) = \int \mathrm{d}^n \theta \; \mathcal{L}(y \mid \theta) \Pi(\theta) \tag{2}

as the normalisation. The structure of the theorem with an integral in the denominator and the integrand in the numerator suggests the definition of the canonical partition function

Z[T,J]=∫dnθ  dnπexp⁡[−1T(π22−log⁡(LΠ)−J⋅θ)](3)Z[T,J] = \int \mathrm{d}^n \theta \; \mathrm{d}^n \pi \exp\left[-\frac{1}{T}\left(\frac{\pi^2}{2} - \log(\mathcal{L}\Pi) - J \cdot \theta\right)\right] \tag{3}

which reduces to the evidence for a special choice of external parameters, Z[T=1,J=0]=(2π)n2pZ[T=1,J=0] = (2\pi)^{\frac{n}{2}}p. By differentiation of the partition function ln⁡Z\ln Z with respect to JJ, cumulants of the posterior distribution p(θ∣y)p(\theta \mid y) can be computed, making them easily accessible beyond second order. Additionally, the partition sum (3) was extended by momentum degrees of freedom π\pi. This enables the use of simulation techniques such as Hamiltonian Monte Carlo (HMC) (Duane et al., 1987) that are more efficient in exploring the typical set of the posterior than the classic Rosenbluth-Metropolis-Hastings algorithm (Metropolis et al., 1953; Hastings, 1970) that does not require momenta. Both algorithms may be described as “canonical” in the sense that they were based on the above partition function (3).

Thermodynamics is a very powerful effective theory since it allows one to study system from very few to 102310^{23} degrees of freedom through statistical physics. Its application to MCMC methods has proven fruitful. Through the canonical partition function above, it has yielded for instance new convergence criteria for HMC (Röver et al., 2023b). A macrocanonical partition function different from (3) has inspired a corresponding macrocanonical sampling algorithm (Herzog et al., 2024). Recently, a microcanonical sampling algorithm, Microcanonical Hamiltonian Monte Carlo (MCHMC), has been proposed (Robnik et al., 2023). It has been studied extensively from a technical, algorithmic and performative point of view; however, its thermodynamic properties have so far remained unexplored. Our aim is to take the point of view of statistical physics by studying a microcanonical partition function in analogy to (3) to determine its thermodynamic properties. Since this algorithm is so clearly inspired by the microcanonical ensemble, we deem it essential for practitioners to understand the underlying assumptions and verify that the thermodynamic prerequisites are met. While this analysis is open-ended, we find several fundamental insights at this intersection between statistical physics, thermodynamics, Bayesian inference and machine learning.

Contributions We check that MCHMC fulfils the first law of thermodynamics in the form of the Helmholtz theorem (described in Sec. 2) analytically in general and numerically by applying it to a toy problem as well as a cosmological inference problem on type Ia supernovae (Sec. 3). Importantly, we find that the main condition for the Helmholtz theorem is strongly conceptually linked to the notion of ergodicity, better explaining how MCHMC improves over its predecessor (Ver Steeg & Galstyan, 2021). At the same time, the notion of volume entropy needed for the Helmholtz theorem inspires a new sampling algorithm which we briefly discuss. Finally, we clarify the notion of thermodynamical entropy in the microcanonical ensemble and its relation to information entropy in inference problems. We compare this to the properties of the canonical ensemble (Sec. 4) and conclude that the latter is a more natural description of most MCMC methods.

Related Work MCHMC was first presented and extensively numerically tested by Robnik et al. (2023), being inspired by HMC (Duane et al., 1987), Langevin Monte Carlo (Grenander & Miller, 1994) and the Energy Sampling Hamiltonian (Ver Steeg & Galstyan, 2021). It has since been improved by introducing RMH accept/reject steps similar to HMC (Robnik et al., 2025) ¹ and tested on cosmological inference (Bayer et al., 2023), statistical field theory (Robnik & Seljak, 2024) and Bayesian Neural Networks (Sommer et al., 2025). The thermodynamic nature of the older, canonical MCMC methods has been studied extensively in the past (Jaynes, 1957; Röver et al., 2023a;b; Herzog et al., 2024; Kuntz et al., 2024; 2025). The original Helmholtz theorem may be found in von Helmholtz (1884). It relies on other notions than those in today's thermodynamics literature and has been rediscovered by Campisi (2005).

In the following, we will denote the likelihood and prior as L\mathcal{L} and Π\Pi, respectively. The posterior is referred to as p(θ∣y)p(\theta \mid y), the evidence as pp. The parameters will be called θ\theta, the momenta π\pi, the Heaviside function Θ\Theta. We adopt index notation and the Einstein summation convention.

References (28)