Constructs a symmetric KNN graph from a given feature space.

ConstructKnnGraph(
  knn = 5,
  feature_space,
  adjust_disconnection = TRUE,
  self_loop = 1
)

Arguments

knn

integer; the number of nearest neighbors to consider for constructing the graph. Default is 5.

feature_space

matrix; a cell-by-coordinate matrix (e.g., 20 principal components).

adjust_disconnection

boolean; TRUE for fully connecting disconnected components. Default is TRUE.

self_loop

integer; weight for self connections (default is 1).

Value

A list containing the following elements:

graph

matrix; symmetric KNN graph W, computed as pmax(1, (A + A^T) / 2).

adj_matrix

matrix; adjacency matrix A.

component

list; disconnected components in the graph, each component is represented as a subgraph.

Examples

feature_space <- matrix(rnorm(200), nrow = 10, ncol = 20)
result <- ConstructKnnGraph(knn = 3, feature_space = feature_space)
#> Constructing KNN graph
#> Remove  10  singleton cells.
graph <- result$graph
adj_matrix <- result$adj_matrix