Graph Laplacians: energy, incidence and normalizations
Build the graph Laplacian from Dirichlet energy and an incidence factorization, prove its positive semidefiniteness and kernel characterization, and compare normalized, grid and directed versions.
After this lesson you can
- Prove the quadratic-form identity and deduce positive semidefiniteness.
- Factor the Laplacian using incidence and interpret discrete gradient and divergence.
- Show that zero-eigenvalue multiplicity counts connected components and describe the kernel.
- Relate combinatorial, symmetric normalized and random-walk Laplacians and bound normalized spectra.
- Construct a magnetic Laplacian for a directed graph and explain its directional information.
Before you start
A signal that changes between neighbors
Two communities are connected by a weak edge. A signal that is constant within each community but differs between them changes only across the bridge. If the bridge has low weight, the signal has low energy: a notion of smoothness that depends on relationships rather than position in a table. The figure shows each contribution before introducing a matrix.
In the previous graph representation, an edge has endpoints and a weight. Here we assume a finite, simple, undirected, loop-free graph with weights . A zero-weight edge is treated as absent when discussing components. A signal is a vector , with at node .
Differences and energy
Let be the weighted adjacency and the weighted strength; . The combinatorial Laplacian is . Its action is local:
At each node it sums differences with its neighbors. A constant is mapped to zero because all differences vanish. The signal’s Dirichlet energy is the sum over unordered edges, counted once each:
Proof
Expand each square. Since , each term appears in the degree sum for , and the cross term appears twice:
Every summand is nonnegative. Thus is symmetric and positive semidefinite. Summing over all ordered pairs introduces a factor ; this factor is unnecessary when each edge is counted once.
∎The constant signal always has zero energy. To seek a nonconstant low-energy signal, avoid the trivial solution by imposing and . In a connected graph with at least two nodes, the minimum of this quotient is the second eigenvalue and is attained by an associated eigenvector; we will study this next. In the figure, a signal that is nearly constant within each community is an intuitive candidate, but need not attain the minimum.
With the figure’s initial values, differences within each triangle are zero and the bridge has weight . Energy is , the mean is zero and the squared norm is 6. Its Rayleigh quotient is . The spectral cell below calculates approximately for the second eigenvalue of the same graph, so the initial signal illustrates a good candidate but is not exactly the minimizer. If the bridge is removed, the graph has two components and that signal has zero energy without being globally constant.
Incidence: discrete gradient and divergence
Choose an arbitrary orientation for each edge solely to construct the matrix. Row of the incidence matrix contains at , at and zeros elsewhere. Then is a discrete gradient on the edge. If is the diagonal matrix of weights, the incidence factorization is
To verify the matrix identity, one row of contributes : it adds to both diagonal positions and subtracts from both off-diagonal positions. Reversing orientation changes that row’s sign without changing the product. Under this convention can be interpreted as divergence; corresponds to the positive sign of . The chosen orientation is not a physical direction of an undirected edge.
The kernel counts components
The kernel and connected components have an exact relationship. If are the components of the graph formed by positive-weight edges, then
Proof
Each indicator is constant along every positive-weight edge; on a zero-weight edge the difference vanishes when multiplied by . Thus and it belongs to the kernel. The indicators are independent because their supports are disjoint and nonempty. Conversely, if , energy is zero. Since each summand is nonnegative and present edges have positive weights, along each positive edge; along a path, is constant on each component. It is a combination of the indicators. This includes an isolated node as a one-node component.
∎When an eigenvalue has multiplicity greater than one, a numerical routine may return orthonormal combinations of indicators. It need not choose one indicator per component, although those form a valid basis. Each eigenvector’s sign is arbitrary too.
Normalizing without dividing by zero
For positive degrees, the normalized Laplacians are
For an isolated node, take diagonal inverses as zero there: both matrices then have a zero row and column at that node. In the formula , replace by the projector onto positive-degree nodes. On the positive-degree subspace, : they are similar, have the same real spectrum, and the random-walk right eigenvector is times the symmetric one. The former is generally not symmetric; do not pass it to a solver that assumes symmetry.
On a component with no isolated nodes, and . To see the second identity, substitute into the definition and use . For several components, the same argument applies to their indicators, weighted by in the symmetric version. Under the chosen convention, isolated nodes have their own null indicators. Here too, the multiplicity of zero counts components.
To bound the spectrum, write on positive-degree nodes. The energy is , which is nonnegative and, by , does not exceed on that subspace. The spectral theorem places all eigenvalues of in ; isolated nodes add zeros. Eigenvalue 2 occurs if and only if some component with at least one edge is bipartite: equality requires on every edge, and a nonzero assignment of alternating signs exists exactly in that case.
The unnormalized star has a large eigenvalue because of its hub. The star is bipartite and its normalized operators attain 2; adding an edge between two leaves creates an odd cycle and the component ceases to be bipartite. With repeated eigenvalues, comparing individual eigenvector coordinates between solvers is unstable: compare their subspaces.
In the figure’s six-node star, has eigenvalue 6 for : the center sums five differences of and each leaf one difference of 6. For the symmetric normalized operator, has eigenvalue 2. Mapping to the random-walk operator through gives a vector proportional to . The figure rescales each vector by its largest magnitude to show its shape; it does not compare their original norms.
The distinction between the two normalizations also has an operational interpretation. With positive degrees, is a row transition matrix and . Applied to a signal at a node, it subtracts the weighted average of its neighbors. By contrast, distributes normalization between source and destination and preserves Euclidean symmetry. Equal eigenvalues do not imply equal entries or eigenvectors. Walk dynamics and the distribution convention are treated separately in the diffusion lesson.
Grid and direction
In a square grid with spacing , an interior node has four neighbors. There , the five-point stencil for . At the boundary, the graph Laplacian uses only present neighbors: the boundary condition is not automatically the same as a Dirichlet discretization. See finite differences.
If and has enough derivatives, Taylor expansion of the two neighbors on each axis cancels odd terms and leaves in the interior. Without the factor , the matrix is dimensionless when the signal is: changing resolution without changing that scale does not approximate the same continuous operator. At the boundary, imposing Dirichlet conditions can require fixing external values or restricting the system instead of simply using the finite graph’s degree.
The signless Laplacian satisfies . Its kernel detects signals that alternate signs across edges, related to bipartition.
The equality follows by expanding the sum as before, but the cross term is now positive. In a connected component with edges, zero energy requires on every edge. If there is an odd cycle, traversing it returns to the starting node with the opposite sign and forces its value to zero; if the component is bipartite, assigning to one part and to the other satisfies every edge. Again, an isolated node contributes a free coordinate to the kernel.
For directed graphs, symmetrizing loses orientation. A magnetic Laplacian uses a complex Hermitian matrix to retain direction as phase. For a loop-free binary directed adjacency, define , , and . The real parameter controls phase; . Complex energy is . At this becomes the Laplacian of the symmetrized graph; phases around cycles can encode information discarded by symmetrization alone. MagNet uses this construction for directed graphs.
Lab: incidence and sparse spectrum
Each undirected edge appears once in edges. We add an isolated node to the two triangles and verify the energy identity and SciPy conventions. Code indices start at zero.
import numpy as np
import networkx as nx
from scipy import sparse
from scipy.sparse.csgraph import laplacian as scipy_laplacian, connected_components
from scipy.sparse.linalg import eigsh
n = 7
edges = [(0,1,1.0),(1,2,1.0),(2,0,1.0),
(3,4,1.0),(4,5,1.0),(5,3,1.0),(2,3,0.3)]
u = np.array([a for a,b,w in edges])
v = np.array([b for a,b,w in edges])
weights = np.array([w for a,b,w in edges])
rows = np.repeat(np.arange(len(edges)), 2)
cols = np.column_stack([u,v]).ravel()
B = sparse.coo_matrix((np.tile([1.0,-1.0],len(edges)), (rows,cols)), shape=(len(edges),n)).tocsr()
A = sparse.coo_matrix((np.r_[weights,weights], (np.r_[u,v],np.r_[v,u])), shape=(n,n)).tocsr()
degree = np.asarray(A.sum(axis=1)).ravel()
L = sparse.diags(degree) - A
inverse = np.divide(1.0, degree, out=np.zeros_like(degree), where=degree>0)
inv_sqrt = np.sqrt(inverse)
Lsym = sparse.diags(inv_sqrt) @ L @ sparse.diags(inv_sqrt)
Lrw = sparse.diags(inverse) @ L
assert np.allclose(L.toarray(), (B.T @ sparse.diags(weights) @ B).toarray())
assert np.allclose(L.toarray(), scipy_laplacian(A).toarray())
assert np.allclose(Lsym.toarray(), scipy_laplacian(A, normed=True).toarray())
x = np.random.default_rng(3).normal(size=n)
energy = np.sum(weights * (x[u]-x[v])**2)
assert np.allclose(x @ L @ x, energy)
values = np.sort(eigsh(L, k=n-1, which='SM', return_eigenvectors=False))
components = connected_components(A, directed=False, return_labels=False)
print('energía:', round(energy, 6), 'componentes:', components)
print('autovalores pequeños:', np.round(values, 6).tolist())
print('ceros encontrados:', int(np.sum(np.abs(values)<1e-8)))
assert np.sum(np.abs(values)<1e-8) == componentsIn this sample, recovers all zeros because there are fewer than components. This is not universal: if all nodes are isolated, eigsh with cannot return all eigenvalues. For large graphs, specify tolerances and distinguish a small value from an exact zero.
G = nx.star_graph(4)
Ag = nx.to_scipy_sparse_array(G, nodelist=range(5), format='csr', dtype=float)
dg = np.asarray(Ag.sum(axis=1)).ravel()
Lg = sparse.diags(dg) - Ag
ig = 1 / np.sqrt(dg)
Sg = sparse.diags(ig) @ Lg @ sparse.diags(ig)
print('estrella L:', np.round(np.linalg.eigvalsh(Lg.toarray()), 6).tolist())
print('estrella normalizada:', np.round(np.linalg.eigvalsh(Sg.toarray()), 6).tolist())
assert np.allclose(np.linalg.eigvalsh(Lg.toarray()), [0,1,1,1,5])
assert np.isclose(np.linalg.eigvalsh(Sg.toarray())[-1], 2)The star has degrees and trace . The sum of its unnormalized eigenvalues is also , an independent check of their order.
Lab: grid and phase
side = 4
grid = nx.grid_2d_graph(side, side)
nodes = [(i,j) for i in range(side) for j in range(side)]
Ag = nx.to_numpy_array(grid, nodelist=nodes)
Lg = np.diag(Ag.sum(axis=1)) - Ag
field = np.arange(side*side, dtype=float).reshape(side,side)**2
applied = (Lg @ field.ravel()).reshape(side,side)
i, j = 1, 2
stencil = 4*field[i,j]-field[i-1,j]-field[i+1,j]-field[i,j-1]-field[i,j+1]
assert np.isclose(applied[i,j], stencil)
print('interior:', applied[i,j], 'esténcil:', stencil)The next cell uses a directed four-node cycle. In each case the matrix is Hermitian and its eigenvalues are real; the phase comparison illustrates the construction, rather than a MagNet benchmark result.
For this particular cycle, assigns weight to each underlying direction and each node has degree 1. The discrete waves diagonalize the matrix and yield , for . Moving from to changes the spectrum. At the accumulated phase around the four edges is and the spectrum again matches that at . Phase carries directional information, but the spectrum alone need not identify orientation: reversing all edges conjugates the matrix and preserves its eigenvalues.
directed = np.zeros((4,4))
for i in range(4):
directed[i,(i+1)%4] = 1
S = (directed + directed.T) / 2
for q in [0.0, 0.1, 0.25]:
phase = 2*np.pi*q*(directed-directed.T)
H = S*np.exp(1j*phase)
magnetic = np.diag(S.sum(axis=1))-H
assert np.allclose(magnetic, magnetic.conj().T)
spectrum = np.linalg.eigvalsh(magnetic)
assert spectrum.min() > -1e-10
closed = np.sort([1-np.cos(2*np.pi*(q+k/4)) for k in range(4)])
assert np.allclose(spectrum, closed)
print('q:', q, 'espectro:', np.round(spectrum, 6).tolist())Exercises
Step 1 of 2. What results from expanding each square?
Step 1 of 2. Why does each indicator belong to the kernel?
Step 1 of 2. Which inequality bounds each difference?
laplacian(edge_index, edge_weight, n, normalization). Edges contain both directions, weights are nonnegative and symmetric, and there are no self-loops. Return CSR for normalization equal to 'none', 'sym' or 'rw'; use zero inverses for zero degrees.import numpy as np
from scipy import sparse
def laplacian(edge_index, edge_weight, n, normalization):
passKey ideas
Normalization changes node scales and places the spectrum in under the stated convention for isolated nodes. Direction requires additional information, such as the complex phase of the magnetic Laplacian.