A primer on nested sampling
In this chapter we will explore the basics of the nested sampling (NS) algorithm. As the name suggests NS is an algorithm that can sample parameter spaces in a particularly elegant way. We will first establish the basic working principle of NS and continuously develop some understanding of how NS can be used.
A first glimpse into the NS algorithm
Conceptually NS follows a very simple algorithm. For an objective function
- Initialization: Randomly generate
so called walker configurations from the parameter space - Repeat the following steps until convergence:
- determine the highest
walker , which defines an iso-threshold - remove
as a sample - sample a new walker configuration uniformly from the region where
- determine the highest
This may sound complicated initially, so let's look at a simple 2-dimensional example. In this case the parameter space is
In the interactive visualization below, you can navigate through a NS simulation employing a set of
So what do we observe here? We start from a set of 5 walkers, which are spread almost over the whole region. By definition of the algorithm above, the energy limit of each iteration is lower than the previous one, it has to be monotonically decreasing. Consequently, after every performed iteration, the accessible region in the parameter space becomes smallery. The set of walkers is therefore continuously zooming into the lower energy parts of the parameter space until all walkers eventually collapse into a single point — the global minimum.
NS as an integration algorithm
So far we recognized NS as a kind of optimization algorithm. If we start with a collection of walkers anywhere on the surface, NS will ideally always end up in the global minimum. However, NS is capable of much more than that. As the name nested sampling suggests, a NS simulation generates a set of very useful samples. Before we dive into the details, let's do another interactive experiment. We use the exact same setup as before, but now for each iteration, I highlight the difference between the energy threshold from the current iteration and the iteration before.
You see, that each sample has such a corresponding volume (or area in this 2D case) assigned. If we knew these volumes
Note, that this is very similar to spanning a regular 2D grid through the parameter space. In this case, the volumes would be
Unfortunately, in NS there is no way to analytically get the values for these volumes
The computational bottleneck of NS
In the previous sections we got an idea of the capabilities of the NS algorithm. However, I strategically ignored one central thing so far, which turns out to be the computational bottleneck of the whole algorithm. Namely, how can we sample a new walker configuration uniformly from the region where
Stated in a mathematical fashion, we need to generate a sample from a distribution, which has the probability density
where
This example clearly demonstrates how these random walks can be used to navigate the volumes enclosed by the energy limit
- Clone a random one of your walker configurations
and then subsequently perform a series of
- Sample a displacement
from a proposal distribution (e.g. a 2D gaussian here) - Apply the displacement to the clone
- Evaluate the Metropolis-Hastings acceptance criterion
- if the step is accepted you keep
else you keep
Given that a sufficient amount of MC steps
In other words, we can now put the whole random walk algorithm together like this:
- Clone a random one of your walker configurations
as - Perform a random walk of
MC steps - for i in (1, ..., L)
- Sample a displacement
from a proposal distribution (e.g. a 2D gaussian here) - Apply the displacement to the clone
- If
keep else
- Sample a displacement
- for i in (1, ..., L)
In MCMC based NS implementations, this is where 99.9% of the total computation time is spent, which mainly arises from the large amount of evaluations of the objective function
A simple nested sampling simulator
In this basic introduction we already got our hands on the two main hyperparameters of NS, namely the number of walkers