首页 > 解决方案 > 为什么 Python 的 Laplacian 方法与 Research Paper 不同?

问题描述

我找到了一个用于拉普拉斯分数特征选择的 Python 库。但实施似乎与研究论文不同。

我根据论文(https://papers.nips.cc/paper/2909-laplacian-score-for-feature-selection.pdf)中的算法实现了选择方法,如下:

纸公式

但是,我找到了一个实现拉普拉斯方法的 Python 库(https://github.com/jundongl/scikit-feature/blob/master/skfeature/function/similarity_based/lap_score.py)。

因此,为了检查我的实现是否正确,我在我的数据集上运行了两个版本,并得到了不同的答案。在调试过程中,我看到库在计算亲和矩阵(论文中的 S 矩阵)时使用了不同的公式。

论文使用这个公式:

热核纸配方

, 而图书馆使用

W_ij = exp(-norm(x_i - x_j)/2t^2)

进一步调查显示,该库计算亲和力矩阵如下:

   t = kwargs['t']
   # compute pairwise euclidean distances
   D = pairwise_distances(X)
   D **= 2
   # sort the distance matrix D in ascending order
   dump = np.sort(D, axis=1)
   idx = np.argsort(D, axis=1)
   idx_new = idx[:, 0:k+1]
   dump_new = dump[:, 0:k+1]
   # compute the pairwise heat kernel distances
   dump_heat_kernel = np.exp(-dump_new/(2*t*t))
   G = np.zeros((n_samples*(k+1), 3))
   G[:, 0] = np.tile(np.arange(n_samples), (k+1, 1)).reshape(-1)
   G[:, 1] = np.ravel(idx_new, order='F')
   G[:, 2] = np.ravel(dump_heat_kernel, order='F')
   # build the sparse affinity matrix W
   W = csc_matrix((G[:, 2], (G[:, 0], G[:, 1])), shape= 
   n_samples,n_samples))
   bigger = np.transpose(W) > W
   W = W - W.multiply(bigger) + np.transpose(W).multiply(bigger)
   return W

我不确定为什么库对距离矩阵中的每个值进行平方。我看到他们也进行了一些重新排序,并且他们使用了不同的热核公式。

所以我只想知道是否有任何资源(论文或图书馆)是错误的,或者它们是否在某种程度上是等价的,或者是否有人知道它们为什么不同。

标签: matrixaffinity

解决方案


推荐阅读