mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-10 20:42:39 +02:00
[gradients xx] getting there
This commit is contained in:
parent
4efb92c554
commit
5d19039d90
3 changed files with 52 additions and 51 deletions
|
|
@ -449,7 +449,7 @@ class GP(Model):
|
||||||
:param bool covariance: whether to include the covariance of the wishart embedding.
|
:param bool covariance: whether to include the covariance of the wishart embedding.
|
||||||
:param array-like dimensions: which dimensions of the input space to use [defaults to self.get_most_significant_input_dimensions()[:2]]
|
:param array-like dimensions: which dimensions of the input space to use [defaults to self.get_most_significant_input_dimensions()[:2]]
|
||||||
"""
|
"""
|
||||||
G = self.predict_wishard_embedding(Xnew, kern, mean, covariance)
|
G = self.predict_wishart_embedding(Xnew, kern, mean, covariance)
|
||||||
if dimensions is None:
|
if dimensions is None:
|
||||||
dimensions = self.get_most_significant_input_dimensions()[:2]
|
dimensions = self.get_most_significant_input_dimensions()[:2]
|
||||||
G = G[:, dimensions][:,:,dimensions]
|
G = G[:, dimensions][:,:,dimensions]
|
||||||
|
|
|
||||||
|
|
@ -70,11 +70,11 @@ class _Slice_wrap(object):
|
||||||
ret[:, self.k._all_dims_active] = return_val
|
ret[:, self.k._all_dims_active] = return_val
|
||||||
elif len(self.shape) == 3: # derivative for X2!=None
|
elif len(self.shape) == 3: # derivative for X2!=None
|
||||||
if self.diag:
|
if self.diag:
|
||||||
ret[:, :, self.k._all_dims_active][:, self.k._all_dims_active] = return_val
|
ret.T[np.ix_(self.k._all_dims_active, self.k._all_dims_active)] = return_val.T
|
||||||
else:
|
else:
|
||||||
ret[:, :, self.k._all_dims_active] = return_val
|
ret[:, :, self.k._all_dims_active] = return_val
|
||||||
elif len(self.shape) == 4: # second order derivative
|
elif len(self.shape) == 4: # second order derivative
|
||||||
ret[:, :, self.k._all_dims_active][:, :, :, self.k._all_dims_active] = return_val
|
ret.T[np.ix_(self.k._all_dims_active, self.k._all_dims_active)] = return_val.T
|
||||||
return ret
|
return ret
|
||||||
return return_val
|
return return_val
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -254,8 +254,9 @@ class Stationary(Kern):
|
||||||
if cov: # 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):
|
||||||
|
tmpdist = (X[:,[q]]-X2[:,[q]].T)
|
||||||
for r in range(self.input_dim):
|
for r in range(self.input_dim):
|
||||||
tmpdist2 = (X[:,[q]]-X2[:,[q]].T)*(X[:,[r]]-X2[:,[r]].T) # Introduce temporary distance
|
tmpdist2 = tmpdist*(X[:,[r]]-X2[:,[r]].T) # Introduce temporary distance
|
||||||
if r==q:
|
if r==q:
|
||||||
grad[:, :, q, r] = np.multiply(dL_dK,(np.multiply((tmp1*invdist2 - tmp2),tmpdist2)/l2[r] - tmp1)/l2[q])
|
grad[:, :, q, r] = np.multiply(dL_dK,(np.multiply((tmp1*invdist2 - tmp2),tmpdist2)/l2[r] - tmp1)/l2[q])
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue