From 06da98f9eab0bda628fc8fadb64dcd367b3d871d Mon Sep 17 00:00:00 2001 From: James Hensman Date: Tue, 28 Jan 2014 14:40:07 +0000 Subject: [PATCH] changed gradient interface to gp and sparse GP --- GPy/core/gp.py | 3 ++- GPy/core/sparse_gp.py | 6 +++++- .../latent_function_inference/exact_gaussian_inference.py | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/GPy/core/gp.py b/GPy/core/gp.py index f54f5721..65898dfa 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -59,7 +59,8 @@ class GP(Model): self.parameters_changed() def parameters_changed(self): - self.posterior, self._log_marginal_likelihood, self._dL_dK = self.inference_method.inference(self.kern, self.X, self.likelihood, self.Y) + self.posterior, self._log_marginal_likelihood, grad_dict = self.inference_method.inference(self.kern, self.X, self.likelihood, self.Y) + self._dL_dK = grad_dict['dL_dK'] def log_likelihood(self): return self._log_marginal_likelihood diff --git a/GPy/core/sparse_gp.py b/GPy/core/sparse_gp.py index 17ecb073..e33703d8 100644 --- a/GPy/core/sparse_gp.py +++ b/GPy/core/sparse_gp.py @@ -11,6 +11,10 @@ class SparseGP(GP): """ A general purpose Sparse GP model + This model allows (approximate) inference using variational DTC or FITC + (Gaussian likelihoods) as well as non-conjugate sparse methods based on + these. + :param X: inputs :type X: np.ndarray (num_data x input_dim) :param likelihood: a likelihood instance, containing the observed data @@ -56,7 +60,7 @@ class SparseGP(GP): self.add_parameter(self.likelihood, gradient=lambda:self.likelihood._gradients(partial=self.partial_for_likelihood)) def parameters_changed(self): - self.posterior = self.inference_method.inference(self.kern, self.X, self.X_variance, self.Z, self.likelihood, self.Y) + self.posterior, self._log_marginal_likelihood, self.grad_dict = self.inference_method.inference(self.kern, self.X, self.X_variance, self.Z, self.likelihood, self.Y) #The derivative of the bound wrt the inducing inputs Z self.Z.gradient = self.kern.dK_dX(self.dL_dKmm, self.Z) diff --git a/GPy/inference/latent_function_inference/exact_gaussian_inference.py b/GPy/inference/latent_function_inference/exact_gaussian_inference.py index 9313316c..907e8485 100644 --- a/GPy/inference/latent_function_inference/exact_gaussian_inference.py +++ b/GPy/inference/latent_function_inference/exact_gaussian_inference.py @@ -53,6 +53,6 @@ class ExactGaussianInference(object): likelihood.update_gradients(np.diag(dL_dK)) - return Posterior(LW, alpha, K), log_marginal, dL_dK + return Posterior(LW, alpha, K), log_marginal, {'dL_dK':dL_dK}