4

I was checking sklearn's implementation of log marginal likelihood of a Gaussian Process (GP). The implementation is based on Algorithm 2.1 in Rasmussen's Gaussian Processes for Machine Learning which I also attached a snapshot of it for convenience:

enter image description here

However, I constantly came across some cases wherethe log likelihood computed by this formula is positive. One specific example is the following example code:

import numpy as np 
from scipy.linalg import cholesky, cho_solve, solve_triangular
from sklearn.gaussian_process.kernels import Matern

kernel=Matern(nu=2.5)
x = np.array([1, 2, 3]).reshape(-1,1)
y = np.array([0.1, 0.2, 0.3])
noise=0
amp2=0.05 

K = kernel(x)

cov = amp2 * (K + 0*np.eye(x.shape[0])) 
cov[np.diag_indices_from(cov)] += noise
L = cholesky(cov, lower=True)
alpha = cho_solve((L, True), y)
logprob = -0.5 * np.dot(y, alpha) - np.log(np.diag(L)).sum() - \
      x.shape[0] / 2. * np.log(2 * np.pi)
print(logprob) # Result: 1.1359631938135135

I believe that the log marginal likelihood of a GP log Pr(y|x, M) should always be non-positive. Why the code above produces a positive log marginal likelihood?

Thank you!

Zeel B Patel
  • 691
  • 5
  • 16
TNg
  • 856
  • 1
  • 9
  • 15
  • 1
    hey, i don't have an answer to your question, but could it be possibly related to this? I am also getting some discrepancies between the way sklearn calculates lml vs gpml https://stats.stackexchange.com/questions/394345/is-it-valid-to-compare-the-likelihood-of-different-models-in-gaussian-process-re – kennyvh Nov 30 '20 at 18:38
  • Hi @khuynh, thanks for the link, though it has been a while that I do not remember much about how I have resolved this question. Hope you can resolve your case too. – TNg Dec 01 '20 at 11:40
  • Any chance @thanhtang that you remembered how you solved this? – MJimitater Jun 02 '21 at 08:32

0 Answers0