22 Lab 06 — Sheaf Diffusion
Anchor chapter: Chapter 6 — Sheaf Diffusion: Heat Equations and Convergence.
Goal. Integrate the sheaf heat equation \(\dot{x} = -\mathcal{L}_\mathcal{F} x\), plot \(\|\delta x_t\|^2\) on a semi-log scale, and verify the predicted convergence rate.
Implement the full sheaf heat equation for a fixed sheaf: compute the restricted Laplacian \(\mathcal{L}_\mathcal{F}[\Omega,\Omega]\), run the forward Euler iteration (6.3), and track total discord and per-edge discord over time. Apply this to three cases: (1) the constant sheaf on a path (should reproduce Ch. 2 linear interpolation), (2) the three-agent discourse sheaf (watch the middle agent converge to the harmonic extension), (3) a fixed-weight [2, 4, 1] neural sheaf (reproduce Figure 6a of Bosca–Ghrist). In case (3), also plot the output stalk trajectory and verify it converges to the forward pass value. This is the smooth baseline for the switching dynamics of Chs. 9–10.
This lab requires only NumPy, Matplotlib, and SciPy, loaded automatically via Pyodide. Code cells run directly in the page via WebAssembly — no local Python installation needed.
Prefer a local Jupyter environment? Download lab-06-sheaf-diffusion.ipynb
22.1 Setup
22.2 1. Build the object
We build three sheaves inline (without importing Lab 04) and assemble their coboundary matrices directly. The constant \(\mathbb{R}^1\) sheaf on a 5-vertex path has \(\delta\) equal to the standard signed incidence matrix; its sheaf heat equation reduces to the ordinary graph heat equation from Lab 02. The discourse sheaf and the neural sheaf extend this to block-valued cochains. In each case we compute \(\mathcal{L}_\mathcal{F}[\Omega,\Omega] = \delta_\Omega^\top \delta_\Omega\) for the free (non-pinned) vertices, together with the boundary forcing term needed for the Euler integration.
22.3 2. Verify a theorem / run an experiment
The sheaf heat equation \(\dot{x}_\Omega = -\mathcal{L}_\mathcal{F}[\Omega,\Omega]\, x_\Omega + \text{boundary}\) drives the total discord \(\|\delta x_t\|^2\) to zero at rate \(e^{-2\lambda_{\min} t}\), where \(\lambda_{\min}\) is the smallest eigenvalue of \(\mathcal{L}_\mathcal{F}[\Omega,\Omega]\). The semi-log plots below confirm this exponential envelope for all three sheaves. For the neural sheaf (case 3), the output stalk converges to the value of the forward pass \(f(x)\), confirming Proposition 3.4 in the fixed-activation-pattern (smooth) regime.
22.4 Exercises
Rate vs. architecture. Fix the weight matrices and vary the network depth: build neural sheaves for [2,2,1], [2,4,1], [2,8,1]. Compute \(\lambda_{\min}(\mathcal{L}_\mathcal{F}[\Omega,\Omega])\) for each and plot convergence speed vs. hidden-layer width.
Per-edge discord. Instead of the total discord, track the per-edge discord \(\|(\delta x_t)_{e_\ell}\|^2\) for each edge of the neural sheaf. Which edge converges fastest and which slowest? Does this depend on the weight magnitudes?
Discourse sheaf: all agents free. Remove the pinning conditions and integrate the unconstrained heat equation \(\dot{x} = -\mathcal{L}_\mathcal{F} x\) for the discourse sheaf. Show that the cochain converges to a global section (element of \(\ker \mathcal{L}_\mathcal{F}\)).
Backward-Euler stability. The forward-Euler step size is limited by \(\Delta t < 1/\lambda_{\max}\). Implement backward Euler (requiring a linear solve at each step) and verify that it is unconditionally stable: use \(\Delta t = 10/\lambda_{\max}\) and confirm the discord still decreases monotonically.