Negative Variances from predictive_gradients()
See original GitHub issueI’m trying to get at the gradient of the predictions, but the variance of the estimate is coming back negative. Not sure if what I’m doing is wrong, but as a MWE, the following seems to demonstrate the issue:
import GPy
import numpy as np
# keep deviates deterministic (actual seed not important)
np.random.seed(123)
# draw from our function
X = np.random.uniform(-3.,3.,(20,1))
Y = np.sin(X) + np.random.randn(20,1)*0.05
# set up model
m = GPy.models.GPRegression(X, Y)
# optimise parameters (optional)
m.optimize()
# where do we want to predict our function
Xp = np.linspace(-4,4,51)[:,None]
# get our predictions of mean and gradient
mu,var = m.predict(Xp)
mug,varg = m.predictive_gradients(Xp)
# display variance in estimate of gradient?
print(varg)
I get back a number of negative values for the variance, which I’m not expecting… If I plot my test points and the function being fit they look fine:
But the variance seems to have a lot of unexpected structure, i.e. doesn’t just look like numerical instability to me. Not sure if this matters, but I’m running without Weave (I’m under OS X and am currently struggling to get OMP code compiling) so don’t know if the C version is correct.
I’ve just started to use GPy, so sorry if this issue/question is malformed! While poking around I’ve just seen m._raw_predict()
which looks useful as well. The underscore prefix makes it look as though it should be internal/private, is it recommended to be using this function?
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (1 by maintainers)
Top GitHub Comments
The derivative of the mean should be the same for all kernel functions.
So I actually had to implement that myself for RBF functions. Couldn’t figure out an easy generic way for all kernels either, mostly because there doesn’t seem to be a way to get the second derivative of the kernel, which is needed for the prior.
Anyways, since your just interested in RBFs anyways, here’s my rbf-specific code…without any warranty or me saying that this is a good implementation in any way. There might be some way that is a lot better, I’m not involved in this project at all, just a user. If you find a bug please let me know.
This bug arose as a misnderstanding of the predictive_gradients function. Have opened a new bug to request a function with the desired behaviour. #213