def grad_input(self, x):
"""Compute the gradient of the mean function and the standard deviation
function at the provided input.
"""
# Compute the gradient of the mean function.
d_kernel = self.kernel.grad_input(x, self.X)
d_mean = d_kernel.T.dot(self.alpha)
# Compute the gradient of the standard deviation function. It is
# absolutely crucial to note that the predict method returns the
# variance, not the standard deviation, of the prediction.
sd = self.predict(x)[1]
K_cross = self.kernel.cov(x, self.X)
M = spla.cho_solve((self.L, True), K_cross.T).ravel()
d_sd = -d_kernel.T.dot(M) / sd
return d_mean, d_sd
评论列表
文章目录