“The Laplacian captures the ‘flow of flow’ — the ultimate second-derivative. In physics: heat. In ML: smoothness, diffusion, and curvature.”
For a 2D vector field :
Divergence:
(How much “outflow” from a point.)
Curl:
(Local “rotation” of the field.)
Laplacian: For scalar field :
(Sum of 2nd derivatives; a “curvature” operator.)
Operator | ML Example |
---|---|
Laplacian | Smoothing, diffusion models, graph Laplacian, loss regularization, spectral clustering |
Divergence | Generative flows, conservation laws |
Curl | Detecting cycles/rotation in flows, e.g. GAN training dynamics |
The heat equation in 2D:
where is the diffusion constant, and is the Laplacian.
Discretized: We can approximate the Laplacian with a convolution kernel:
# calc-11-div-curl-laplace/heat_equation_demo.py
import numpy as np
import matplotlib.pyplot as plt
from scipy.ndimage import convolve
N = 64
D = 0.15 # diffusion constant
steps = 80
# Laplacian kernel for 2D grid
kernel = np.array([[0, 1, 0],
[1, -4, 1],
[0, 1, 0]])
# Initial "hot spot" in center
u = np.zeros((N, N))
u[N//2, N//2] = 10.0
# For plotting
fig, axs = plt.subplots(2, 4, figsize=(12, 6), sharex=True, sharey=True)
plot_steps = np.linspace(0, steps-1, 8, dtype=int)
for s in range(steps):
lap = convolve(u, kernel, mode="constant")
u += D * lap
if s in plot_steps:
ax = axs.flat[list(plot_steps).index(s)]
im = ax.imshow(u, vmin=0, vmax=10, cmap="hot")
ax.set_title(f"step {s}")
plt.colorbar(im, ax=axs.ravel().tolist(), shrink=0.85)
plt.suptitle("2D Heat Equation Evolution (Diffusion of Hot Spot)")
plt.tight_layout(rect=[0,0,1,0.96])
plt.show()
Put solutions in calc-11-div-curl-laplace/
and tag v0.1
.
Next: Calculus 12 — ODEs, Gradient Flows, and Neural Dynamics.