In this post, we summarize several important applications of the theory of Wasserstein gradient flows in statistics and machine learning.

Variational Inference

\[q_*=\arg\min_{q\in\cQ} \KL(q\|\pi)\]

For this problem, our previous theory proves that minimizing the Kullback-Leibler (KL) divergence to a log-concave distribution over the Wasserstein space is a strongly convex problem.

$\pi\propto \exp(-V)$

\[\tag{1} \partial_t\mu_t={\rm div}(\mu_t\nabla\log \frac{\mu_t}{\pi})\]

Suppose $V:\RR^d\to\RR$ is $\alpha$-convex on $\RR^d$. Then the corresponding potential energy functional $\cV$ defined by $\cV(\mu):=\int V\mathrm{d}\mu$ is $\alpha$-geodesically convex on $\cP_{2,\rm{ac}}(\RR^d)$.

The entropy functional $\cH(\mu):=\int \mu\log \mu$ is geodesically convex on $\cP_{2,\rm{ac}}(\RR^d)$.

Gaussian VI

Going beyond the Laplace approximation, we can ask for the optimal Gaussian approximation, which is formulated as the VI problem

\[q_*=\arg\min_{q\in{\rm BW}(\RR^d)} \KL(q\|\pi)\]

For the KL ddivergence \(\cF=\KL(\cdot\|\pi)\),

Therefore, the BW gradient flow of the functional \(\KL(\cdot\|\pi)\), where $\pi\propto \exp(-V)$, is the curve $(q_t=\cN(m_t,\Sigma_t))_{t\geq 0}$, where

\[\begin{align*} &\dot{m}_t=-\EE \nabla V(X_t)\\ &\dot{\Sigma}_t=2I-\EE \nabla^2 V(X_t)\Sigma_t-\Sigma_t\EE \nabla^2V(X_t) \end{align*}\]

and $X_t\sim q_t$.

Mean-Field VI

Another important variational family is the class $\cQ=\cP_{2,{\rm ac}}(\RR)^{\otimes d}$ of product measures over $\RR^d$, in which case the problem is known as mean-field VI:

\[q_*=\arg\min_{q\in\cP_{2,{\rm ac}}(\RR)^{\otimes d}} \KL(q\|\pi).\]

In this section, we describe an approach based on finite-dimensional parameterization. The idea is to parameterize an element $q\in \cP_{2,{\rm ac}}(\RR)^{\otimes d}$ via the Brenier map $T_{\rho\to q}$ from the standard Gaussian measure $\rho$. Since both $\rho$ and $q$ are product measures, the transport map is separable, i.e., it is of the form $T_{\rho\to q}(x)=(T_1(x_1),\dots,T_d(x_d))$ for some univariate (and increasing) maps $T_i:\RR\to\RR$.

However, the class of such mapsis still infinite-dimensional and needs to be further restricted for implementation. To do so, we take a finite family $\cT:={T_1,\dots,T_N}$ of optimal transport maps called the dictionary, and take as our eventual family of map the set $\operatorname{cone}(\cT)$ of all conic combinations of elements of $\cT$:

\[\operatorname{cone}(\cT)=\left\{\sum_{i=1}^N \lambda_iT_i \bigg\vert \lambda\in \RR_+^N \right\}.\]

This set is now finite-dimensional, and in fact is parameterized by the positive orthant $\RR_+^N$. Therefore, we can now optimize the functional \(\lambda\mapsto \KL(\rho^\lambda\| \pi)\) over $\RR_+^N$. Note that we have replaced our original variational family $\cP_{2,\rm{ac}}(\RR)^{\otimes d}$ with the smaller set \(\operatorname{cone}(\cT)_\sharp\rho\), but the hope is that for an appropriate choice of $\cT$, the family \(\operatorname{cone}(\cT)_\sharp\rho\) is expressive enough to approximately capture all of $\cP_{2,\rm{ac}}(\RR)^{\otimes d}$.

The key observation is that the map \((\RR_+^N,\|\cdot\|_Q)\to (\operatorname{cone}(\cT)_\sharp\rho,W_2)\): $\lambda\mapsto\rho^\lambda$ is an isometry, where $|x|_Q^2:=\left\langle x,Qx\right\rangle$ and $Q$ is the $N\times N$ matrix with entries

\[Q_{ij}:=\left\langle T_i,T_j\right\rangle_\rho.\]

Denote $T^\lambda:=\sum_{i=1}^N \lambda_iT_i$ and \(\rho^\lambda:=(T^\lambda)_\sharp\rho.\) The Wasserstein gradient flow of $\KL(\cdot|\pi)$ restricted to \(\operatorname{cone}(\cT)_\sharp\rho\) is given by $(\rho^{\lambda(t)})_{t\geq 0}$, where

\[\dot{\lambda}_T=\]

Stein Variational Gradient Descent

We now ask whether we can minimize the KL divergence over the family of empirical measures.

Instead of doing the steepest descent in $L^2(\mu)$, we do the steepest descent with respect to a RKHS.

Sampling

We already know that the Wasserstein gradient flow of $\mathrm{KL}(\mu|\pi)$, where $\pi\propto e^{-V}$, is

\[\partial_t\mu_t =\nabla\cdot(\mu_t\nabla V)+\Delta\mu_t.\]

The important observation is that this equation has a stochastic implementation:

\[dX_t=-\nabla V(X_t)\,dt+\sqrt2\,dB_t.\]

Our theory proves that the Fokker-Planck equation (which governs the marginal law of the stochastic Langevin diffusion) is exactly the Wasserstein gradient flow of the KL divergence.

By proving that sampling is mathematically identical to optimization, practitioners can borrow state-of-the-art algorithms from deep learning and convex optimization (like Proximal Gradient, Mirror Descent, and Nesterov Acceleration) to remove asymptotic bias and drastically speed up the convergence of their MCMC samplers.

\[\tag{2} \partial_t\mu_t=\Delta \mu_t+{\rm div}(\mu_t\nabla V).\]

which is the Fokker-Planck equation

Interacting Particle Systems

If there is an interaction energy.

More generally,

Mean Field VI

One can show that for a functional $\cF$, the component of the Wasserstein gradient $\nabla\mkern-10mu\nabla\cF(\mu)$ which is tangential to the space of product measures takes the form

\[x\mapsto \left(\int \nabla\mkern-10mu\nabla\cF(\mu)(x)\mu(\mathrm{d} x_1,\dots,\mathrm{d} x_{i-1},\mathrm{d} x_{i+1},\dots,\mathrm{d} x_d)\right)_{i=1}^d.\]

Note that the particle approach does not apply because the Wasserstein gradient of the KL divergence is not defined for discrete measures. We therefore use the stochastic dynamics to circumvent this issue:

\[\mathrm{d} X_t=-\int \nabla_1 W(X_t,y)\mu_t(\mathrm{d} y)\mathrm{d} t+\sqrt{2}\mathrm{d} B_t\]

where $\mu_t=\operatorname{Law}(X_t)$, $\nabla_1$ denotes the gradient taken with respect to the first argument, and

\[W(x,y):=\sum_{i=1}^d V(y_1,\dots,y_{i-1},x_i,y_{i+1},\dots, y_d).\]

The corresponding interacting particle system is given by

\[\mathrm{d} X_t^j=-\frac{1}{N-1}\su\]

Birth-Death Sampling

Fisher-Rao gradient flow can also be implemented by a stochastic birth–death process, in the same sense that Langevin diffusion implements the Wasserstein gradient flow of KL.

Write

\[\partial_t\mu_t=-\alpha_t\mu_t, \qquad \int\alpha_t\,d\mu_t=0.\]

We want to construct a birth–death process whose probability distribution satisfies this equation.

For any test function $\varphi$, the desired evolution is

\[\frac{d}{dt}\int\varphi\,d\mu_t =-\int\varphi(x)\alpha_t(x)\,\mu_t(dx).\]

We will prove this identity from the birth–death mechanism.

Suppose that at time $t$, the particle population has distribution $\mu_t$.

A particle at $x$ has an exponential clock with instantaneous rate $ \alpha_t(x) $.

When its clock rings:

  • If $\alpha_t(x)>0$, it dies and is replaced by a particle sampled from $\mu_t$.
  • If $\alpha_t(x)<0$, it duplicates itself and replaces a randomly selected particle from $\mu_t$. Let $m_\varphi=\int\varphi\,d\mu_t$.

Death events. A particle at $x$ with $\alpha_t(x)>0$ is replaced by $Y\sim\mu_t$. The expected change in $\varphi$ is

\[\EE[\varphi(Y)-\varphi(x)] =m_\varphi-\varphi(x).\]

Since the death rate is $\alpha_t(x)$, the total death contribution is

\[\int \alpha_t(x)_+ \big(m_\varphi-\varphi(x)\big)\,\mu_t(dx).\]

Birth events. A particle at $x$ with $\alpha_t(x)<0$ replaces another particle $Y\sim\mu_t$. The expected change is

\[\EE[\varphi(x)-\varphi(Y)] =\varphi(x)-m_\varphi.\]

The birth rate is $\alpha_t(x)_-=\max{-\alpha_t(x),0}$, so the total birth contribution is

\[\int \alpha_t(x)_- \big(\varphi(x)-m_\varphi\big)\,\mu_t(dx).\]

Adding both contributions gives

\[\begin{aligned} \frac{d}{dt}\int\varphi\,d\mu_t &=-\int\alpha_t(x) \big(\varphi(x)-m_\varphi\big)\,\mu_t(dx)\\ &=-\int\alpha_t(x)\varphi(x)\,\mu_t(dx), \end{aligned}\]

where the last equality uses $\int\alpha_t\,d\mu_t=0$.

This is exactly equation (1). Therefore, the limiting birth–death dynamics implement the Fisher–Rao gradient flow.

Non-parametric Maximum Likelihood

The NPMLE problem can be mathematically reformulated as minimizing an entropic optimal transport cost, which can be approached via gradient flows.

Consider a Gaussian mixture on $\RR^d$ with density given by:

\[G_\rho=\int_{\RR^d}\phi(\cdot-y)\rho(\mathrm{d} y)=\phi * \rho.\]

where $\phi(z)=(2\pi)^{-d/2}\exp(-|z|^2/2)$.

The negative log-likelihood for this problem is defined as:

\[\ell_n(\rho):=-\frac{1}{n}\sum_{i=1}^n \log G_\rho(X_i)=-\frac{1}{n}\sum_{i=1}^n\log \phi*\rho(X_i).\]

The non-parametric maximum likelihood estimator (NPMLE) is defined as any minimizer of $\ell_n$:

\[\hat\rho=\arg\min_{\rho\in \cP(\RR^d)}\ell_n(\rho).\]

Entropic OT Connection

KL barycenter problem

Writing $\mu_n$ for the empirical measure $\frac{1}{n}\sum_{i=1}^n\delta_{X_i}$, it turns out that the NPMLE satisfies

\[\hat\rho=\arg\min_{\rho\in\cP(\RR^d)}S_{2\sigma^2}(\mu_n,\rho),\]

where $S_{2\sigma^2}(\cdot,\cdot)$ is the entropic optimal transport cost with regularization parameter $\epsilon=2\sigma^2$.

The reason that this could happen is similar to Moreau envelop.

Algorithms Based on Wasserstein Gradient Flow

Mean-Field Neural Networks

The key idea is to interpret the training of two-layer neural networks as a Wasserstein gradient flow over probability distributions on neuron parameters.

A two-layer neural network can be represented as

\[f_\mu(x)=\int \rho(x;\omega)\,\mu(\mathrm{d}\omega),\]

where \(\mu\) is a probability distribution over neuron parameters. A finite-width network corresponds to the empirical measure

\[\mu=\frac{1}{m}\sum_{j=1}^m\delta_{\omega_j}.\]

The squared loss is convex in \(\mu\) under linear interpolation of measures, even though it is generally nonconvex in the neuron parameters.

Ordinary Euclidean gradient flow of the neuron parameters induces the Wasserstein gradient flow of the loss functional, up to a time rescaling by the network width $m$. Thus, neural network training can be understood as an interacting particle system, where each neuron is a particle.

Suppose $\mathcal F$ is any sufficiently differentiable functional on probability measures, and define

\[F_m(\omega_1,\ldots,\omega_m) = \mathcal F\left(\frac1m\sum_{j=1}^m\delta_{\omega_j}\right).\]

The chain rule gives

\[\nabla_{\omega_j}F_m = \frac1m \nabla_\omega\frac{\delta\mathcal F}{\delta\mu}(\omega_j).\]

This identity immediately establishes the correspondence between Euclidean gradient flow of $F_m$ and Wasserstein gradient flow of $\mathcal F$ restricted to equally weighted empirical measures.

As \(m\to\infty\), the empirical distribution of neuron parameters can converge to a deterministic measure-valued gradient flow. This provides a framework for analyzing neural network training without fixing the number of neurons. Although the loss is convex under linear interpolation of measures, it is generally not Wasserstein geodesically convex, so standard geodesic-convexity arguments do not apply. Nevertheless, under suitable assumptions on initialization and the model, global convergence results can be established using the mean-field formulation.

Transformers

The key idea is to interpret self-attention as an interacting particle system and use gradient-flow theory to study token clustering.

  1. Self-attention as particle dynamics. In a simplified continuous-depth transformer, each token is a particle whose velocity depends on the empirical distribution of all tokens. This yields a mean-field dynamical system.

  2. Gradient-flow structure. For simplified self-attention with \(Q=K=V=I\), unnormalized attention is the Wasserstein gradient ascent of the interaction energy

    \[\mathcal E(\mu)=\frac12\iint e^{\langle x,y\rangle}\,\mathrm{d}\mu(x)\mathrm{d}\mu(y).\]

    Normalized (softmax) attention is not generally a gradient flow under the standard Wasserstein metric, but it is a preconditioned gradient ascent of the same energy, or equivalently a gradient flow under a modified Riemannian metric. The modified metric offers a convenient interpretation, but introduces little additional mathematical substance.

  3. Token clustering. When tokens are constrained to the unit sphere, the interaction energy is maximized by Dirac measures, corresponding to complete token alignment. The gradient-flow structure provides a Lyapunov function and allows the use of dynamical-systems tools to establish convergence to clustered configurations under suitable assumptions.