0

我有来自 KNN 的数组,如下所示:

[[point0, 1st nearest point of point0,......., kth nearest point of point0]\
 [point1, 1st nearest point of point1,......., kth nearest point of point1]\
 .....\
 [pointN, 1st nearest point of pointN,......., kth nearest point of pointN]]

例如:
[[0,12,1,13]
[1,9,4,76]]
....
[76,2,3,4]]

现在我需要使用这个数组创建一个图,我尝试for通过添加节点和边在网络中循环,但图拉普拉斯矩阵与正确答案不匹配。因为我正在处理 ImageNet,所以无法逐个节点检查以找出错误所在。

然后我尝试用这个数组从 KNN 生成一个稀疏邻接矩阵,然后用nx.from_scipy_sparse_matrix. 但即使使用lil_matrix,生成稀疏邻接矩阵仍然很慢。

现在我想知道有没有更好更快的方法来实现这一目标?

PS(根据networkx,曾经我们使用添加边,比如G.add_edge(1, 2)。我们不需要单独添加这个节点,比如G.add_node(1)。但是根据我的观察,在处理大量数据时并不正确)

4

0 回答 0