
Expand an adjacency matrix to include higher-order neighborhoods
expand_adjacency_matrix.Rd
The node neighborhoods are expanded by multiplying the adjacency matrix k
times. To make sure that all neighbors up to k
steps away are included,
self-loops are added by setting the diagonal of A
to 1. These self-loops
are removed from the resulting matrix after expansion. Note that the self-loops
affect how the transition probabilities are calculated. When use_weights = FALSE
,
the edge values of the result from the matrix multiplication corresponds to the
number of k-step random walks between any pair of nodes. For the expanded adjacency
matrix, we replace these edge values with 1 so that the adjacency matrix corresponds
to an unweighted graph with expanded neighborhoods.
Arguments
- A
An adjacency matrix. Can be a sparse matrix (
dgCMatrix
)- k
An integer specifying the neighborhood size. Each node will be connected to nodes up to
k
steps away.- use_weights
If
TRUE
, the transpose of the stochastic matrix will be expanded. The resulting edge weights will correspond to the incoming transition probabilities for ak
-step random walk.