# Shallow neural networks as Wasserstein gradient flows

## Motivation

Artificial neural networks (ANNs) consist of layers of artificial "neurons" which take in information from the previous layer and output information to neurons in the next layer. Gradient descent is a common method for updating the weights of each neuron based on training data. While in practice every layer of a neural network has only finitely many neurons, it is beneficial to consider a neural network layer with infinitely many neurons, for the sake of developing a theory that explains how ANNs work. In particular, from this viewpoint the process of updating the neuron weights for a shallow neural network can be described by a Wasserstein gradient flow.

## Single Layer Neural Networks

### Discrete Formulation

Let us introduce the mathematical framework and notation for a neural network with a single hidden layer. Let $D\subset \mathbb {R} ^{d}$ be open . The set $D$ represents the space of inputs into the network. There is some unknown function $f:D\rightarrow \mathbb {R}$ which we would like to approximate. Let $N\in \mathbb {N}$ be the number of neurons in the hidden layer. Define

$F_{N}:D\times \Omega ^{N}\rightarrow \mathbb {R} ^{k}$ be given by

$F_{N}(x,\omega _{1},\dots ,\omega _{N},\theta _{1},\dots ,\theta _{N})={\frac {1}{N}}\sum _{i=1}^{N}\omega _{i}h(\theta _{i},x)$ where $h$ is a fixed activation function and $\Omega ^{N}$ is a space of possible parameters $(\omega ,\theta )=(\omega _{1},\dots ,\omega _{N},\theta _{1},\dots ,\theta _{N})$ . The goal is to use training data to repeatedly update the weights $\omega _{i}$ and $\theta _{i}$ based on how close $f_{N,\omega ,\theta }:=F_{N}(\cdot ,\omega _{1},\dots ,\omega _{N},\theta _{1},\dots ,\theta _{N})$ is to the function $f$ . More concretely, we want to find $\omega ,\theta$ that minimizes the loss function:

$l(f,f_{N,\omega ,\theta }):={\frac {1}{2}}\int _{D}|f(x)-f_{N,\omega ,\theta }(x)|^{2}dx$ A standard way to choose and update the weights is to start with a random choice of weights ${\bar {\omega }},{\bar {\theta }}$ and perform gradient descent on these parameters. Unfortunately, this problem is non-convex, so the minimizer may not be achieved. It turns out in practice, neural networks are surprisingly good at finding the minimizer. A nicer minimization problem that may provide insight into how neural networks work is a neural network model with infinitely many neurons.

### Continuous Formulation

For the continuous formulation (i.e. when $N=\infty$ ), we rephrase the above mathematical framework. In this case, it no longer makes sense to look for weights $\omega ,\theta$ that minimize the loss function. We instead look for a probability measure $\mu \in {\mathcal {P}}(\Omega )$ such that

$f_{\mu }(x):=\int _{\Omega }\Phi (\xi ,x)d\mu (\xi )$ minimizes the loss function:

$F(\mu ):={\frac {1}{2}}\int _{D}(f-f_{\mu })^{2}dx$ .

Here $\Phi (\xi ,x)$ is an activation function with parameter $\xi =(\omega ,\theta )\in \Omega$ . We will in fact restrict choices of $\mu$ to probability measures with finite second moment, denoted ${\mathcal {P}}_{2}(\Omega )$ . This is a small technicality to ensure that the Wasserstein metric is indeed a metric.

Note that by restricting choices of $\mu$ to probability measures of the form $\mu _{N}={\frac {1}{N}}\sum _{i=1}^{N}\delta _{\xi _{i}}$ , the above minimization problem generalizes to case with finitely many neurons as well.

To avoid overfitting the network to the training data, a potential term is added the loss function. For the remainder of this article, we define the loss function $F$ to be:

$F(\mu ):={\frac {1}{2}}\int _{D}(f-(\int _{\Omega }\Phi (\xi ,x)d\mu (\xi )))^{2}dx+\int _{\Omega }V(\xi )d\mu (\xi )$ for a convex potential function $V:\Omega \rightarrow \mathbb {R}$ . Often we choose $V(\xi )={\frac {\lambda }{2}}|\xi |^{2}$ . In fact, $F$ is convex (along linear interpolations), in contrast to the minimization function in the finite neuron case.

When $X\subseteq \mathbb {R} ^{n}$ , the gradient flow of a differentiable function $g:X\rightarrow \mathbb {R}$ starting at a point $x_{0}$ is a curve $x(t):[0,T)\rightarrow X$ satisfying the differential equation

${\frac {d}{dt}}x(t)=-\nabla g(x(t)),x(0)=x_{0}$ .

where $\nabla g$ is the gradient of g.

Crucially, the gradient flow heads in the direction that decreases the value of $g$ the fastest. We would like to use this nice property of gradient flow in our setting with the functional $F$ . However, it is not immediately straightforward how to do this, since $F$ is defined on the space of probability measures, rather than on $\mathbb {R} ^{n}$ , so the usual gradient is not defined. Before we generalize the notion of gradient flow, recall that $\nabla g$ is the unique function from $\mathbb {R} ^{n}$ to $\mathbb {R} ^{n}$ such that

$\langle \nabla g,v\rangle =D_{v}g$ ,

where $D_{v}g$ is the directional derivative of $g$ in the direction $v$ . Motivated by this and using the Riemannian structure of the space of probability measures, we can define the a notion of gradient for our loss functional $F$ .

Note that one can define gradient flows in a general Hilbert space.

We are looking for an element $\nabla _{W_{2}}F(\mu )$ in the tangent space of ${\mathcal {P}}_{2}(\Omega )$ at $\mu$ such that

$\langle \nabla _{W_{2}}F(\mu _{*}),{\frac {d}{dt}}\mu (t)|_{t=0}\rangle _{W_{2}}=\lim _{h\rightarrow 0}{\frac {F(\mu (h))-F(\mu _{*})}{h}}$ for any absolutely continuous curve $\mu (t)$ in ${\mathcal {P}}_{2}(\Omega )$ with $\mu (0)=\mu _{*}$ .

We claim that in fact

$\nabla _{W_{2}}F(\mu _{*})=-\nabla \cdot (\mu _{*}\nabla {\frac {\delta F}{\delta \mu _{*}}})$ where ${\frac {\delta F}{\delta \mu _{*}}}$ is the first variation of $F$ at $\mu _{*}$ (also called the functional derivative).

We provide a formal argument for this equality that makes the most sense when $\mu$ is absolutely continuous with respect to the Lebesgue measure. In this case, we can think of $\mu$ as a density function with $d\mu (x)=\mu (x)dx$ . We can further assume that $\mu$ is in $L^{2}(\Omega )$ . Therefore the same notion of gradient for $L^{2}$ exists for $F$ , and in fact

$\nabla _{L^{2}}F(\mu )={\frac {\delta F}{\delta \mu }}$ Thus by definition of $L^{2}$ gradient and $L^{2}$ inner product, we should have

$\lim _{h\rightarrow 0}{\frac {F(\mu (h))-F(\mu _{*})}{h}}=\langle {\frac {\delta F}{\delta \mu _{*}}},{\frac {d}{dt}}\mu (t)|_{t=0}\rangle _{L^{2}}$ $=\int {\frac {\delta F}{\delta \mu _{*}}}{\frac {d}{dt}}\mu (t)|_{t=0}dx$ by the continuity equation for $\mu (t)$ and divergence theorem,

$\int {\frac {\delta F}{\delta \mu _{*}}}{\frac {d}{dt}}\mu (t)|_{t=0}dx=-\int {\frac {\delta F}{\delta \mu _{*}}}(\nabla \cdot (v_{*}\mu _{*}))dx=\int \nabla {\frac {\delta F}{\delta \mu _{*}}}(v_{*}\mu _{*})dx=\int \nabla {\frac {\delta F}{\delta \mu _{*}}}v_{*}d\mu _{*}$ where $v_{*}$ is the unique velocity vector corresponding to $\mu _{*}$ by the equivalence of absolutely continuous curves and solutions of the continuity equation. Now by the definition of the inner product structure of $({\mathcal {P}}_{2}(\mathbb {R} ^{d}),W_{2})$ , we have

$\int \nabla {\frac {\delta F}{\delta \mu _{*}}}v_{*}d\mu _{*}=\langle -\nabla \cdot (\mu \nabla {\frac {\delta F}{\delta \mu _{*}}}),{\frac {d}{dt}}\mu (t)|_{t=0}\rangle _{W_{2}}.$ Therefore we have

$\nabla _{W_{2}}F(\mu _{*})=-\nabla \cdot (\mu \nabla {\frac {\delta F}{\delta \mu _{*}}}).$ so the gradient flow for $F$ is an absolutely continuous curve of probability measure $\mu _{t}$ such that

$\partial _{t}\mu _{t}=\nabla \cdot (\mu _{t}\nabla {\frac {\delta F}{\delta \mu _{t}}})$ .

Now we actually compute this gradient flow for our loss functional $F$ .

### Computing the Wasserstein Gradient Flow for F

First, we compute the first variation ( or functional derivative) of a function from ${\mathcal {P}}(\Omega )$ to $\mathbb {R}$ of $F$ ${\frac {\delta F}{\delta \mu }}(\mu _{*})=\int _{D}\Phi (\cdot ,x)[\int _{\Omega }\Phi ({\bar {\xi }},x)d\mu _{*}({\bar {xi}})-f(x)]dx+V$ Therefore we have

$\nabla {\frac {\delta F}{\delta \mu }}(\mu _{*})=\int _{D}\nabla _{\xi }\Phi (\cdot ,x)[\int _{\Omega }\Phi ({\bar {\xi }},x)d\mu _{*}({\bar {xi}})-f(x)]dx+\nabla V.$ Hence the Wasserstein gradient flow is

$\partial _{t}\mu _{t}={\rm {{div}(\mu _{t}\nabla {\frac {\delta F}{\delta \mu }}(\mu _{t}))}}$ .

## Open Problems

### Generalization

Generalization error is how well a model generalizes for a new data not in your training data set. In practice, gradient descent does generalize really well, but it is an open problem to provide a theoretical framework to guarantee generalization. Wang, Meng, Chen and Liu 2021 made progress on studying the implicit regularization of the algorithm, and provide a framework for convergence.