Foundations to Frontier
Tests

GP classification

For classification the GP models a latent function f(x), squashed through a sigmoid to give P(y = 1 | x). The Bernoulli likelihood is not Gaussian, so the posterior over f has no closed form and must be approximated. The Laplace approximation fits a Gaussian at the posterior mode by Newton's method. Expectation propagation (EP) matches moments site by site, variational methods (including SVGP) maximize a bound, and MCMC (elliptical slice sampling) samples the exact posterior. Predictions then average the sigmoid over the latent uncertainty, which pulls probabilities toward 1/2 where the model is unsure. This page derives the Laplace and EP algorithms, the predictive approximations and the multi-class extension, and compares them with a sampling reference. In the exercise 50 noisy labels are classified with signal sd 1, 3 and 10. Laplace systematically shrank the latent function (to 0.94, 0.83 and 0.71 of the MCMC posterior mean's size), while EP matched it (0.99 to 1.01). EP beat Laplace against the true probabilities in all 9 runs. A negative surprise: plugging in the Laplace mean without averaging beat properly averaged Laplace predictions in 7 of 9 runs, because averaging adds a second shrinkage on top of Laplace's.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Probabilities instead of numbers

To classify, a GP models an invisible score that varies smoothly over the inputs and turns it into a probability with an S-shaped squashing function. High score means probably class 1, low means probably class 0. Because the labels are only 0s and 1s, the maths no longer has a neat closed form, so the score has to be approximated. The reward is honest probabilities: near the training data they are confident, far from it they drift back to 50/50. The demo shows the latent score’s band and the resulting probability; compare the averaged probability with the over-confident one that ignores the band.

Uncertainty lab
30 labels from P(y = 1) = σ(3 sin x). Green: predictive probability averaging σ over the Laplace posterior of the latent; red dashed: plug-in σ(mean), which is more extreme; band: σ of the latent ±2 sd. Larger σ_f lets the latent grow and the probabilities sharpen.
Why engineers care

Calibrated class probabilities are what safety cases need: a terrain classifier that says ‘traversable with probability 0.6’ far from its training data, rather than 0.99, lets a planner slow down or ask for help. GP classifiers are also standard in active learning and in preference learning for robot reward models.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A GP classifier passes the latent function through…
  2. 2. Far from the training data, its probabilities go toward…
  3. 3. The GP classification posterior is…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

The model and two approximations

  • Model: f ~ GP(0, k), P(y_i = 1 | f_i) = σ(f_i) with the logistic σ (or the probit Φ). σ(2) = 0.881.
  • Posterior: p(f | y) ∝ N(f | 0, K) Π_i σ(f_i)^(y_i) (1 − σ(f_i))^(1 − y_i). Log-likelihood Σ y_i f_i − log(1 + e^(f_i)); two latent values of 0 cost 2 log 2 = 1.386 nats.
  • Laplace (Williams and Barber, 1998):
    • Find the mode f̂ by Newton’s method; at the mode f̂ = K(y − σ(f̂)).
    • Approximate p(f | y) ≈ N(f̂, (K⁻¹ + W)⁻¹) with W = diag(σ(f̂)(1 − σ(f̂))) ≤ 0.25. Confident points (p = 0.99, W = 0.0099) barely reduce the variance.
    • Predictive latent: mean kᵀ(y − σ(f̂)) (only badly fitted points contribute, as in an SVM), variance k** − kᵀ(K + W⁻¹)⁻¹k*.
  • EP (Minka, 2001): replace each likelihood term by a Gaussian site; for each i, remove its site (cavity), multiply in the true likelihood, match mean and variance, update the site. Iterate to convergence.
  • Prediction: average, do not plug in: P(y* = 1) = E[σ(f*)] for f* ~ N(μ*, v*).
    • MacKay’s probit approximation: σ(μ*/√(1 + πv*/8)). For N(2, 4): 0.777 instead of σ(2) = 0.881.
    • Exact alternative: Gauss–Hermite quadrature.
  • Other routes: variational GP classification and SVGP with a Bernoulli likelihood (Hensman, Matthews and Ghahramani, 2015); elliptical slice sampling (Murray, Adams and MacKay, 2010) or HMC for an exact reference; Pólya–Gamma augmentation for Gibbs sampling.
  • Multi-class: one latent GP per class with a softmax likelihood (Laplace in R&W §3.5), or a robust-max or Dirichlet-based likelihood.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Laplace's covariance is…
  2. 2. EP updates each site by…
  3. 3. Averaging σ over N(2, 4) gives about…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

GP classifiers in practice

Exercise 1.

  • Newton’s method for the Laplace mode (the stable B = I + W½KW½ form).
  • The Laplace predictive latent mean and variance.
  • MacKay’s probit approximation, checked against Monte Carlo.

Practice.

  • For a few thousand points: EP or Laplace with an exact GP (GPflow VGP/GPC, scikit-learn GaussianProcessClassifier uses Laplace).
  • For more data or minibatches: SVGP with a Bernoulli likelihood (GPyTorch, GPflow).
  • Learn hyperparameters on the approximate evidence (Laplace or EP) or the ELBO; EP’s evidence approximation is usually better.
  • Always report averaged probabilities and check calibration (reliability diagrams, expected calibration error) on held-out data.
  • Watch large signal variances: the posterior becomes skewed and Laplace degrades; prefer EP, VI with full covariance, or MCMC there.
import gpytorch as gp, torch
class GPC(gp.models.ApproximateGP):
    def __init__(s, Z):
        q = gp.variational.CholeskyVariationalDistribution(Z.size(0))
        super().__init__(gp.variational.VariationalStrategy(s, Z, q, learn_inducing_locations=True))
        s.mean = gp.means.ConstantMean(); s.cov = gp.kernels.ScaleKernel(gp.kernels.RBFKernel())
    def forward(s, x): return gp.distributions.MultivariateNormal(s.mean(x), s.cov(x))
model, lik = GPC(X[:200]), gp.likelihoods.BernoulliLikelihood()          # probit link, averaged predictions
mll = gp.mlls.VariationalELBO(lik, model, num_data=len(X))
# after training: p = lik(model(X_test)).mean    -> E[Φ(f*)], already averaged over the latent
🐍 Exercise 1: the Laplace approximation
Find the Laplace mode by Newton's method, compute the predictive latent mean and variance, and average the sigmoid with the probit approximation.
📝 Quick check (Level 2)
0/3 answered
  1. 1. scikit-learn's GaussianProcessClassifier uses…
  2. 2. For millions of labelled points, use…
  3. 3. Laplace degrades most when…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Newton’s method for the mode. Ψ(f) = log p(y | f) − ½fᵀK⁻¹f has gradient ∇log p − K⁻¹f and Hessian −W − K⁻¹. Newton’s step gives f_new = (K⁻¹ + W)⁻¹(Wf + ∇log p). Writing it with B = I + W½KW½ (well-conditioned, eigenvalues between 1 and 1 + n·max k/4) avoids inverting K. Ψ is concave for log-concave likelihoods, so the mode is unique.

Why Laplace shrinks the latent. The logistic likelihood saturates: once a point is classified correctly, pushing f further gains almost nothing. So the true posterior over f is skewed, with a long tail away from zero. The mode sits closer to zero than the mean, and the Gaussian fitted at the mode inherits a too-small location (Kuss and Rasmussen, 2005; Nickisch and Rasmussen, 2008). The effect grows with the signal variance because the prior allows larger |f|.

Why EP does better. EP minimizes a local forward KL, matching the mean and variance of each tilted distribution, so it targets the posterior’s moments rather than its mode. For GP classification it is typically almost indistinguishable from long MCMC runs, at the cost of a more delicate algorithm (convergence is not guaranteed in general, though for log-concave likelihoods it usually converges).

Averaging and calibration. For f* ~ N(μ, v), E[σ(f*)] is closer to 1/2 than σ(μ) because σ is convex below 0 and concave above it. MacKay’s approximation replaces σ by a probit with matched slope, Φ(λz) with λ² = π/8, for which the Gaussian average is exact: Φ(λμ/√(1 + λ²v)). Averaging is the right thing only if μ and v are right. With Laplace, μ is already too small, so averaging shrinks twice.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The Laplace mode is unique because…
  2. 2. Laplace underestimates the latent mean's magnitude because…
  3. 3. The probit approximation uses λ² =…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How far do Laplace, EP and plug-in predictions deviate from the exact GP classifier?

History.

  • C. Williams and D. Barber, “Bayesian classification with Gaussian processes” (1998): Laplace.
  • T. Minka, “Expectation propagation for approximate Bayesian inference” (2001); M. Seeger’s and Rasmussen and Williams’s EP for GPC.
  • M. Kuss and C. Rasmussen, “Assessing approximate inference for binary Gaussian process classification” (2005); H. Nickisch and C. Rasmussen, “Approximations for binary Gaussian process classification” (2008).
  • I. Murray, R. Adams and D. MacKay, “Elliptical slice sampling” (2010).

Exercise 2. 50 inputs uniform on [−5, 5] with labels from P(y = 1) = σ(3 sin x). RBF kernel with ℓ = 1 and signal sd σ_f = 1, 3 or 10 (fixed).

  • Methods: Laplace (Newton, 50 iterations max) with predictions averaged by Gauss–Hermite quadrature; the plug-in σ(Laplace mean); EP with Gauss–Hermite moment matching; and a reference from two independent elliptical-slice chains (1000 samples each after 300 burn-in).
  • Measures: expected negative log-likelihood against the true probabilities on 101 test points (Bayes optimum 0.3768, no Monte Carlo noise), and the average magnitude of the latent posterior mean relative to the MCMC estimate.
σ_f NLL plug-in NLL Laplace NLL EP NLL MCMC latent size, Laplace / EP (MCMC = 1)
1 0.4949 0.5061 0.4997 0.4971 0.94 / 0.99
3 0.4412 0.4596 0.4426 0.4436 0.83 / 0.99
10 0.4614 0.4758 0.453 0.4448 0.71 / 1.01
  • Laplace shrinks the latent function, more as σ_f grows (to 71% at σ_f = 10, also 0.71 and 0.70 on seeds 1 and 2); EP stays within 5% of MCMC in every run (0.95–1.05).
  • EP beat Laplace against the true probabilities in all 9 runs (3 signal variances × 3 seeds).
  • Negative surprise: the theoretically wrong plug-in σ(Laplace mean) beat averaged Laplace predictions in 7 of 9 runs; it lost only at σ_f = 10 on seeds 1 and 2. Laplace’s mean is too small, and averaging shrinks it again, so the two errors compound; the plug-in accidentally cancels part of the first. EP’s averaged predictions beat the plug-in at σ_f = 10 in all three seeds but not at σ_f = 1 or 3.
  • MacKay’s probit approximation was within 0.0016–0.0042 (mean absolute difference) of quadrature.
  • Caveat on the reference: the two MCMC chains disagreed by 0.017–0.061 in mean predicted probability, as large as the differences between methods, so the MCMC column is only indicative (on seed 1 at σ_f = 10 its NLL was the worst, 0.4884). The latent-size ratios average over all points and are much more stable.
🐍 Exercise 2 (research): how far do Laplace, EP and plug-in predictions deviate from the exact GP classifier?
Compare Laplace, EP and plug-in predictions with an elliptical-slice-sampling reference for GP classification at three signal variances.

GP classification in AI, robotics and aerospace

  • Terrain classification: GP classifiers on proprioceptive and visual features give traversability probabilities that fall back to 0.5 on unfamiliar terrain, used for cautious planning.
  • Active learning and preference learning: GP classifiers drive query selection (BALD) and learn reward functions from pairwise human preferences for robot behaviour.
  • Failure-region estimation: GP classifiers over simulation parameters map where a controller or flight software fails, with uncertainty guiding further simulations.
  • Earth observation: land-cover and cloud masks with per-pixel probabilities from SVGP classifiers.

References

  1. C. K. I. Williams and D. Barber (1998). “Bayesian classification with Gaussian processes.” IEEE PAMI, 20.
  2. T. Minka (2001). “Expectation propagation for approximate Bayesian inference.” UAI.
  3. M. Kuss and C. E. Rasmussen (2005). “Assessing approximate inference for binary Gaussian process classification.” JMLR, 6.
  4. C. E. Rasmussen and C. K. I. Williams (2006). Gaussian Processes for Machine Learning, ch. 3. MIT Press.
  5. H. Nickisch and C. E. Rasmussen (2008). “Approximations for binary Gaussian process classification.” JMLR, 9.
  6. I. Murray, R. P. Adams and D. J. C. MacKay (2010). “Elliptical slice sampling.” AISTATS.
  7. J. Hensman, A. G. de G. Matthews and Z. Ghahramani (2015). “Scalable variational Gaussian process classification.” AISTATS.