mirror of
https://github.com/SheffieldML/GPy.git
synced 2026-05-09 03:52:39 +02:00
fixed up dK_dX in the exponential and Matern kerns
This commit is contained in:
parent
4241a7c24f
commit
a6300fab10
3 changed files with 9 additions and 10 deletions
|
|
@ -78,12 +78,12 @@ class Matern32(kernpart):
|
|||
"""derivative of the diagonal of the covariance matrix with respect to the parameters."""
|
||||
target[0] += np.sum(partial)
|
||||
|
||||
def dK_dX(self,X,X2,target):
|
||||
def dK_dX(self,partial,X,X2,target):
|
||||
"""derivative of the covariance matrix with respect to X."""
|
||||
if X2 is None: X2 = X
|
||||
dist = np.sqrt(np.sum(np.square((X[:,None,:]-X2[None,:,:])/self.lengthscales),-1))[:,:,None]
|
||||
ddist_dX = (X[:,None,:]-X2[None,:,:])/self.lengthscales**2/np.where(dist!=0.,dist,np.inf)
|
||||
dK_dX += - np.transpose(3*self.variance*dist*np.exp(-np.sqrt(3)*dist)*ddist_dX,(1,0,2))
|
||||
dK_dX = - np.transpose(3*self.variance*dist*np.exp(-np.sqrt(3)*dist)*ddist_dX,(1,0,2))
|
||||
target += np.sum(dK_dX*partial.T[:,:,None],0)
|
||||
|
||||
def dKdiag_dX(self,X,target):
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ class Matern52(kernpart):
|
|||
self.name = 'Mat52'
|
||||
self.set_param(np.hstack((variance,lengthscales)))
|
||||
|
||||
|
||||
def get_param(self):
|
||||
"""return the value of the parameters."""
|
||||
return np.hstack((self.variance,self.lengthscales))
|
||||
|
|
@ -77,12 +76,12 @@ class Matern52(kernpart):
|
|||
"""derivative of the diagonal of the covariance matrix with respect to the parameters."""
|
||||
target[0] += np.sum(partial)
|
||||
|
||||
def dK_dX(self,X,X2,target):
|
||||
def dK_dX(self,partial,X,X2,target):
|
||||
"""derivative of the covariance matrix with respect to X."""
|
||||
if X2 is None: X2 = X
|
||||
dist = np.sqrt(np.sum(np.square((X[:,None,:]-X2[None,:,:])/self.lengthscales),-1))[:,:,None]
|
||||
ddist_dX = (X[:,None,:]-X2[None,:,:])/self.lengthscales**2/np.where(dist!=0.,dist,np.inf)
|
||||
dK_dX += - np.transpose(self.variance*5./3*dist*(1+np.sqrt(5)*dist)*np.exp(-np.sqrt(5)*dist)*ddist_dX,(1,0,2))
|
||||
dK_dX = - np.transpose(self.variance*5./3*dist*(1+np.sqrt(5)*dist)*np.exp(-np.sqrt(5)*dist)*ddist_dX,(1,0,2))
|
||||
target += np.sum(dK_dX*partial.T[:,:,None],0)
|
||||
|
||||
def dKdiag_dX(self,X,target):
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ class exponential(kernpart):
|
|||
#NB: derivative of diagonal elements wrt lengthscale is 0
|
||||
target[0] += np.sum(partial)
|
||||
|
||||
def dK_dX(self,X,X2,target):
|
||||
def dK_dX(self,partial,X,X2,target):
|
||||
"""derivative of the covariance matrix with respect to X."""
|
||||
if X2 is None: X2 = X
|
||||
dist = np.sqrt(np.sum(np.square((X[:,None,:]-X2[None,:,:])/self.lengthscales),-1))[:,:,None]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue