Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-318

Gaussian Process Log Marginal Likelihood

Problem

For a zero-mean Gaussian process with squared exponential kernel and additive noise variance noise, the log marginal likelihood is -0.5 * y^T (K + noise * I)^-1 y - 0.5 * log det(K + noise * I) - (n / 2) * log(2 * pi). Compute it with a Cholesky factorization and return 0.0 for empty or mismatched data or invalid hyperparameters.

Hint

The marginal likelihood trades off data fit, the Occam penalty from the determinant, and the normalization.

Test cases

case 1
in: [[0],[1],1,1]
expected: -1.5155121234846454
case 2
in: [[0,1],[1,2],1,1]
expected: -3.525410113236392
case 3
in: [[0,1],[0,0],2,0.5]
expected: -2.0309159974296955
case 4
in: [[],[],1,1]
expected: 0
case 5
in: [[0,1],[1],1,1]
expected: 0
Starter codePython
import math


def gp_log_marginal_likelihood(x_train, y_train, length_scale, noise):
    # Your code here
    pass

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