COSIE.utils.compute_knn_graph

compute_knn_graph(input_data, n_neighbors)[source]

Construct a k-nearest neighbors (k-NN) graph based on an input feature matrix.

Parameters

input_datanp.ndarray

An array of shape (n_cells, n_features) representing input features of cells, which can be spatial coordinates or feature vectors.

n_neighborsint

Number of nearest neighbors to connect for each node.

Returns

edge_indextorch.LongTensor

A tensor of shape (2, num_edges) representing the edges of the graph. Each column (i, j) represents an edge from node i to its j-th nearest neighbor.