def kernel(self, X, Y=None):
GenericTests.check_type(X,'X',np.ndarray,2)
# if X=Y, use more efficient pdist call which exploits symmetry
if Y is None:
dists = squareform(pdist(X, 'euclidean'))
else:
GenericTests.check_type(Y,'Y',np.ndarray,2)
assert(shape(X)[1]==shape(Y)[1])
dists = cdist(X, Y, 'euclidean')
if self.nu==0.5:
#for nu=1/2, Matern class corresponds to Ornstein-Uhlenbeck Process
K = (self.sigma**2.) * exp( -dists / self.width )
elif self.nu==1.5:
K = (self.sigma**2.) * (1+ sqrt(3.)*dists / self.width) * exp( -sqrt(3.)*dists / self.width )
elif self.nu==2.5:
K = (self.sigma**2.) * (1+ sqrt(5.)*dists / self.width + 5.0*(dists**2.) / (3.0*self.width**2.) ) * exp( -sqrt(5.)*dists / self.width )
else:
raise NotImplementedError()
return K
评论列表
文章目录