Implement Gaussian process regression the way Murphy's book recommends: through a Cholesky factorisation, never an explicit inverse, and return the log marginal likelihood split into its two parts.
Use the squared-exponential kernel k(x,x′)=σf2exp(−∥x−x′∥2/(2ℓ2)) and a zero prior mean. Implement gp_fit_predict(X, y, X_star, ell, sf, sn, jitter=1e-8):
X (N, D) training inputs (a 1-D array means D=1), y (N,), X_star (M, D) test inputs; sf =σf, sn =σy (noise standard deviation).
- Kσ=K(X,X)+(σy2+jitter)I, factorised as Kσ=LL⊤.
- α=L⊤\(L\y); mean μ∗=k∗⊤α.
- v=L\k∗; latent variance σ∗2=k∗∗−v⊤v, i.e. the variance of f(x∗) without the noise.
- logp(y∣X)=−21y⊤α−∑nlogLnn−2Nlog(2π).
Return (mu, var, log_ml, fit, complexity) where fit =−21y⊤α and complexity =−∑nlogLnn (=−21log∣Kσ∣).