Given a covariance matrix $\Sigma \in \mathbb{R}^{n \times n}$, I want to produce a sample $x \in \mathbb{R}^n$ from the corresponding multivariate normal distribution, but conditioning on $x$ satisfying some constraint.
The simplest constraint is $sum(x) = 0$. More generally, I could mandate a set of linear equalities $A x = b$.
Most generally, I would ask that $x$ satisfy a constraint like $f(x) = 0 $.
The very most general question is, if I know how to sample from a multivariate distribution $\mathcal{D}$, how would I sample from that distribution conditioned on the constraint $f(x) = 0$?
How could I do this? I'd imagine there's a good solution for at least the Gaussian + linear case.
My current guess at a solution is something like Gibbs sampling:
- Initialize $x$ to be something
- Randomly choose two indices $i,j$ and fix each component of $x$ except $x_i$ and $x_j$.
- Let $x_j = g(x_i)$, where $g$ is such that $x$ will satisfy the given constraint.
- The only free variable left is $x_i$. Sample $x_i$ from the single-variate distribution, which (e.g. for a gaussian dist.) is proportional to $\exp\left( x^\intercal \Sigma^{-1} x \right)$ where only $x_i$ is free, $x_j$ is a function of $x_i$, and the rest are fixed.
- Go back to step 2 to repeat a few hundred times for a good sample.