SheffieldML / GPy

Gaussian processes framework in python
BSD 3-Clause "New" or "Revised" License
2.05k stars 562 forks source link

gp models predictive_gradients with mean function #643

Open ghost opened 6 years ago

ghost commented 6 years ago

Hi,

I found that when calling predictive_gradients for a gp model with non trivial mean, the gradient returned for mean does not include the contribute of gradient from the mean function. To fix it, I believe simply add the gradient of mean to the result is correct. Here is an example where the I use linear mean function, and gradient of predicted means are about 0.

import numpy as np
import GPy

x_test = np.linspace(-1,1,10).reshape(-1,1)
mf = GPy.mappings.Linear(1,1)
X = np.linspace(-1,1,10).reshape(-1,1)
Y = X
gp_model = GPy.models.GPRegression(X, Y, mean_function=mf)
gp_model.optimize_restarts()
print(gp_model)
print(gp_model.predict(x_test)[0])
print(gp_model.predictive_gradients(x_test)[0])
mzwiessele commented 6 years ago

I think you are right. We are always happy for any help. The fix would need to go to a little helper (e.g. _predict_mean_jacobian(self, Xnew, kern)) for the core GP class. If you want to give it a try, please include some tests testing the predictive gradients for different mappings.