All problems
Gaussian Process Posterior Mean
Problem
For a zero-mean Gaussian process with squared exponential kernel exp(-(a - b)^2 / (2 * length_scale^2)) and additive noise variance noise, the posterior mean at x_star is k_star^T (K + noise * I)^-1 y. Build the kernel matrix, solve the system with a Cholesky factorization, and return the predictive mean. Return 0.0 for empty or mismatched data or invalid hyperparameters.
Hint
The predictive mean is the kernel vector against the training targets, smoothed by the regularized kernel inverse.
Test cases
case 1
in: [[0],[2],1,1,1]
expected: 0.6065306597126333
case 2
in: [[0,1],[0,1],0.5,1,0.1]
expected: 0.5171292397015598
case 3
in: [[0,2],[1,3],1,1,0.5]
expected: 1.4835628288095244
case 4
in: [[],[],1,1,1]
expected: 0
case 5
in: [[0,1],[1],1,1,1]
expected: 0
Starter codePython
import math
def gp_posterior_mean(x_train, y_train, x_star, length_scale, noise):
# Your code here
pass5 test cases · run your code against them in the editor