Fokker–Planck: the stationary density of an Ornstein–Uhlenbeck process
PINN fokker_planck_2d.py
A particle jitters under random kicks while a spring pulls it back to the origin. Where does it spend its time? The answer is a probability density, the stationary solution of the Fokker–Planck equation. A network learns it from the physics, a normalisation, and noisy boundary observations that are drawn fresh at every step.

The network's density \(p(x,y)\) during training, epochs 0 to 15 000, on the colour range \(0\) to the exact peak \(1/\pi\).
The problem
The 2-D Ornstein–Uhlenbeck process \(dX_t=-X_t\,dt+dW^{(1)}_t\), \(dY_t=-Y_t\,dt+dW^{(2)}_t\) has the stationary Fokker–Planck equation
with the exact solution \(p^\infty=e^{-(x^2+y^2)}/\pi\).
The jNO code
jno.np.vector(...) builds a vector from scalar components, so the drift divergence reads like the mathematics:
net = jno.nn(foundax.mlp(in_features=2, hidden_dims=64, num_layers=5, key=jax.random.PRNGKey(0)))
net.optimizer(
optax.chain( # clipping caps the occasional gradient spike of the stiff residual
optax.clip_by_global_norm(1.0),
optax.adam(optax.exponential_decay(1e-3, 2000, 0.5, end_value=1e-5)),
)
)
p = net(x, y).scalar.bind(x=x, y=y)
drift = jno.np.vector(x * p, y * p).div(x, y) # ∇·(b p) with drift b = (x, y)
fp = drift + 0.5 * (p.xx + p.yy) # = 0
.integrate() reduces \(p\) to \(\int_\Omega p\), so the normalisation is one term. jno.noise.gaussian(std=1e-4) is a
placeholder that draws a fresh array at every training step, a noisy measurement of the boundary values:
norm = p.integrate() - 1.0 # ∬ p dx dy = 1
bc = net(xb, yb) - (exp(-(xb**2 + yb**2)) / π + jno.noise.gaussian(std=1e-4)) # noisy boundary data
Result
After 15 000 Adam steps the density matches \(p^\infty\) to rel. \(L^2=2.3\times10^{-2}\) on the mesh nodes, with a peak of 0.313 against the exact \(1/\pi\approx0.318\). The peak forms between epochs 1000 and 5000.
Full script
The whole script, as it runs in the tests
"""2-D Fokker-Planck equation of an Ornstein-Uhlenbeck process on a disc, solved with a PINN."""
import foundax
import jax
import optax
import jno
run = jno.setup(__file__)
π, exp = jno.np.pi, jno.np.exp
d = jno.shape.disk(0, 0, 3.0, size=0.25).domain() # radius 3 holds the Gaussian's support
x, y, _ = d.variable("interior")
xb, yb, _ = d.variable("boundary")
p_exact = exp(-(x**2 + y**2)) / π
net = jno.nn(foundax.mlp(in_features=2, hidden_dims=64, num_layers=5, key=jax.random.PRNGKey(0)))
net.optimizer(
optax.chain( # clipping caps the occasional gradient spike of the stiff residual
optax.clip_by_global_norm(1.0),
optax.adam(optax.exponential_decay(1e-3, 2000, 0.5, end_value=1e-5)),
)
)
p = net(x, y).scalar.bind(x=x, y=y)
drift = jno.np.vector(x * p, y * p).div(x, y) # ∇·(b p) with drift b = (x, y)
fp = drift + 0.5 * (p.xx + p.yy) # = 0
norm = p.integrate() - 1.0 # ∬ p dx dy = 1
bc = net(xb, yb) - (exp(-(xb**2 + yb**2)) / π + jno.noise.gaussian(std=1e-4)) # noisy boundary data
crux = jno.core([fp.mse, norm.mse, bc.mse])
crux.solve(15_000)
p_h, p_ref = crux.eval([p, p_exact])
rel_l2 = float(jax.numpy.linalg.norm(p_h - p_ref) / jax.numpy.linalg.norm(p_ref)) # reference: e^-(x²+y²) / π
print(f"Relative L2 error: {rel_l2:.4e}")
assert rel_l2 < 3e-1, f"relative L2 error too large: {rel_l2:.3e}"