From f6d07ff76acaab59950ff75630a3a5183bca38fe Mon Sep 17 00:00:00 2001 From: Max Zwiessele Date: Thu, 3 Sep 2015 10:19:57 +0100 Subject: [PATCH] [magnification] added static kernel support and faster derivative computations --- GPy/core/gp.py | 9 ++++++--- GPy/kern/_src/add.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/GPy/core/gp.py b/GPy/core/gp.py index 60038263..c278d509 100644 --- a/GPy/core/gp.py +++ b/GPy/core/gp.py @@ -352,13 +352,16 @@ class GP(Model): for i in range(self._predictive_variable.shape[0]): dK_dXnew_full[i] = kern.gradients_X([[1.]], Xnew, self._predictive_variable[[i]]) + if full_cov: + dK2_dXdX = kern.gradients_XX([[1.]], Xnew) + else: + dK2_dXdX = kern.gradients_XX_diag([[1.]], Xnew) + def compute_cov_inner(wi): if full_cov: # full covariance gradients: - dK2_dXdX = kern.gradients_XX([[1.]], Xnew) var_jac = dK2_dXdX - np.einsum('qnm,miq->niq', dK_dXnew_full.T.dot(wi), dK_dXnew_full) else: - dK2_dXdX = kern.gradients_XX_diag([[1.]], Xnew) var_jac = dK2_dXdX - np.einsum('qim,miq->iq', dK_dXnew_full.T.dot(wi), dK_dXnew_full) return var_jac @@ -568,7 +571,7 @@ class GP(Model): which_data_ycols, fixed_inputs, levels, samples, fignum, ax, resolution, plot_raw=plot_raw, Y_metadata=Y_metadata, - data_symbol=data_symbol, predict_kw=predict_kw, + data_symbol=data_symbol, predict_kw=predict_kw, plot_training_data=plot_training_data, **kw) diff --git a/GPy/kern/_src/add.py b/GPy/kern/_src/add.py index 132c53d2..3c97a08a 100644 --- a/GPy/kern/_src/add.py +++ b/GPy/kern/_src/add.py @@ -73,7 +73,10 @@ class Add(CombinationKernel): return target def gradients_XX(self, dL_dK, X, X2): - target = 0. + if X2 is None: + target = np.zeros((X.shape[0], X.shape[0], X.shape[1])) + else: + target = np.zeros((X.shape[0], X2.shape[0], X.shape[1])) [target.__iadd__(p.gradients_XX(dL_dK, X, X2)) for p in self.parts] return target