Functions
to_laplacian
Converts an adjacency matrix to a normalized Laplacian matrix.Adjacency matrix (will be converted to sparse CSR format)
csr_array - Normalized Laplacian matrix L = D^(-1/2) * A * D^(-1/2)
Details:
The normalized Laplacian is computed as:
to_adjacency
Converts edge list and vertices to a sparse adjacency matrix.Vertex array of shape (n_vertices, n_dims)
Edge array of shape (n_edges, 2) containing vertex indices
csr_array - Sparse adjacency matrix of shape (n_vertices, n_vertices)
Example:
label_propagation
Performs label propagation on a graph using the normalized Laplacian method.Adjacency matrix defining the graph structure
Initial label values for each node. Can be binary labels, soft labels, or continuous values.
Diffusion parameter controlling the influence of neighbors. Higher values (closer to 1) result in more smoothing.
np.ndarray - Propagated label values for each node
Details:
This function solves the linear system:
- I is the identity matrix
- L is the normalized Laplacian
- α is the diffusion parameter
- Y is the initial label vector
- F is the solution (propagated labels)
- Semi-supervised classification: Label a few nodes and propagate to unlabeled nodes
- Signal smoothing on graphs: Denoise signals defined on graph vertices
- Feature diffusion: Spread feature values across connected regions
alphaclose to 1.0 (e.g., 0.99): Strong smoothing, labels diffuse far across the graphalphaaround 0.5: Moderate smoothing, balanced between initial labels and neighborsalphaclose to 0.0: Weak smoothing, stays close to initial labels