laplacian_mat: Compute the Graph Laplacian Matrix

View source: R/laplacian_mat.R

laplacian_matR Documentation

Compute the Graph Laplacian Matrix

Description

laplacian_mat computes various forms of the graph Laplacian matrix for a given adjacency matrix W.

Usage

laplacian_mat(W, type = "unnormalized")

Arguments

W

Adjacency matrix (dense or sparseMatrix).

type

Character string, type of Laplacian matrix to compute. Can be "unnormalized" (default), "normalized", or "randomwalk".

Details

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.

Value

L The graph Laplacian matrix.

References

Chung, F. R. (1997). Spectral graph theory (Vol. 92). American Mathematical Soc.

Examples

# 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")

gasper documentation built on Oct. 27, 2023, 1:07 a.m.