def fast_heat_similarity_matrix(X, sigma):
"""
PyTorch based similarity calculation
:param X: the matrix with the data
:param sigma: scaling factor
:return: the similarity matrix
"""
use_gpu = False
# Use GPU if available
if torch.cuda.device_count() > 0:
use_gpu = True
X = Variable(torch.from_numpy(np.float32(X)))
sigma = Variable(torch.from_numpy(np.float32([sigma])))
if use_gpu:
X, sigma = X.cuda(), sigma.cuda()
D = sym_heat_similarity_matrix(X, sigma)
if use_gpu:
D = D.cpu()
return D.data.numpy()
评论列表
文章目录