From 0e109cd3dac077156d60fdcfd72420049e27bb06 Mon Sep 17 00:00:00 2001 From: alessandratosi Date: Thu, 21 Apr 2016 15:45:37 +0100 Subject: [PATCH] syntax fix --- GPy/kern/src/add.py | 5 ++--- GPy/kern/src/kernel_slice_operations.py | 6 +++--- GPy/kern/src/linear.py | 2 +- GPy/kern/src/static.py | 2 +- GPy/kern/src/stationary.py | 8 ++++---- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/GPy/kern/src/add.py b/GPy/kern/src/add.py index 9b83d633..7c03d064 100644 --- a/GPy/kern/src/add.py +++ b/GPy/kern/src/add.py @@ -86,7 +86,7 @@ class Add(CombinationKernel): return target def gradients_XX(self, dL_dK, X, X2, cov=True): - if cov==True: # full covarance + if cov: # full covarance if X2 is None: target = np.zeros((X.shape[0], X.shape[0], X.shape[1], X.shape[1])) else: @@ -96,8 +96,7 @@ class Add(CombinationKernel): 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, cov)) for p in self.parts] + [target.__iadd__(p.gradients_XX(dL_dK, X, X2)) for p in self.parts] return target def gradients_XX_diag(self, dL_dKdiag, X): diff --git a/GPy/kern/src/kernel_slice_operations.py b/GPy/kern/src/kernel_slice_operations.py index ddb16ea1..104bed48 100644 --- a/GPy/kern/src/kernel_slice_operations.py +++ b/GPy/kern/src/kernel_slice_operations.py @@ -119,14 +119,14 @@ def _slice_gradients_XX(f): N, M = X.shape[0], X.shape[0] else: N, M = X.shape[0], X2.shape[0] - if cov==True: # full covariance + if cov: # full covariance with _Slice_wrap(self, X, X2, ret_shape=(N, M, X.shape[1], X.shape[1])) as s: #with _Slice_wrap(self, X, X2, ret_shape=None) as s: - ret = s.handle_return_array(f(self, dL_dK, s.X, s.X2, cov=True)) + ret = s.handle_return_array(f(self, dL_dK, s.X, s.X2, cov)) else: # diagonal covariance with _Slice_wrap(self, X, X2, ret_shape=(N, M, X.shape[1])) as s: #with _Slice_wrap(self, X, X2, ret_shape=None) as s: - ret = s.handle_return_array(f(self, dL_dK, s.X, s.X2, cov=True)) + ret = s.handle_return_array(f(self, dL_dK, s.X, s.X2, cov)) return ret return wrap diff --git a/GPy/kern/src/linear.py b/GPy/kern/src/linear.py index fa412c1d..cd0fb937 100644 --- a/GPy/kern/src/linear.py +++ b/GPy/kern/src/linear.py @@ -101,7 +101,7 @@ class Linear(Kern): #return (((X2[None,:, :] * self.variances)) * dL_dK[:, :, None]).sum(1) return dL_dK.dot(X2)*self.variances #np.einsum('jq,q,ij->iq', X2, self.variances, dL_dK) - def gradients_XX(self, dL_dK, X, X2=None): + def gradients_XX(self, dL_dK, X, X2=None, cov=True): if X2 is None: dL_dK = (dL_dK+dL_dK.T)/2 if X2 is None: return 2*np.ones(X.shape)*self.variances diff --git a/GPy/kern/src/static.py b/GPy/kern/src/static.py index 3ce0dc0a..a56d1903 100644 --- a/GPy/kern/src/static.py +++ b/GPy/kern/src/static.py @@ -24,7 +24,7 @@ class Static(Kern): def gradients_X_diag(self, dL_dKdiag, X): return np.zeros(X.shape) - def gradients_XX(self, dL_dK, X, X2): + def gradients_XX(self, dL_dK, X, X2=None, cov=True): if X2 is None: X2 = X return np.zeros((X.shape[0], X2.shape[0], X.shape[1]), dtype=np.float64) diff --git a/GPy/kern/src/stationary.py b/GPy/kern/src/stationary.py index 4de52d91..ae302266 100644 --- a/GPy/kern/src/stationary.py +++ b/GPy/kern/src/stationary.py @@ -222,14 +222,14 @@ class Stationary(Kern): """ Given the derivative of the objective K(dL_dK), compute the second derivative of K wrt X and X2: - cov = Full: returns the full covariance matrix [QxQ] of the input dimensionfor each pair or vectors - cov = Diag: returns the diagonal of the covariance matrix [QxQ] of the input dimensionfor each pair + cov = True: returns the full covariance matrix [QxQ] of the input dimensionfor each pair or vectors + cov = False: returns the diagonal of the covariance matrix [QxQ] of the input dimensionfor each pair or vectors (computationally more efficient if the full covariance matrix is not needed) ..math: \frac{\partial^2 K}{\partial X2 ^2} = - \frac{\partial^2 K}{\partial X\partial X2} ..returns: - dL2_dXdX2: [NxMxQ] in the cov=Diag case, or [NxMxQxQ] in the cov=full case, + dL2_dXdX2: [NxMxQxQ] in the cov=True case, or [NxMxQ] in the cov=False case, for X [NxQ] and X2[MxQ] (X2 is X if, X2 is None) Thus, we return the second derivative in X2. """ @@ -251,7 +251,7 @@ class Stationary(Kern): # (seems to have a bug: it is subtracted to the first X1 anyway) tmp1[invdist2==0.] -= self.variance - if cov==True: # full covariance + if cov: # full covariance grad = np.empty((X.shape[0], X2.shape[0], X2.shape[1], X.shape[1]), dtype=np.float64) for q in range(self.input_dim): for r in range(self.input_dim):