Search

Search papers and lessons

Deep Neural Networks as Gaussian Processes

Jaehoon Lee, Yasaman Bahri, Roman Novak et al. · 2017

Lee and colleagues showed that a deep fully connected network with random weights becomes a Gaussian process as its width grows, with a kernel computed layer by layer, so Bayesian regression with it is exact.

On this page

  • Colour = topic mix
  • Probability
  • Linear algebra
  • Discrete math
  • Neural network basics
  • Calculus
  • Inference
  • ReadReady to readNot yet

TL;DR

A fully connected neural network with random weights computes a random function. Lee and colleagues showed that when every hidden layer is made infinitely wide, that random function becomes a Gaussian process, and they gave a recipe that computes its covariance (the kernel) one layer at a time. With that kernel, predicting new values is exact Bayesian regression, done with matrix algebra and no gradient training. On MNIST and CIFAR-10 the resulting Gaussian processes often matched or beat trained networks, and they gave an uncertainty estimate for every prediction.

Builds on: Gaussian Process Regression, Central Limit Theorem, Feedforward Neural Network · Leads to: Neural Tangent Kernel: Convergence and Generalization in Neural Networks, Bayesian Neural Network

Why it mattered

The equivalence was not new for a single hidden layer. Radford Neal had shown it in 1994, and Christopher Williams gave closed-form kernels for one-layer networks in 1997. The paper's contribution was the deep case, and it made the result usable. For a deep network, the kernel can be computed for any reasonable activation function, and the resulting Gaussian process is used for real prediction on image benchmarks, not just as a theory object.

The paper's numbers are the reason people kept reading it. The best Gaussian process on CIFAR-10 with 45,000 training images reached 0.5566 test accuracy with a ReLU kernel, above the best trained network at 0.5313 (Table 1 of the paper). The Gaussian process also reported an uncertainty for each test point, and that uncertainty tracked the actual error on those points (Figure 3). Later work on infinitely wide networks, including Neural Tangent Kernel: Convergence and Generalization in Neural Networks, built on the same idea that a wide network can be analysed as a kernel method.

The problem

Before this paper, a network trained by gradient descent had no tractable Bayesian treatment. Placing a prior over its weights and asking for the posterior over its outputs requires integrating over millions of parameters. A Gaussian process is different: it gives a prior over functions directly, and conditioning it on data is a short matrix calculation (see Gaussian Process Regression). So if a deep network could be shown to be a Gaussian process, Bayesian prediction would come for free.

Two things were missing. First, nobody had shown that the equivalence held for a deep stack of layers, where each layer's output feeds the next nonlinearity. Second, the kernels that existed for deep networks, such as the compositional kernels of Cho and Saul (2009) and Daniely and colleagues (2016), had been derived outside a Bayesian framework. They were not used as covariance functions of a Gaussian process for prediction. Deep Gaussian processes, which stack GPs, were a different object again: they are not the limit of a neural network.

How it works

The idea has two steps: a central limit argument for one layer, then an induction over layers. The walkthrough below uses one tiny instance, with two inputs in two dimensions and a ReLU activation.

  1. Set up the network. Take inputs x∈Rdinx \in \mathbb{R}^{d_{\text{in}}}. Each hidden unit computes a weighted sum of the previous layer's activations plus a bias, then applies a nonlinearity ϕ\phi. Draw every weight and bias at random, with weight variance σw2/N\sigma_w^2 / N (where NN is the layer width) and bias variance σb2\sigma_b^2. Check: with NN units feeding one output, each weight is small when the layer is wide.
  2. Let the width grow. One output of a layer is a sum of NN independent terms, so by the central limit theorem it becomes Gaussian as NN grows. Several inputs together give a joint Gaussian, which is exactly the definition of a Gaussian process. Check: the output at one input is a sum of many independent random pieces, the situation the theorem covers.
  3. Pass the covariance up one layer. The covariance of the next layer depends only on the covariance of the current one, through a fixed function. Tiny instance: take x=(1,0)x = (1, 0) and x′=(0,1)x' = (0, 1), with din=2d_{\text{in}} = 2, σw2=2\sigma_w^2 = 2, σb2=0\sigma_b^2 = 0, and ReLU. The input covariance is K0(x,x′)=σw2 x⋅x′/din=0K^0(x, x') = \sigma_w^2 \, x \cdot x' / d_{\text{in}} = 0, and K0(x,x)=K0(x′,x′)=2⋅1/2=1K^0(x, x) = K^0(x', x') = 2 \cdot 1 / 2 = 1. Check: the two inputs are orthogonal, so their covariance is zero.
  4. Compute the next layer. The first hidden layer's pre-activations at the two inputs are independent Gaussians with variance 1. Their ReLU outputs have mean 1/2π1/\sqrt{2\pi} each, so K1(x,x′)=2⋅(1/2π)2=1/π≈0.318K^1(x, x') = 2 \cdot (1/\sqrt{2\pi})^2 = 1/\pi \approx 0.318. Check: the covariance is no longer zero, so the nonlinearity has created a link between the inputs.
  5. Repeat for every layer. Each layer's kernel is computed from the previous one, giving KLK^L. The network's output, at any set of inputs, is then a Gaussian process with covariance KLK^L.
  6. Predict. Condition the Gaussian process on training data with the standard GP regression formulas. For a test input, this gives a predicted mean and a predicted variance, which is the Bayesian answer for the infinitely wide network.
flowchart LR
  A[Inputs] --> B[Base kernel from inner products]
  B --> C[Layer kernel from previous layer]
  C --> D[Repeat for each layer]
  D --> E[Output kernel K at depth L]
  E --> F[GP regression on training data]
  F --> G[Mean and uncertainty at test inputs]

Two practical points follow from the walkthrough. The recursion is deterministic and differentiable, so the kernel depends only on the architecture and the variances σw2\sigma_w^2 and σb2\sigma_b^2. And for some nonlinearities, such as ReLU, step 4 has a closed form; for others, the paper computes it numerically with a lookup table.

The math

Definition: Neural network Gaussian process (NNGP)

A neural network Gaussian process is the distribution over functions ff that a fully connected network defines when its weights and biases are drawn independently from zero-mean Gaussians and every hidden layer width goes to infinity. For any finite set of inputs, the vector of outputs is multivariate Gaussian with mean zero and covariance KLK^L, where KLK^L is built by the recursion below.

Steps 1 and 2 in symbols

Write the network with pre-activations zilz^l_i and post-activations xil=ϕ(zil−1)x^l_i = \phi(z^{l-1}_i). The layer map is

zil(x)=bil+∑j=1NlWijl ϕ(zjl−1(x)),z^{l}_{i}(x) = b^{l}_{i} + \sum_{j=1}^{N_l} W^{l}_{ij}\, \phi\big(z^{l-1}_{j}(x)\big),

with WijlW^l_{ij} drawn from a zero-mean Gaussian of variance σw2/Nl\sigma_w^2 / N_l and bilb^l_i from one of variance σb2\sigma_b^2. Here NlN_l is the width of layer ll, and ϕ\phi is the activation applied to each unit.

Since the WijlW^l_{ij} and bilb^l_i are independent across jj, the sum has NlN_l independent terms. As Nl→∞N_l \to \infty the central limit theorem makes zil(x)z^l_i(x) Gaussian, and jointly Gaussian across inputs. The covariance it has is

Kl(x,x′)=σb2+σw2 E[ϕ(u) ϕ(v)],K^{l}(x, x') = \sigma_b^2 + \sigma_w^2 \, \mathbb{E}\big[\phi(u)\,\phi(v)\big],

where (u,v)(u, v) is zero-mean Gaussian with variances Kl−1(x,x)K^{l-1}(x,x) and Kl−1(x′,x′)K^{l-1}(x',x') and covariance Kl−1(x,x′)K^{l-1}(x,x').

Step 3 in symbols: the recursion

Write FϕF_\phi for the expectation in step 2, so that

Kl(x,x′)=σb2+σw2 Fϕ(Kl−1(x,x′), Kl−1(x,x), Kl−1(x′,x′)).K^{l}(x, x') = \sigma_b^2 + \sigma_w^2 \, F_\phi\big(K^{l-1}(x,x'),\, K^{l-1}(x,x),\, K^{l-1}(x',x')\big).

The base case uses the input inner product:

K0(x,x′)=σb2+σw2 x⋅x′din.K^{0}(x, x') = \sigma_b^2 + \sigma_w^2 \, \frac{x \cdot x'}{d_{\text{in}}}.

Step 4 in symbols: the ReLU closed form

For ReLU, ϕ(z)=max⁡(0,z)\phi(z) = \max(0, z), the expectation has a closed form, the arc-cosine kernel. With θl−1=arccos⁡ ⁣(Kl−1(x,x′)/Kl−1(x,x) Kl−1(x′,x′))\theta^{l-1} = \arccos\!\big(K^{l-1}(x,x') / \sqrt{K^{l-1}(x,x)\,K^{l-1}(x',x')}\big),

Kl(x,x′)=σb2+σw22πKl−1(x,x) Kl−1(x′,x′) (sin⁡θl−1+(π−θl−1)cos⁡θl−1).K^{l}(x, x') = \sigma_b^2 + \frac{\sigma_w^2}{2\pi} \sqrt{K^{l-1}(x,x)\,K^{l-1}(x',x')}\,\Big(\sin\theta^{l-1} + (\pi - \theta^{l-1})\cos\theta^{l-1}\Big).
Example
Example 1: the ReLU kernel for two identical inputs

Take x=x′=(1,0)x = x' = (1, 0), din=2d_{\text{in}} = 2, σw2=2\sigma_w^2 = 2, σb2=0\sigma_b^2 = 0. Then K0(x,x)=2⋅1/2=1K^0(x,x) = 2 \cdot 1 / 2 = 1.

  1. The inputs are identical, so K0(x,x′)=1K^0(x,x') = 1 and the cosine ratio is 11.
  2. So θ0=arccos⁡(1)=0\theta^0 = \arccos(1) = 0.
  3. Then sin⁡0=0\sin 0 = 0 and cos⁡0=1\cos 0 = 1, so the bracket is 0+(π−0)⋅1=π0 + (\pi - 0) \cdot 1 = \pi.
  4. The prefactor is 22π⋅1⋅1=1π\frac{2}{2\pi} \cdot \sqrt{1 \cdot 1} = \frac{1}{\pi}.
  5. Multiply: K1(x,x)=1π⋅π=1K^1(x,x) = \frac{1}{\pi} \cdot \pi = 1.

Interpretation: a ReLU layer with these variances keeps the squared norm of the input unchanged, so the diagonal of the kernel stays at 1.

Step 6 in symbols: the posterior

Let D\mathcal{D} be the training inputs xx with targets tt, and let the observation noise have variance σϵ2\sigma_\epsilon^2. Write KDDK_{\mathcal{D}\mathcal{D}} for the training-by-training kernel matrix and K∗DK_{*\mathcal{D}} for the row of test-to-training kernel values. Then the predictive distribution at a test input is Gaussian with

μˉ=K∗D(KDD+σϵ2In)−1t,Kˉ=K∗∗−K∗D(KDD+σϵ2In)−1K∗DT.\bar{\mu} = K_{*\mathcal{D}} \big(K_{\mathcal{D}\mathcal{D}} + \sigma_\epsilon^2 \mathbf{I}_n\big)^{-1} t, \qquad \bar{K} = K_{**} - K_{*\mathcal{D}} \big(K_{\mathcal{D}\mathcal{D}} + \sigma_\epsilon^2 \mathbf{I}_n\big)^{-1} K_{*\mathcal{D}}^{T}.

These are the same formulas as in Gaussian Process Regression, with the kernel KLK^L of the deep network in place of a hand-picked one.

Example
Example 2: one training point

Suppose there is one training input with KDD=2K_{\mathcal{D}\mathcal{D}} = 2, a test input with K∗∗=2K_{**} = 2 and K∗D=1K_{*\mathcal{D}} = 1, noise σϵ2=1\sigma_\epsilon^2 = 1, and target t=3t = 3.

  1. The denominator is KDD+σϵ2=2+1=3K_{\mathcal{D}\mathcal{D}} + \sigma_\epsilon^2 = 2 + 1 = 3.
  2. The mean is μˉ=1⋅3/3=1\bar{\mu} = 1 \cdot 3 / 3 = 1.
  3. The variance is Kˉ=2−1⋅1/3=5/3≈1.67\bar{K} = 2 - 1 \cdot 1 / 3 = 5/3 \approx 1.67.

Interpretation: the prediction moves from the prior mean 0 to 1, which is a third of the way toward the target 3, because the noise variance of 1 is as large as the training kernel value and pulls the fit back. The variance drops from 2 to about 1.67, so the training point helps only a little.

Step 5 in symbols: depth

Applying the recursion LL times gives KLK^L, the covariance of the network's output. Appendix C of the paper derives the same kernel by a different route, marginalising over the intermediate layers, and notes that the result does not depend on the order in which the widths go to infinity when the weights have Gaussian priors.

Results

Setup. The paper compares the NNGP with fully connected networks trained by gradient methods on MNIST and CIFAR-10. Training used mean squared error against one-hot targets, with the zero-mean encoding of −0.1-0.1 for wrong classes and 0.90.9 for the right class. The networks were trained with the Adam optimizer (Adam Optimizer, a variant of Stochastic Gradient Descent) and no dropout (Dropout). Their hyperparameters were chosen by random search, averaging about 250 trials for each choice of training size, depth, width and nonlinearity, and the Gaussian process hyperparameters were chosen from a grid of 900 points. MNIST used a 50,000/10,000/10,000 split (training, validation, test), and CIFAR-10 used 45,000/5,000/10,000.

Table 1 (selected rows, test accuracy). For the ReLU kernel:

Training setBest NNGPBest trained network
MNIST, 1k0.92790.9252
MNIST, 50k0.98750.9864
CIFAR-10, 10k0.47800.4545
CIFAR-10, 45k0.55660.5313

The paper's notation for the best settings is depth-width-σw2\sigma_w^2-σb2\sigma_b^2 for networks and depth-σw2\sigma_w^2-σb2\sigma_b^2 for Gaussian processes. The tanh columns follow the same pattern: the NNGP is ahead in all six tanh rows of the table, and in five of the six ReLU rows (the exception is MNIST with 10k training images, where the trained network leads, 0.9771 against 0.9765).

Uncertainty. The predicted variance Kˉ\bar{K} at each test point was strongly correlated with the realised squared error (Figure 3), so the uncertainty is informative about where the model is wrong.

Width. Among 180 five-hidden-layer networks on CIFAR-10 (125 tanh and 55 ReLU after filtering for full training accuracy), the best generalising networks were consistently the widest (Figure 2). These networks were trained with cross entropy rather than MSE, so the comparison is not a like-for-like replay of the main experiments. Finite networks trained with SGD moved toward the NNGP result as width grew.

Depth and signal propagation. The paper connects performance to the way a random network's kernel changes with depth. For tanh there are two regimes, called ordered and chaotic, separated by a critical line in (σw2,σb2)(\sigma_w^2, \sigma_b^2) space. Near that line the kernel decays slowly with depth, and the NNGP performed best there (Figure 4). Far from it, the kernel converges to a constant, and the information in the data survives only as a tiny difference that can be lost to numerical precision at large depth.

Limits and misreadings

  • It is a limit, not the same model. A finite network is not a Gaussian process. The paper's evidence is that finite networks approach the NNGP as width grows, which is a different claim from "every deep network is a GP".
  • It is not learned features. The NNGP uses fixed basis functions set by the architecture and two variances. The paper notes that it found no salient advantage for learned features on these tasks, which is a surprising empirical observation and not a general law.
  • It is regression. Classification was treated as least-squares regression on labels. The paper notes that Gaussian processes can be extended to softmax classification with cross entropy, and leaves that to future work.
  • Cost. The posterior needs solving with an n×nn \times n matrix, where nn is the training set size, so the cost grows fast with data. The paper handled 50,000 points and names scaling to larger data as future work.
  • Open question. Whether SGD approximately implements Bayesian inference is left open by the paper.

Reading guide

  1. Introduction (section 1). Needs Central Limit Theorem and a Feedforward Neural Network. The contrast drawn with deep Gaussian processes needs no more.
  2. Section 2.1 and 2.2 (notation and the one-layer case). Needs Multivariate Gaussian and the kernel form of Gaussian Process Regression. The notation σw2\sigma_w^2 and σb2\sigma_b^2 is the variance of the weights and biases.
  3. Section 2.3 (induction over layers). Needs Kernel Function and Activation Function. The recursion in the math section above is equation 5.
  4. Section 2.4 (Bayesian training). Needs Posterior Distribution and the posterior formulas in Gaussian Process Regression.
  5. Section 2.5 (efficient implementation). Needs Cholesky Decomposition for the linear solves and Rectified Linear Unit (ReLU) for the closed form. The lookup table is a numerical integration.
  6. Section 3 (experiments). Needs Mean Squared Error and the training ideas in Stochastic Gradient Descent and Adam Optimizer.
  7. Section 3.2 and Appendix B. Need the idea of a fixed point of a recursion: a value the kernel approaches as depth grows. Appendix B gives the closed form of the ReLU step used in the math section above.

Check yourself

QuestionRecall: what does the central limit theorem contribute to the NNGP argument?Show answer

Each unit's output in a layer is a sum of many independent terms, one per unit of the previous layer. As the width goes to infinity, the central limit theorem makes that sum Gaussian, and the joint distribution across several inputs is Gaussian too. That joint Gaussian is the definition of a Gaussian process, so the network's function is a draw from a GP.

QuestionComputation: with one training point, KDD=4K_{\mathcal{D}\mathcal{D}} = 4, K∗D=2K_{*\mathcal{D}} = 2, K∗∗=4K_{**} = 4, σϵ2=0\sigma_\epsilon^2 = 0 and target t=2t = 2, what is the predictive mean?Show answer

With no noise, the denominator is just KDD=4K_{\mathcal{D}\mathcal{D}} = 4. The mean is μˉ=K∗D⋅t/KDD=2⋅2/4=1\bar{\mu} = K_{*\mathcal{D}} \cdot t / K_{\mathcal{D}\mathcal{D}} = 2 \cdot 2 / 4 = 1. The variance is Kˉ=4−2⋅2/4=3\bar{K} = 4 - 2 \cdot 2 / 4 = 3. Answer: the mean is 1.

QuestionWhy: in the tiny ReLU example, why is K1(x,x′)=1/πK^1(x,x') = 1/\pi rather than zero even though K0(x,x′)=0K^0(x,x') = 0?Show answer

The zero covariance at the input means the two first-layer pre-activations are independent. But ReLU outputs are never negative, so each has a positive mean, 1/2π1/\sqrt{2\pi}. The next layer's pre-activations are weighted sums of these outputs, and the covariance is the uncentred product σw2 E[ϕ(u)ϕ(v)]=2⋅(1/2π)2=1/π\sigma_w^2 \, \mathbb{E}[\phi(u)\phi(v)] = 2 \cdot (1/\sqrt{2\pi})^2 = 1/\pi. Independence at one layer does not stop the next layer from being correlated, because the nonzero mean of the activations is shared.

QuestionApplied: a researcher uses the NNGP for a dataset where the predicted variance is large for a set of test points. What does that tell them?Show answer

The model is uncertain about those points given its prior and the training data. The paper found that this predicted variance correlates with the realised error, so those points are the ones most likely to be wrong, and they are candidates for a new label in active learning. The uncertainty does not say the model is correct about the points where it is confident, and it depends on the prior chosen through σw2\sigma_w^2, σb2\sigma_b^2 and depth.

Sources

Read the full paper

Jaehoon Lee, Yasaman Bahri, Roman Novak et al., 2017. arXiv:1711.00165