mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-18 13:55:14 +02:00
syntax fix
This commit is contained in:
parent
5c0c1d4c3d
commit
0e109cd3da
5 changed files with 11 additions and 12 deletions
|
|
@ -86,7 +86,7 @@ class Add(CombinationKernel):
|
||||||
return target
|
return target
|
||||||
|
|
||||||
def gradients_XX(self, dL_dK, X, X2, cov=True):
|
def gradients_XX(self, dL_dK, X, X2, cov=True):
|
||||||
if cov==True: # full covarance
|
if cov: # full covarance
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
target = np.zeros((X.shape[0], X.shape[0], X.shape[1], X.shape[1]))
|
target = np.zeros((X.shape[0], X.shape[0], X.shape[1], X.shape[1]))
|
||||||
else:
|
else:
|
||||||
|
|
@ -96,8 +96,7 @@ class Add(CombinationKernel):
|
||||||
target = np.zeros((X.shape[0], X.shape[0], X.shape[1]))
|
target = np.zeros((X.shape[0], X.shape[0], X.shape[1]))
|
||||||
else:
|
else:
|
||||||
target = np.zeros((X.shape[0], X2.shape[0], X.shape[1]))
|
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]
|
||||||
[target.__iadd__(p.gradients_XX(dL_dK, X, X2, cov)) for p in self.parts]
|
|
||||||
return target
|
return target
|
||||||
|
|
||||||
def gradients_XX_diag(self, dL_dKdiag, X):
|
def gradients_XX_diag(self, dL_dKdiag, X):
|
||||||
|
|
|
||||||
|
|
@ -119,14 +119,14 @@ def _slice_gradients_XX(f):
|
||||||
N, M = X.shape[0], X.shape[0]
|
N, M = X.shape[0], X.shape[0]
|
||||||
else:
|
else:
|
||||||
N, M = X.shape[0], X2.shape[0]
|
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=(N, M, X.shape[1], X.shape[1])) as s:
|
||||||
#with _Slice_wrap(self, X, X2, ret_shape=None) 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
|
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=(N, M, X.shape[1])) as s:
|
||||||
#with _Slice_wrap(self, X, X2, ret_shape=None) 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 ret
|
||||||
return wrap
|
return wrap
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -101,7 +101,7 @@ class Linear(Kern):
|
||||||
#return (((X2[None,:, :] * self.variances)) * dL_dK[:, :, None]).sum(1)
|
#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)
|
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: dL_dK = (dL_dK+dL_dK.T)/2
|
||||||
if X2 is None:
|
if X2 is None:
|
||||||
return 2*np.ones(X.shape)*self.variances
|
return 2*np.ones(X.shape)*self.variances
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Static(Kern):
|
||||||
def gradients_X_diag(self, dL_dKdiag, X):
|
def gradients_X_diag(self, dL_dKdiag, X):
|
||||||
return np.zeros(X.shape)
|
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:
|
if X2 is None:
|
||||||
X2 = X
|
X2 = X
|
||||||
return np.zeros((X.shape[0], X2.shape[0], X.shape[1]), dtype=np.float64)
|
return np.zeros((X.shape[0], X2.shape[0], X.shape[1]), dtype=np.float64)
|
||||||
|
|
|
||||||
|
|
@ -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:
|
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 = True: 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 = 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)
|
or vectors (computationally more efficient if the full covariance matrix is not needed)
|
||||||
..math:
|
..math:
|
||||||
\frac{\partial^2 K}{\partial X2 ^2} = - \frac{\partial^2 K}{\partial X\partial X2}
|
\frac{\partial^2 K}{\partial X2 ^2} = - \frac{\partial^2 K}{\partial X\partial X2}
|
||||||
|
|
||||||
..returns:
|
..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)
|
for X [NxQ] and X2[MxQ] (X2 is X if, X2 is None)
|
||||||
Thus, we return the second derivative in X2.
|
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)
|
# (seems to have a bug: it is subtracted to the first X1 anyway)
|
||||||
tmp1[invdist2==0.] -= self.variance
|
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)
|
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 q in range(self.input_dim):
|
||||||
for r in range(self.input_dim):
|
for r in range(self.input_dim):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue