COSIE.utils.construct_knn_graph_hnsw
- construct_knn_graph_hnsw(data, k=20, space='l2')[source]
Efficiently compute approximate k-nearest neighbor (k-NN) graph using the hnswlib library. This method is suitable for large-scale datasets.
Parameters
- datatorch.Tensor
A tensor of shape (n_cells, n_features) representing the input feature matrix.
- kint, optional
Number of nearest neighbors to retrieve for each sample. Default is 20.
- spacestr, optional
Distance metric used to build the index. Must be one of {‘l2’, ‘ip’, ‘cosine’}.
‘l2’: Euclidean distance
‘ip’: Inner product
‘cosine’: Cosine similarity
Default is ‘l2’.
Returns
- edge_indextorch.LongTensor
A tensor of shape (2, n_edges) representing the edges of the graph. Each column represents an edge from source node to target node.