Module contents
Lesson 2 of 30Core 100 min

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.

InteractivePaint a signal on the graph
123456

Número: nodo; azul indica señal negativa y rojo positiva. Grosor de arista: contribución ponderada a la energía; una línea discontinua tiene peso cero.

0.3
1.0
1.0
1.0
-1.0
-1.0
-1.0
Energy1.20
Mean0.00
Squared norm6.00
Adjust node values and the weight of the bridge. Each edge's thickness represents its weighted contribution. Compare a signal constant within each triangle with a signal that changes inside one triangle.

In the previous graph representation, an edge has endpoints and a weight. Here we assume a finite, simple, undirected, loop-free graph with weights wij=wji≥0w_{ij}=w_{ji}\ge 0. A zero-weight edge is treated as absent when discussing components. A signal is a vector x∈Rn\vb{x}\in\R^n, with xix_i at node ii.

Differences and energy

Let A\mat{A} be the weighted adjacency and di=∑jAijd_i=\sum_j A_{ij} the weighted strength; D=diag⁡(d1,…,dn)\mat{D}=\diag(d_1,\ldots,d_n). The combinatorial Laplacian is L=D−A\mat{L}=\mat{D}-\mat{A}. Its action is local:

(Lx)i=∑jwij(xi−xj).(\mat{L}\vb{x})_i=\sum_j w_{ij}(x_i-x_j).

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:

E(x)=∑{i,j}∈Ewij(xi−xj)2=x⊤Lx.\mathcal{E}(\vb{x})=\sum_{\{i,j\}\in E}w_{ij}(x_i-x_j)^2=\vb{x}\T\mat{L}\vb{x}.
Proof

Expand each square. Since Aij=AjiA_{ij}=A_{ji}, each term wijxi2w_{ij}x_i^2 appears in the degree sum for ii, and the cross term appears twice:

∑{i,j}∈Ewij(xi−xj)2=∑idixi2−∑i,jAijxixj=x⊤(D−A)x.\sum_{\{i,j\}\in E}w_{ij}(x_i-x_j)^2 =\sum_i d_i x_i^2-\sum_{i,j}A_{ij}x_ix_j =\vb{x}\T(\mat{D}-\mat{A})\vb{x}.

Every summand is nonnegative. Thus L\mat{L} is symmetric and positive semidefinite. Summing over all ordered pairs introduces a factor 1/21/2; 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 x⊤1=0\vb{x}\T\vb{1}=0 and ∥x∥2=1\norm{\vb{x}}_2=1. 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 0.30.3. Energy is 0.3(1−(−1))2=1.20.3(1-(-1))^2=1.2, the mean is zero and the squared norm is 6. Its Rayleigh quotient is 0.20.2. The spectral cell below calculates approximately 0.1751920.175192 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 e=(i,j)e=(i,j) of the incidence matrix B∈Rm×n\mat{B}\in\R^{m\times n} contains +1+1 at ii, −1-1 at jj and zeros elsewhere. Then (Bx)e=xi−xj(\mat{B}\vb{x})_e=x_i-x_j is a discrete gradient on the edge. If W\mat{W} is the diagonal matrix of weights, the incidence factorization is

L=B⊤WB,x⊤Lx=∥W1/2Bx∥22.\mat{L}=\mat{B}\T\mat{W}\mat{B},\qquad \vb{x}\T\mat{L}\vb{x}=\norm{\mat{W}^{1/2}\mat{B}\vb{x}}_2^2.

To verify the matrix identity, one row of B\mat{B} contributes we(ei−ej)(ei−ej)⊤w_e(\vb{e}_i-\vb{e}_j)(\vb{e}_i-\vb{e}_j)\T: it adds wew_e to both diagonal positions and subtracts wew_e from both off-diagonal positions. Reversing orientation changes that row’s sign without changing the product. Under this convention −B⊤-\mat{B}\T can be interpreted as divergence; L\mat{L} corresponds to the positive sign of −∇⋅∇-\nabla\cdot\nabla. 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 C1,…,CcC_1,\ldots,C_c are the components of the graph formed by positive-weight edges, then

ker⁡L=span⁡{1C1,…,1Cc},dim⁡ker⁡L=c.\ker \mat{L}=\operatorname{span}\{\vb{1}_{C_1},\ldots,\vb{1}_{C_c}\},\qquad \dim\ker\mat{L}=c.
Proof

Each indicator is constant along every positive-weight edge; on a zero-weight edge the difference vanishes when multiplied by W1/2\mat{W}^{1/2}. Thus W1/2B1Cr=0\mat{W}^{1/2}\mat{B}\vb{1}_{C_r}=0 and it belongs to the kernel. The indicators are independent because their supports are disjoint and nonempty. Conversely, if Lx=0\mat{L}\vb{x}=0, energy is zero. Since each summand is nonnegative and present edges have positive weights, xi=xjx_i=x_j along each positive edge; along a path, xx is constant on each component. It is a combination of the indicators. This includes an isolated node as a one-node component.

∎
InteractiveCut edges, create zeros
123456
Component indicators, written as node sets: {1,2,3,4,5,6}
06
Spectrum: 0.0000.4383.0003.0003.0004.562
Components1
Zero eigenvalues1
All active edges have weight 1. Disable the bridge between triangles and keep cutting. The line shows all eigenvalues; coincident points are stacked. Node sets are the supports of an indicator basis for the kernel.

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

Lsym=D−1/2LD−1/2,Lrw=D−1L.\mat{L}_{\mathrm{sym}}=\mat{D}^{-1/2}\mat{L}\mat{D}^{-1/2},\qquad \mat{L}_{\mathrm{rw}}=\mat{D}^{-1}\mat{L}.

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 I−D−1/2AD−1/2\mat{I}-\mat{D}^{-1/2}\mat{A}\mat{D}^{-1/2}, replace I\mat{I} by the projector onto positive-degree nodes. On the positive-degree subspace, Lrw=D−1/2LsymD1/2\mat{L}_{\mathrm{rw}}=\mat{D}^{-1/2}\mat{L}_{\mathrm{sym}}\mat{D}^{1/2}: they are similar, have the same real spectrum, and the random-walk right eigenvector is D−1/2\mat{D}^{-1/2} 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, Lrw1=0\mat{L}_{\mathrm{rw}}\vb{1}=0 and LsymD1/21=0\mat{L}_{\mathrm{sym}}\mat{D}^{1/2}\vb{1}=0. To see the second identity, substitute D−1/2D1/21=1\mat{D}^{-1/2}\mat{D}^{1/2}\vb{1}=\vb{1} into the definition and use L1=0\mat{L}\vb{1}=0. For several components, the same argument applies to their indicators, weighted by di\sqrt{d_i} 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 y=D−1/2x\vb{y}=\mat{D}^{-1/2}\vb{x} on positive-degree nodes. The energy is ∑{i,j}wij(yi−yj)2\sum_{\{i,j\}}w_{ij}(y_i-y_j)^2, which is nonnegative and, by (a−b)2≤2(a2+b2)(a-b)^2\le 2(a^2+b^2), does not exceed 2∑idiyi2=2∥x∥22\sum_i d_i y_i^2=2\norm{\vb{x}}^2 on that subspace. The spectral theorem places all eigenvalues of Lsym\mat{L}_{\mathrm{sym}} in [0,2][0,2]; isolated nodes add zeros. Eigenvalue 2 occurs if and only if some component with at least one edge is bipartite: equality requires yi=−yjy_i=-y_j on every edge, and a nonzero assignment of alternating signs exists exactly in that case.

InteractiveThree Laplacians on a star
123456123456node
Bars are scaled by the largest vector magnitude. Sign is arbitrary; with repeated values the basis is not unique either.
06
  • Other eigenvalues
  • Selected
Eigenvalues: 0.000 · 1.000 · 1.000 · 1.000 · 1.000 · 2.000.
Laplacian
6
Selected eigenvalue2.000
Maximum degree5
Connect two leaves to create a triangle. Choose the Laplacian and ordered eigenvector: the normalized operators share eigenvalues, but their right eigenvectors use different scales.

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, (−5,1,1,1,1,1)⊤(-5,1,1,1,1,1)\T has eigenvalue 6 for L\mat{L}: the center sums five differences of −6-6 and each leaf one difference of 6. For the symmetric normalized operator, (−5,1,1,1,1,1)⊤(-\sqrt{5},1,1,1,1,1)\T has eigenvalue 2. Mapping to the random-walk operator through D−1/2\mat{D}^{-1/2} gives a vector proportional to (−1,1,1,1,1,1)⊤(-1,1,1,1,1,1)\T. 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, P=D−1A\mat{P}=\mat{D}^{-1}\mat{A} is a row transition matrix and Lrw=I−P\mat{L}_{\mathrm{rw}}=\mat{I}-\mat{P}. Applied to a signal at a node, it subtracts the weighted average of its neighbors. By contrast, Lsym\mat{L}_{\mathrm{sym}} 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 hh, an interior node has four neighbors. There (Lx)i,j/h2=(4xi,j−xi−1,j−xi+1,j−xi,j−1−xi,j+1)/h2(\mat{L}\vb{x})_{i,j}/h^2=(4x_{i,j}-x_{i-1,j}-x_{i+1,j}-x_{i,j-1}-x_{i,j+1})/h^2, the five-point stencil for −Δ-\Delta. 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 xi,j=f(ih,jh)x_{i,j}=f(ih,jh) and ff has enough derivatives, Taylor expansion of the two neighbors on each axis cancels odd terms and leaves Lx/h2=−Δf+O(h2)\mat{L}\vb{x}/h^2=-\Delta f+O(h^2) in the interior. Without the factor h−2h^{-2}, 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 Q=D+A\mat{Q}=\mat{D}+\mat{A} satisfies x⊤Qx=∑{i,j}wij(xi+xj)2\vb{x}\T\mat{Q}\vb{x}=\sum_{\{i,j\}}w_{ij}(x_i+x_j)^2. 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 xi=−xjx_i=-x_j 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 +c+c to one part and −c-c to the other satisfies every edge. Again, an isolated node contributes a free coordinate to the kernel.

For directed graphs, symmetrizing A\mat{A} loses orientation. A magnetic Laplacian uses a complex Hermitian matrix to retain direction as phase. For a loop-free binary directed adjacency, define Sij=(Aij+Aji)/2S_{ij}=(A_{ij}+A_{ji})/2, θij=2πq(Aij−Aji)\theta_{ij}=2\pi q(A_{ij}-A_{ji}), Hij=SijeiθijH_{ij}=S_{ij}e^{\mathrm{i}\theta_{ij}} and L(q)=DS−H\mat{L}^{(q)}=\mat{D}_S-\mat{H}. The real parameter qq controls phase; Hji=Hij‾H_{ji}=\overline{H_{ij}}. Complex energy is ∑{i,j}Sij∣zi−eiθijzj∣2≥0\sum_{\{i,j\}} S_{ij}|z_i-e^{\mathrm{i}\theta_{ij}}z_j|^2\ge0. At q=0q=0 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.

[ ]Build B and the three LaplaciansBrowser
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) == components

In this sample, k=n−1k=n-1 recovers all zeros because there are fewer than nn components. This is not universal: if all nodes are isolated, eigsh with k<nk<n cannot return all eigenvalues. For large graphs, specify tolerances and distinguish a small value from an exact zero.

[ ]Normalizations and bipartitionBrowser
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 K1,4K_{1,4} has degrees (4,1,1,1,1)(4,1,1,1,1) and trace 88. The sum of its unnormalized eigenvalues is also 88, an independent check of their order.

Lab: grid and phase

[ ]Grid and five-point stencilBrowser
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, SS assigns weight 1/21/2 to each underlying direction and each node has degree 1. The discrete waves zj=e2πikj/4z_j=e^{2\pi\mathrm{i}kj/4} diagonalize the matrix and yield λk(q)=1−cos⁡(2π(q+k/4))\lambda_k(q)=1-\cos(2\pi(q+k/4)), for k=0,1,2,3k=0,1,2,3. Moving from q=0q=0 to q=0.1q=0.1 changes the spectrum. At q=0.25q=0.25 the accumulated phase around the four edges is 2π2\pi and the spectrum again matches that at q=0q=0. Phase carries directional information, but the spectrum alone need not identify orientation: reversing all edges conjugates the matrix and preserves its eigenvalues.

[ ]Magnetic Laplacian of a cycleBrowser
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

Proof
Prove: In an undirected graph with nonnegative weights, the Laplacian quadratic form is the sum of squared differences and is nonnegative.
0
Each unordered edge is counted exactly once.

Step 1 of 2. What results from expanding each square?

Proof
Prove: The dimension of the kernel of L is the number of positive-weight components.
0
Consider component indicators.

Step 1 of 2. Why does each indicator belong to the kernel?

Proof
Prove: Under the zero-isolate convention, the spectrum of the symmetric normalized L lies in [0,2].
0
For positive degrees write y_i = x_i / sqrt(d_i).

Step 1 of 2. Which inequality bounds each difference?

Numeric
For the star K_{1,4}, what is the largest eigenvalue of the unnormalized Laplacian?
Numeric
In K_{1,4}, what is the multiplicity of eigenvalue 1 of the unnormalized Laplacian?
Quiz
Under this lesson's convention, what happens at an isolated node when constructing the symmetric normalized Laplacian?
Code
Implement 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):
  pass
Shift+Enter to run

Key ideas

Key idea
The Laplacian turns local differences into a global quadratic form: its energy is a nonnegative sum, and its zeros are exactly the signals constant on each component.

Normalization changes node scales and places the spectrum in [0,2][0,2] under the stated convention for isolated nodes. Direction requires additional information, such as the complex phase of the magnetic Laplacian.