Search

Search papers and lessons

Deep Kernel Learning

Andrew Gordon Wilson, Zhiting Hu, Ruslan Salakhutdinov et al. · 2015

Deep kernel learning feeds inputs through a neural network before a spectral mixture kernel, then trains the network and kernel jointly through the Gaussian process marginal likelihood.

On this page

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

TL;DR

Deep kernel learning combines a Gaussian process with a deep network. The network first maps each input to a learned feature vector, and a kernel then compares those features, so the model's notion of similarity is learned. The network weights and the kernel parameters are trained together by maximising the Gaussian process marginal likelihood, and scalable approximations let the model run on data with up to two million examples.

Builds on: Gaussian Process Regression, Marginal Likelihood, Feedforward Neural Network, Spectral Mixture Kernel · Leads to: Bayesian Optimization, which needs calibrated uncertainty from the same kind of model

Why it mattered

Gaussian processes give calibrated uncertainty, but a standard kernel on raw pixels measures similarity poorly, and exact inference costs time that grows with the cube of the number of training points. Deep networks learn good features, but they give point predictions with no principled error bar. This paper showed that the two can be combined in a single closed-form model, trained by one objective, and scaled to large data. Its experiments include face orientation from image patches and regression on about two million rows, where the model beat stand-alone deep networks on the same architectures.

The problem

A Gaussian process is defined by a mean and a kernel. The kernel says how strongly two inputs should move together. Standard kernels such as the radial basis function (RBF) measure distance in the raw input space, so two images of faces at similar angles can look far apart if their pixels differ. Learning better kernels had been tried with hand-designed families, but those families still rely on Euclidean distance.

Two costs also limit the classical model. Exact inference solves a linear system with an n×nn \times n matrix, which takes time of order n3n^3 and storage of order n2n^2. The paper's aim is a model that keeps the non-parametric flexibility of a Gaussian process, scales linearly in nn, and learns the kernel's inputs from data rather than fixing them.

How it works

The model is a pipeline: transform the inputs, apply a base kernel, build the covariance matrix, and score the result by the marginal likelihood. Here is one tiny instance with a one-number input and a network that is just a scaling, so the effect of learning is easy to see.

  1. Start with a raw input. Take the input x=1x = 1. The network is g(x,w)=wxg(x, w) = w x, a single weight ww. Check: with w=2w = 2 the network maps 1 to 2.
  2. Map the inputs to features. Map two inputs, x=0x = 0 and x=1x = 1, through the network. With w=2w = 2 they become g=0g = 0 and g=2g = 2. Check: the features are two numbers, and the gap between them is 2.
  3. Apply the base kernel to the features. Use the RBF base kernel with length scale 1, k(u,v)=exp⁡(−(u−v)2/2)k(u, v) = \exp(-(u - v)^2/2). The kernel value between the two features is exp⁡(−4/2)=exp⁡(−2)≈0.135\exp(-4/2) = \exp(-2) \approx 0.135. Check: the inputs are only weakly related because their features are far apart.
  4. Change the weight and recompute. With w=0.5w = 0.5 the features become 00 and 0.50.5. The kernel is exp⁡(−0.25/2)=exp⁡(−0.125)≈0.883\exp(-0.25/2) = \exp(-0.125) \approx 0.883. Check: the same raw inputs are now strongly related. The network changed the metric without changing the kernel.
  5. Score the weight. The marginal likelihood says how well each weight explains the observed targets, with a penalty for complexity. Gradient descent moves ww toward the value that scores best. Check: this step is the one that makes the features learnable, and it is where the paper's joint training happens.

The figure below shows the whole pipeline and where the approximation enters.

flowchart LR
  X[Raw inputs x] --> N[Deep network g x w]
  N --> B[Spectral mixture base kernel on features]
  B --> I[Inducing grid with local interpolation M]
  I --> C[Covariance K approximately M K_UU M transpose]
  C --> L[Log marginal likelihood]
  L --> U[Update network weights w and kernel parameters theta]
  U --> N

The paper trains in three stages. It first trains a deep network with ordinary stochastic gradient descent on a squared loss, then fits a scalable Gaussian process on the network's top-layer features, and finally trains everything jointly through the marginal likelihood. The joint stage is what makes it a single model.

The math

Definition

Let k(x,x′∣θ)k(\mathbf{x}, \mathbf{x}' \mid \boldsymbol{\theta}) be a base kernel with hyperparameters θ\boldsymbol{\theta}, and let g(x,w)g(\mathbf{x}, \mathbf{w}) be a deep network with weights w\mathbf{w}. The deep kernel is

kdeep(x,x′)=k(g(x,w), g(x′,w) ∣ θ).k_{\text{deep}}(\mathbf{x}, \mathbf{x}') = k\big(g(\mathbf{x}, \mathbf{w}),\, g(\mathbf{x}', \mathbf{w}) \,\big|\, \boldsymbol{\theta}\big).

All trainable parameters are γ={w,θ}\boldsymbol{\gamma} = \{\mathbf{w}, \boldsymbol{\theta}\}.

Step 1 in symbols: transform the inputs

The network replaces the raw input by a feature vector g(x,w)g(\mathbf{x}, \mathbf{w}). In the walkthrough this was g(x,w)=wxg(x, w) = wx. The base kernel is then applied to features, not inputs, so every weight in the network changes the metric the kernel uses.

Step 2 in symbols: the spectral mixture base kernel

The paper uses a spectral mixture base kernel with QQ components:

kSM(x,x′)=∑q=1Qaq ∣Σq∣1/2(2π)D/2exp⁡ ⁣(−12∥Σq1/2(x−x′)∥2)cos⁡(2π μqT(x−x′)).k_{\text{SM}}(\mathbf{x}, \mathbf{x}') = \sum_{q=1}^{Q} a_q\, \frac{|\Sigma_q|^{1/2}}{(2\pi)^{D/2}} \exp\!\Big(-\tfrac{1}{2}\big\|\Sigma_q^{1/2}(\mathbf{x} - \mathbf{x}')\big\|^2\Big) \cos\big(2\pi\, \boldsymbol{\mu}_q^{T}(\mathbf{x} - \mathbf{x}')\big).

Here aqa_q is the mixture weight, Σq\Sigma_q holds the bandwidths (inverse length scales), and μq\boldsymbol{\mu}_q holds the frequencies. The Gaussian envelope and the cosine are the ones from Spectral Mixture Kernel. The normalising factor is a constant that the paper keeps for completeness.

Step 3 in symbols: the Gaussian process prediction

Given training data and noise variance σ2\sigma^2, the predictive mean and covariance at test inputs X∗X_* are

E[f∗]=μX∗+KX∗,X [KX,X+σ2I]−1y,\mathbb{E}[\mathbf{f}_*] = \boldsymbol{\mu}_{X_*} + K_{X_*,X}\,[K_{X,X} + \sigma^2 I]^{-1}\mathbf{y}, cov⁡(f∗)=KX∗,X∗−KX∗,X [KX,X+σ2I]−1KX,X∗.\operatorname{cov}(\mathbf{f}_*) = K_{X_*,X_*} - K_{X_*,X}\,[K_{X,X} + \sigma^2 I]^{-1}K_{X,X_*}.

Every KK is built from the deep kernel, so the network enters the prediction through the matrices. This is the form from Gaussian Process Regression.

Step 4 in symbols: the marginal likelihood

The log marginal likelihood, up to the constant term the paper omits, is

log⁡p(y∣γ,X)=−12 yT(Kγ+σ2I)−1y−12log⁡∣Kγ+σ2I∣+const.\log p(\mathbf{y} \mid \boldsymbol{\gamma}, X) = -\tfrac{1}{2}\,\mathbf{y}^{T}(K_{\boldsymbol{\gamma}} + \sigma^2 I)^{-1}\mathbf{y} - \tfrac{1}{2}\log\big|K_{\boldsymbol{\gamma}} + \sigma^2 I\big| + \text{const}.

The first term rewards fitting the data. The second penalises complexity, which is why the paper says the model's complexity is calibrated automatically, without a separate regulariser.

Step 5 in symbols: joint training and the approximation

Training maximises the log marginal likelihood with respect to γ\boldsymbol{\gamma}. The derivative with respect to the data covariance is ∂L/∂K=12(K−1yyTK−1−K−1)\partial\mathcal{L}/\partial K = \tfrac{1}{2}(K^{-1}\mathbf{y}\mathbf{y}^T K^{-1} - K^{-1}), and the chain rule carries it back through the kernel into the network by backpropagation.

For scale, the paper replaces KγK_{\boldsymbol{\gamma}} by KKISS=MKU,UdeepMTK_{\text{KISS}} = M K^{\text{deep}}_{U,U} M^{T}. Here UU is a grid of mm inducing points in feature space, MM is a sparse interpolation matrix with 4 nonzero entries per row, and KU,UK_{U,U} is a Kronecker product of Toeplitz matrices. Matrix-vector products with that structure are fast, so the solves use conjugate gradients rather than a Cholesky factor. The paper reports training cost of order n+h(m)n + h(m) and prediction cost of order 1 per test point after training.

Worked examples

Example
1. One weight, two points (tiny)
  1. Network g(x,w)=wxg(x, w) = wx with w=0.5w = 0.5. Inputs x=0x = 0 and x=1x = 1 give features 00 and 0.50.5.
  2. Base kernel: k(u,v)=exp⁡(−(u−v)2/2)k(u, v) = \exp(-(u - v)^2/2). The feature gap is 0.50.5.
  3. Kernel value: exp⁡(−0.25/2)=exp⁡(−0.125)≈0.883\exp(-0.25/2) = \exp(-0.125) \approx 0.883.
  4. Compare with the raw inputs, which have gap 1: exp⁡(−1/2)≈0.607\exp(-1/2) \approx 0.607.
  5. Interpretation: the network moved the two inputs closer in feature space, so the deep kernel treats them as more related than the plain kernel does.
Example
2. A two-point Gaussian process prediction (standard case)

Use the same network and kernel, with w=0.5w = 0.5, so the features of the training inputs x=0x = 0 and x=1x = 1 are 00 and 0.50.5. Their kernel value is 0.8830.883. Set noise variance σ2=0.1\sigma^2 = 0.1, and targets y=(1,0)y = (1, 0). Predict at the test input x∗=0.5x_* = 0.5, whose feature is 0.250.25.

  1. Training matrix: K+σ2I=(1.10.8830.8831.1)K + \sigma^2 I = \begin{pmatrix} 1.1 & 0.883 \\ 0.883 & 1.1 \end{pmatrix}, since each diagonal entry is 1+0.11 + 0.1.
  2. Determinant: 1.1×1.1−0.8832=1.21−0.780=0.4301.1 \times 1.1 - 0.883^2 = 1.21 - 0.780 = 0.430.
  3. Solve for α=(K+σ2I)−1y\boldsymbol{\alpha} = (K + \sigma^2 I)^{-1}\mathbf{y}. The inverse is 10.430(1.1−0.883−0.8831.1)\frac{1}{0.430}\begin{pmatrix} 1.1 & -0.883 \\ -0.883 & 1.1 \end{pmatrix}, so α=10.430(1.1, −0.883)≈(2.558, −2.053)\boldsymbol{\alpha} = \frac{1}{0.430}(1.1,\, -0.883) \approx (2.558,\, -2.053).
  4. Test-to-training kernel values: the feature 0.250.25 is 0.250.25 away from both 00 and 0.50.5, so both values are exp⁡(−0.03125)≈0.969\exp(-0.03125) \approx 0.969.
  5. Predictive mean: 0.969×(2.558−2.053)=0.969×0.505≈0.490.969 \times (2.558 - 2.053) = 0.969 \times 0.505 \approx 0.49.
  6. Predictive variance: the prior variance is 1. The subtracted term is 0.9692×(1T(K+σ2I)−11)=0.939×1.01≈0.950.969^2 \times (\mathbf{1}^T (K+\sigma^2 I)^{-1}\mathbf{1}) = 0.939 \times 1.01 \approx 0.95, so the variance is about 0.050.05.
  7. Interpretation: the test point sits between the two training points, so the mean is between their targets and the variance is small. Out past the data, the variance would grow back toward 1.
Example
3. A realistic regression comparison (paper's Table 2)

On the MNIST digit magnitude task, the paper reports RMSE of 1.25 for a Gaussian process with an RBF kernel on raw pixels, 0.59 for a convolutional network, and 0.53 for deep kernel learning with the same convolutional architecture. Lower RMSE is better.

  1. Reduction against the plain Gaussian process: 1.25−0.53=0.721.25 - 0.53 = 0.72.
  2. Relative reduction: 0.72/1.25=0.5760.72 / 1.25 = 0.576.
  3. Reduction against the convolutional network: 0.59−0.53=0.060.59 - 0.53 = 0.06.
  4. Relative reduction: 0.06/0.59≈0.100.06 / 0.59 \approx 0.10.
  5. Interpretation: most of the gain over the plain kernel comes from learning the features. The gain over the convolutional network alone is smaller, about a tenth, but the deep kernel also supplies a posterior with uncertainty, which the network does not.

Try it: on the paper's Olivetti face task, the Gaussian process with an RBF kernel scores 16.33 and the deep kernel scores 6.07. What is the relative reduction in RMSE? Answer: (16.33−6.07)/16.33=10.26/16.33≈0.63(16.33 - 6.07)/16.33 = 10.26/16.33 \approx 0.63, so about 63 percent lower.

Results

UCI regression (Table 1). The paper compares 16 regression datasets with between about 2,500 and 2,049,280 training points. For most datasets, deep kernel learning with a spectral mixture base kernel gives the lowest test RMSE among the Gaussian process methods, and the paper reports that combining the deep network with the scalable Gaussian process beats the stand-alone deep network on all 16 datasets. The extra runtime over the deep network is about 10 percent in the paper's measurements.

Olivetti faces (Table 2). The task is to predict face orientation from 28 by 28 patches. The Gaussian process with an RBF kernel scores RMSE 16.33, the deep belief network with a Gaussian process scores 6.42, the convolutional network scores 6.34, and deep kernel learning scores 6.07. The model was trained on 12,000 instances using all labels, where the deep belief network approach was limited to 1,000 labelled images.

MNIST digit magnitude (Table 2). The RMSE values are 1.25 for the Gaussian process, 1.03 for the deep belief network with a Gaussian process, 0.59 for the convolutional network, and 0.53 for deep kernel learning.

Scaling. Training time grows roughly linearly in nn with a slope of about 1 on a log-log plot, as the paper's Figure 3 shows.

Limits. The spectral mixture base kernel gives notable additional gains over the RBF base kernel in the paper's tables. The method also depends on the approximation being accurate, which the paper supports with a large number of inducing points, close to the number of training points. Many parameters are fitted by the marginal likelihood, so the model's complexity is set by data that may be limited.

Reading guide

Read the paper in this order, with the lessons it needs.

Read next: Bayesian Optimization, which uses Gaussian processes whose uncertainty drives the search.

Check yourself

QuestionIn the tiny example, the network weight changes from 2 to 0.5. Does the base kernel itself change, and what does change?Show answer
The base kernel formula does not change. What changes is the feature gap that the kernel sees: with weight 2 the features are 2 apart, and with weight 0.5 they are 0.5 apart. The same raw inputs therefore get a different kernel value, which is how the network changes the metric.
QuestionTwo points have kernel value 0.883 between them and noise variance 0.1. What is the value of the diagonal entries of K+σ2IK + \sigma^2 I if the base kernel has value 1 on the diagonal?Show answer
Each diagonal entry is 1+0.1=1.11 + 0.1 = 1.1. The noise variance is added to every diagonal entry of the kernel matrix, not to the off-diagonal entries.
QuestionWhy does the marginal likelihood include a log-determinant term, and what does it do for the model?Show answer
The log-determinant of K+σ2IK + \sigma^2 I grows as the kernel becomes more flexible, so it penalises complex kernels. Together with the data-fit term it gives the model's complexity calibrated by the data, without a separate regulariser.
QuestionThe paper pretrains the network with stochastic gradient descent on a squared loss before joint training. Why is that useful?Show answer
Joint training starts from a sensible feature space rather than random weights, so the marginal likelihood gradients are informative from the start. The pretraining is a starting point; the joint stage then trains the network weights and the kernel parameters together through the marginal likelihood.
QuestionFor a dataset with 500 points, is the scaling argument the main reason to use this method?Show answer
Not on its own. The scaling argument matters when nn is large, where exact inference is costly. At 500 points an exact Gaussian process is cheap, so the main reasons would be the learned features and the posterior uncertainty.

Sources

Read the full paper

Andrew Gordon Wilson, Zhiting Hu, Ruslan Salakhutdinov et al., 2015. arXiv:1511.02222