View source: R/laplacian_mat.R
laplacian_mat | R Documentation |
laplacian_mat
computes various forms of the graph Laplacian matrix for a given adjacency matrix W
.
laplacian_mat(W, type = "unnormalized")
W |
Adjacency matrix (dense or sparseMatrix). |
type |
Character string, type of Laplacian matrix to compute. Can be "unnormalized" (default), "normalized", or "randomwalk". |
The function supports three types of Laplacian matrices:
Unnormalized Laplacian:
L = D - W
Normalized Laplacian:
L_{norm} = I - D^{-1/2} W D^{-1/2}
Random Walk Laplacian:
L_{rw} = I - D^{-1} W
Where:
D
is the degree matrix, a diagonal matrix where each diagonal element D_{ii}
represents the sum of the weights of all edges connected to node i
.
W
is the adjacency matrix of the graph.
I
is the identity matrix.
The function supports both standard and sparse matrix representations of the adjacency matrix.
L
The graph Laplacian matrix.
Chung, F. R. (1997). Spectral graph theory (Vol. 92). American Mathematical Soc.
# Define the 3x3 adjacency matrix
W <- matrix(c(0, 1, 0,
1, 0, 1,
0, 1, 0), ncol=3)
# Non-sparse cases
laplacian_mat(W, "unnormalized")
laplacian_mat(W, "normalized")
laplacian_mat(W, "randomwalk")
# Convert W to a sparse matrix
W_sparse <- as(W, "sparseMatrix")
# Sparse cases
laplacian_mat(W_sparse, "unnormalized")
laplacian_mat(W_sparse, "normalized")
laplacian_mat(W_sparse, "randomwalk")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.