Derive the log marginal likelihood of a GP regression model with y∼N(0,Ky), Ky=K+σ2I, and its gradient with respect to a kernel hyperparameter θ. How do the data-fit and complexity terms trade off as the length-scale grows?

Probabilistic models, Gaussian processes
Level L4 Advanced. Length Long. Nature Mat Mathematical.

What's being asked

Whether you can differentiate a Gaussian log-density through a matrix inverse and a log-determinant, and interpret the terms.

Key idea

ln⁡p(y)=−12y⊤Ky−1y−12ln⁡∣Ky∣−n2ln⁡2π, and ∂∂θln⁡p=12tr((αα⊤−Ky−1)∂Ky∂θ) with α=Ky−1y.

Steps

  1. Integrating out the latent function gives y∼N(0,Ky), so the log density is −12y⊤Ky−1y−12ln⁡∣Ky∣−n2ln⁡2π.
  2. Use ∂Ky−1∂θ=−Ky−1∂Ky∂θKy−1 and ∂ln⁡∣Ky∣∂θ=tr(Ky−1∂Ky∂θ).
  3. The derivative is 12y⊤Ky−1∂Ky∂θKy−1y−12tr(Ky−1∂Ky∂θ)=12tr((αα⊤−Ky−1)∂Ky∂θ).
  4. Terms: −12y⊤Ky−1y is the data fit. −12ln⁡∣Ky∣ is the complexity penalty (the log volume of functions the prior allows). The last is a constant.
  5. Length-scale trade-off: for small ℓ, K is close to the identity, so ln⁡∣Ky∣ is large (a flexible model) and the fit is good only if the data are noisy. For large ℓ, K is nearly rank one, so ln⁡∣Ky∣ is small, but the fit term becomes large since a flat function cannot match wiggly data. The maximum lies in between.
  6. Cost: one Cholesky of Ky gives Ky−1y and ln⁡∣Ky∣=2∑iln⁡Lii, in O(n3). The objective is non-convex in θ, so use several restarts.

Common mistakes

How long your answer should be

A page. About 8 minutes.

Last checked on 4 December 2026.

Read this

Previous in Probabilistic models: For Bayesian linear regression with prior w∼N(0,α−1I) and noise precision β, derive the log evidence ln⁡p(t∣α,β). Which terms reward fit, and which penalise complexity?
Next in Probabilistic models: The target is a bivariate Gaussian with zero mean, unit variances and correlation ρ=0.9. A mean-field approximation q(z1,z2)=q1(z1)q2(z2) is fitted by minimising KL(q ∥ p). What are the factor variances, and why are they much smaller than the true marginal variances?