Sampling from a specific level set of a Gaussian

How to sample uniformly from a level set of a Gaussian

In this very short note, I will describe how to sample from a specific level set of a d-dimensional Gaussian.

Ellipsoids

A (d1)-dimensional ellipsoid in Rd is defined by the following equation (xv)A(xv)=1, where vRn is the center of the ellipsoid and A is an n×n positive-definite symmetric matrix.

Gaussian Level-Sets as Ellipsoids

Consider a multivariate Gaussian distribution π with covariance matrix Σ and mean μ with density π(x)=(2π)d/2det(Σ)1/2exp(12(xμ)Σ1(xμ)). The maximum density value achieved is π(μ) as can be seen by setting the gradient to zero xπ(x)=π(x)Σ1(xμ)=0x=μ. For any positive value c(0,π(μ)), π1({c}) denotes the c-level set of π. We wish to show that this is a (d1)-dimensional ellipsoid in Rd. The level set is the following set of points Ec:={xRd:(2π)d/2det(Σ)1/2exp(12(xμ)Σ1(xμ))=c} Since log is a monotone function, this is equivalent to Ec:={xRd:d2log(2π)12logdetΣ12(xμ)Σ1(xμ)=logc} Rearranging terms we get Ec:={xRd:(xμ)Σ1(xμ)=b(c,Σ)} where we have defined the constant b(c,Σ)=2logcdlog(2π)logdetΣ. Since the LHS is a quadratic form, b(c,Σ) must be positive so we can divide through to obtain Ec:={xRd:(xμ)(bΣ)1(xμ)=1} Therefore they are ellipsoids centered at v=μ with matrix A=(bΣ)1.

Sampling from the level set

To sample exactly from this level set we follow the following algorithm:

  1. Sample xN(0d,Id)
  2. Set x^:=x/x so that x^U(Sd1)
  3. Obtain sample y:=Lx^ where L is the Cholesky decomposition of bΣ, i.e. bΣ=LL
Avatar
Mauro Camara Escudero
Machine Learning Engineer

My research interests include approximate manifold sampling and generative models.