matrix - 为什么 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
我不确定为什么库对距离矩阵中的每个值进行平方。我看到他们也进行了一些重新排序,并且他们使用了不同的热核公式。
所以我只想知道是否有任何资源(论文或图书馆)是错误的,或者它们是否在某种程度上是等价的,或者是否有人知道它们为什么不同。
解决方案
推荐阅读
- typescript - 将数组指定为元组
- openlayers - 修复 Openlayers 中的文本大小
- paypal - 我在使用 paypal checkout-sdk 的沙盒中找不到交易历史记录
- mongodb - 更新文档上的 MongoDb TTL 索引
- regex - 如何匹配两个单词之间的句子 REGEX
- python - 如何从现有 df 设置多索引列
- python - 在 pandas 或 numpy 中对多行组合求和:加速慢速嵌套循环
- nestjs - Nestjs:为动态模块设置全局前缀
- xamarin.forms - 应用程序中心构建成功 xamarin 使用编译器符号形成 android,但为白标应用程序构建 IOS 失败
- arrays - 如何从 char 数组中删除前 80 个字符?