buildFromAdjacency.Rd
Construct a kNN-graph from an input adjacency matrix - either binary or distances between NNs.
x | An n X n |
---|---|
k | (optional) Scalar value that represents the number of nearest neighbours in the original graph. This
can also be inferred directly from the adjacency matrix |
is.binary | Logical scalar indicating if the input matrix is binary or not. |
A Milo
with the graph slot populated.
This function will take a matrix as input and construct the kNN graph that it describes. If the matrix is not symmetric then the graph is assumed to be directed, whereas if the matrix is not binary, i.e. all 0's and 1's then the input values are taken to be distances between graph vertices; 0 values are assumed to represent a lack of edge between vertices.
r <- 1000 c <- 1000 k <- 35 m <- floor(matrix(runif(r*c), r, c)) for(i in seq_along(1:r)){ m[i, sample(1:c, size=k)] <- 1 } milo <- buildFromAdjacency(m)#>#>