Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-316

Gaussian Process Posterior Variance

Problem

The posterior variance of a zero-mean Gaussian process with squared exponential kernel and additive noise variance noise is 1 minus k_star^T (K + noise * I)^-1 k_star. Build the kernel matrix, solve the system with a Cholesky factorization, clamp tiny negative values to 0.0, and return 1.0 for empty training data.

Hint

Observation noise adds to the diagonal, so the posterior variance never reaches zero exactly.

Test cases

case 1
in: [[0],1,1,1]
expected: 0.8160602794142788
case 2
in: [[0],0,1,1]
expected: 0.5
case 3
in: [[0,1],0.5,1,0.1]
expected: 0.08727009545489339
case 4
in: [[],0,1,1]
expected: 1
case 5
in: [[0,1],2,1,0.5]
expected: 0.7451180897502568
Starter codePython
import math


def gp_posterior_variance(x_train, x_star, length_scale, noise):
    # Your code here
    pass

5 test cases · run your code against them in the editor