Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Use Tempered SMC to Improve Exploration of MCMC Methods.

Multimodal distributions are typically hard to sample from, in particular using energy based methods such as HMC, as you need high energy levels to escape a potential well.

Tempered SMC helps with this by considering a sequence of distributions:

pλk(x)∝p0(x)exp⁡(−λkV(x))p_{\lambda_k}(x) \propto p_0(x) \exp(-\lambda_k V(x))

where the tempering parameter λk\lambda_k takes increasing values between 0 and 1. Tempered SMC will also particularly shine when the MCMC step is not well calibrated (too small step size, etc) like in the example below.

Imports

Notebook Cell

Sampling From a Bimodal Potential

Experimental Setup

We consider a prior distribution

p0(x)=N(x∣0,1)p_0(x) = \mathcal{N}(x \mid 0, 1)

and a potential function

V(x)=(x2−1)2V(x) = (x^2 - 1)^2

This corresponds to the following distribution. We plot the resulting tempered density for 5 different values of λk\lambda_k : from λk=1\lambda_k =1 which correponds to the original density to λk=0\lambda_k=0. The lower the value of λk\lambda_k the easier it is for the sampler to jump between the modes of the posterior density.

Source
<Figure size 1200x800 with 1 Axes>

Sample with HMC

We first try to sample from the posterior density using an HMC kernel.

CPU times: user 3.11 s, sys: 110 ms, total: 3.22 s
Wall time: 2.44 s
Source
<Figure size 640x480 with 1 Axes>

Sample with NUTS

We now use a NUTS kernel.

CPU times: user 24.8 s, sys: 194 ms, total: 25 s
Wall time: 24.1 s
Source
<Figure size 640x480 with 1 Axes>

Tempered SMC with HMC Kernel

We now use the adaptive tempered SMC algorithm with an HMC kernel. We only take one HMC step before resampling. The algorithm is run until λk\lambda_k crosses the λk=1\lambda_k = 1 limit.

Number of steps in the adaptive algorithm:  2
CPU times: user 4.13 s, sys: 81.7 ms, total: 4.21 s
Wall time: 2.17 s
Source
<Figure size 640x480 with 1 Axes>

Sampling from the Rastrigin Potential

Experimental Setup

We consider a prior distribution p0(x)=N(x∣02,2I2)p_0(x) = \mathcal{N}(x \mid 0_2, 2 I_2) and we want to sample from a Rastrigin type potential function V(x)=−2A+∑i=12xi2−Acos⁡(2πxi)V(x) = -2 A + \sum_{i=1}^2x_i^2 - A \cos(2 \pi x_i) where we choose A=10A=10. These potential functions are known to be particularly hard to sample.

We plot the resulting tempered density for 5 different values of λk\lambda_k: from λk=1\lambda_k =1 which correponds to the original density to λk=0\lambda_k=0. The lower the value of λk\lambda_k the easier it is to sampler from the posterior log-density.

Source
<Figure size 1200x800 with 1 Axes>

HMC Sampler

We first try to sample from the posterior density using an HMC kernel.

CPU times: user 1.31 s, sys: 11.1 ms, total: 1.33 s
Wall time: 889 ms
Source
<Figure size 640x480 with 1 Axes>

NUTS Sampler

We do the same using a NUTS kernel.

CPU times: user 1.72 s, sys: 26.1 ms, total: 1.74 s
Wall time: 1.03 s
Source
<Figure size 640x480 with 1 Axes>

Tempered SMC with HMC Kernel

We now use the adaptive tempered SMC algorithm with an HMC kernel. We only take one HMC step before resampling. The algorithm is run until λk\lambda_k crosses the λk=1\lambda_k = 1 limit. We correct the bias introduced by the (arbitrary) prior.

Number of steps in the adaptive algorithm:  6
CPU times: user 3.77 s, sys: 39.9 ms, total: 3.81 s
Wall time: 1.92 s
Source
<Figure size 640x480 with 1 Axes>

The tempered SMC algorithm with the HMC kernel clearly outperfoms the HMC and NUTS kernels alone.