how to quickly create a graph with KNN results(ImageNet)

144 views Asked by At

I have arrays from KNN which are like:

[[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]]

for example:
[[0,12,1,13]
[1,9,4,76]]
....
[76,2,3,4]]

Now I need to create a graph using this array, I tried for loop in networks by adding nodes and edges but the graph Laplacian matrix doesn't match with the right answer. Because I'm dealing with ImageNet so it's not possible to check node by node to find out where is wrong.

Then I tried generating a sparse adjacency matrix with this array from KNN, then create a graph with nx.from_scipy_sparse_matrix. But even with lil_matrix, it's still pretty slow to generate a sparse adjacency matrix.

Now I'm wondering is there any better and faster way to achieve this?

PS(according to networkx, once we used adding edges, like G.add_edge(1, 2). We don't need to add this node separately, likeG.add_node(1). But it is not ture when dealing with massive data from my observation)

0

There are 0 answers