Physics-Based Machine Learning

Discovering equations from data (SINDy), encoding PDEs into a loss function (PINNs), and taming a vortex wake with reinforcement learning — a tour of the marriage between ML and physics.

Why inject physics into ML?

"Pure" deep learning assumes data is abundant and cheap. In science and engineering it rarely is: a finite-element simulation of a turbulent flow costs hours of high-performance computing, and an experimental campaign is measured in weeks. On the other hand, we hold an asset computer vision does not: centuries of physical laws — conservation of mass, momentum and energy, symmetries, invariances.

Physics-based (or physics-informed) machine learning exploits these laws as inductive biases: they constrain the hypothesis space, shrink the data requirement, and yield models that generalize beyond the training sample. Three strategies dominate:

  • Discover physics from data — sparse regression over a library of terms (SINDy);
  • Enforce physics during training — a PDE residual inside the loss function (PINNs);
  • Exploit system structure — modal decompositions (POD, DMD), the Koopman operator, and reduced-order models for control and RL.
This is the through-line of Brunton & Kutz: complex systems exhibit dominant low-dimensional structure, and the right coordinate transform — learned from data — makes the dynamics simple, sometimes even linear.

SINDy: discovering the equations of motion

Suppose we measure a trajectory \(\mathbf{x}(t) \in \mathbb{R}^n\) of an unknown system \(\dot{\mathbf{x}} = f(\mathbf{x})\). The idea behind SINDy (Sparse Identification of Nonlinear Dynamics): if \(f\) contains only a few terms from a library of candidates \(\Theta(\mathbf{X}) = [\,1,\ \mathbf{x},\ \mathbf{x}^2,\ \mathbf{x}\otimes\mathbf{x},\ \sin \mathbf{x},\ \ldots\,]\), then identifying the dynamics reduces to sparse regression: \[\dot{\mathbf{X}} \approx \Theta(\mathbf{X})\,\Xi, \qquad \Xi = \arg\min_{\Xi'} \big\|\dot{\mathbf{X}} - \Theta(\mathbf{X})\,\Xi'\big\|_2^2 + \lambda \|\Xi'\|_0.\] In practice one solves via sequentially thresholded least squares: regress, zero out small coefficients, repeat. The result is not a black box but a readable equation.

Animation 1. Left, a trajectory of the Lorenz system is traced out (\(x\)–\(z\) projection). Right, the library coefficients \(\Xi\): thresholding passes prune spurious terms until only the exact structure remains — \(\dot{x} = \sigma(y-x)\), \(\dot{y} = x(\rho - z) - y\), \(\dot{z} = xy - \beta z\).
The sparsity–accuracy trade-off is a Pareto front: \(\lambda\) plays the role of Occam's razor. It is the same philosophy as model selection via information criteria (AIC/BIC) in statistics.

PINNs: physics as regularization

A physics-informed neural network (PINN) approximates the solution \(u(x,t)\) of a PDE \(\mathcal{N}[u] = 0\) with a network \(u_\theta\), trained by minimizing a composite loss: \[\mathcal{L}(\theta) = \underbrace{\frac{1}{N_d}\sum_{i} \big|u_\theta(x_i, t_i) - u_i\big|^2}_{\text{data \& conditions}} \;+\; \underbrace{\frac{\lambda}{N_r}\sum_{j} \big|\mathcal{N}[u_\theta](x_j, t_j)\big|^2}_{\text{PDE residual}}.\] The second term is evaluated by automatic differentiation — the same machinery that computes training gradients delivers \(\partial_t u_\theta\), \(\partial_{xx} u_\theta\), and so on, mesh-free. The physics acts as a regularizer: even with very few measurement points, the solution is "pulled" onto the manifold of admissible solutions.

Animation 2. A damped oscillator \(\ddot{u} + 2\zeta\omega\dot{u} + \omega^2 u = 0\): with only four observations (yellow dots), the data loss alone would leave the network unconstrained between points; the physics residual (red bar) forces the blue curve to hug the true solution (dashed).

Reduced-order models: POD, DMD, Koopman

A discretized velocity field lives in dimension \(10^5\) to \(10^8\), yet its dynamics often unfold on a low-dimensional manifold. POD (proper orthogonal decomposition, i.e. the SVD of snapshots) extracts the energetically dominant modes \(\Phi\), and a Galerkin projection of the Navier–Stokes equations onto \(\Phi\) yields a small ODE system — fast enough for real-time control.

DMD instead seeks the best linear operator \(A\) with \(\mathbf{x}_{k+1} \approx A\,\mathbf{x}_k\): each mode carries its own frequency and growth rate — ideal for isolating the vortex-shedding frequency of a wake. It can be read as a finite-dimensional approximation of the Koopman operator \(\mathcal{K}\), which makes the dynamics linear by acting on observables: \(\mathcal{K}g(\mathbf{x}) = g(F(\mathbf{x}))\). Finding good Koopman coordinates — possibly with an autoencoder — pulls a nonlinear problem back into the realm where LQR, Kalman filtering and all of linear theory apply.

MethodWhat is learnedStrengthLimitation
SINDySparse symbolic ODEInterpretabilityLibrary choice
PINNPDE solution \(u_\theta(x,t)\)Data-efficient, mesh-freeTricky training
POD–GalerkinModal basis + reduced ODESpeed, physical groundingFragile off-regime
DMD / KoopmanLinear evolution operatorSpectral analysis, forecastingStrongly nonlinear dynamics
RL (HydroGym)Control policy \(\pi_\theta\)Model-free, nonlinearSimulation cost

Case study: flow control with HydroGym

The canonical test bench of flow control is the cylinder wake. Beyond a critical Reynolds number (\(\mathrm{Re} \approx 47\)), the flow becomes unstable and a von Kármán vortex street sheds periodically, increasing drag and inducing vibrations. The control problem: act (via cylinder rotation or blowing/suction jets) using a handful of pressure sensors to stabilize the wake.

This is precisely an MDP — partial state, continuous actions, reward = drag reduction — and this is where HydroGym comes in: a platform exposing dozens of fluid-mechanics environments (cylinder, fluidic pinball, cavity, backward-facing step, NACA airfoils, turbulent boundary layers) behind the standard Gymnasium interface, with multiple solvers (Firedrake finite elements, lattice Boltzmann, spectral elements, differentiable JAX solvers) and MPI coupling for HPC. You can therefore plug Stable-Baselines3's PPO or SAC into a Navier–Stokes simulation just as you would into CartPole.

Animation 3. Von Kármán vortex street behind a cylinder (advected tracers, Manim style). Toggle the control to emulate a trained RL policy: the vortices die down, the wake symmetrizes, and the drag indicator \(C_D\) drops. This is the typical objective of HydroGym's cylinder environments.

A training skeleton, faithful to the project's API:

# Cylinder wake control: standard Gymnasium interface
import gymnasium as gym
import hydrogym
from stable_baselines3 import PPO

env = gym.make("HGym/Cylinder-medium-v0")   # Navier–Stokes, Re = 100
model = PPO("MlpPolicy", env, gamma=0.99)
model.learn(total_timesteps=500_000)         # reward ≈ −(drag + actuation penalty)

obs, info = env.reset()
for _ in range(1000):
    action, _ = model.predict(obs)           # cylinder rotation / jets
    obs, reward, terminated, truncated, info = env.step(action)
Where the physics comes back. "Raw" RL on a CFD solver is expensive: every environment step is a PDE solve. Reduced-order models (POD–Galerkin, DMD) accelerate training by providing surrogate simulators; Koopman coordinates linearize the control problem; and differentiable solvers let you backpropagate through the physics. The loop closes: discover, reduce, control.

Synthesis and outlook

Physics-based ML does not pit data against equations: it composes them. SINDy turns trajectories into laws; PINNs turn laws into regularization; reduced-order models turn gigantic fields into tractable dynamics; RL closes the loop by acting on the system. The same tools travel far beyond fluids — epidemiology, finance (where Black–Scholes-type PDEs play the role of Navier–Stokes), hydrology, or precision agriculture.

For the reinforcement side of this story — Bellman equations, Q-learning, policy gradients — see the companion article on reinforcement learning.

References. S. Brunton & J. N. Kutz, Data-Driven Science and Engineering (2nd ed.), ch. 7 (DMD, SINDy, Koopman), ch. 12–13 (reduced-order models) and ch. 14 (physics-informed ML: SINDy autoencoders, Koopman forecasting, neural operators, PINNs); the HydroGym project (dynamicslab) for RL applied to flow control.