Foundations to Frontier
Tests
J. Scientific Machine Learning › J3 Neural Differential Equations

Universal differential equations: known physics plus learned terms

Most real models are partly known. A universal differential equation (UDE) keeps the trusted terms of a differential equation and replaces only the unknown parts with a neural network, then trains the whole thing through an ODE solver. The network has far less to learn than in a pure neural ODE, needs less data, and its output can afterwards be turned back into a formula by sparse regression (SINDy), which is what makes extrapolation possible. This page follows the Lotka–Volterra example of Rackauckas et al. (2020). Growth of prey and death of predators are known; the interaction terms −0.9xy and 0.8xy are learned from 31 observations on t ∈ [0, 3]. With 1% noise, sparse regression on the trained network recovered exactly one term per equation, −0.88·xy and 0.79·xy. The recovered equation predicted t ∈ [3, 10] with RMS error 0.2, while the trained UDE network and a pure neural ODE, used directly, diverged (errors 30 and 10 against a signal RMS of 3.2). With 5% noise the recovery picked up spurious terms.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Keep what you know, learn what you don’t

Scientists rarely start from nothing. For rabbits and foxes we know that rabbits multiply and foxes die off when there is nothing to eat, but we may not know exactly how often foxes catch rabbits. A universal differential equation keeps the known parts of the rule and lets a neural network learn only the missing piece from data. Afterwards we can ask which simple formula the network learned, and often get back a clean law such as ‘catches are proportional to rabbits times foxes’. A formula like that can be trusted far outside the data, which a raw network cannot. The demo learns the missing interaction and reports its coefficient.

Neural differential equation lab
Lotka–Volterra prey (black) and predators (red), 0 ≤ t ≤ 20; dashed: the hybrid model whose interaction terms were learned from t ≤ 10. Learned xy coefficients: -0.499 (true −0.5) and 0.293 (true 0.3). Keeping the known physics leaves only a small function to learn.
Why engineers care

Hybrid models of this kind are used in climate models, where most of the physics is solved directly and only small-scale processes such as clouds are learned, and in pharmacology, where known drug kinetics are combined with learned patient responses.

📝 Quick check (Level 0)
0/3 answered
  1. 1. A universal differential equation learns…
  2. 2. Why convert the learned part to a formula?
  3. 3. In predator–prey models, the interaction term describes…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Form: dz/dt = f_known(z, t; p) + N_θ(z, t), or more generally f(z, N_θ(z), t) with the network inside a known structure (a closure, a rate law, a source term).
  • Training: exactly as a neural ODE (J3-1): solve, compare with data, differentiate through the solver (backprop, adjoint or forward sensitivities). Known parameters p can be learned jointly.
  • Why it helps: the network represents a lower-dimensional, simpler function; physical terms provide the right behaviour where data are missing; fewer data are needed.
  • From network to law: evaluate N_θ on the states visited and fit a sparse combination of candidate terms (polynomials, trigonometric functions) by sequentially thresholded least squares (SINDy, Brunton et al., 2016; J6-1). The result can be checked by experts and extrapolated.
  • Examples: missing interactions in ecology, unknown reaction rates, turbulence closures, learned subgrid terms in climate models (Rackauckas et al., 2020; Kochkov et al., 2021 for hybrid CFD).
  • Pitfalls: the network can absorb errors of the known part (identifiability); networks extrapolate poorly in state space; noise in data makes sparse recovery unreliable.
📝 Quick check (Level 1)
0/3 answered
  1. 1. A UDE is trained…
  2. 2. SINDy fits…
  3. 3. A UDE needs fewer data because…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Building a universal differential equation

Exercise 1.

  • A Lotka–Volterra field with known linear terms plus a small tanh network, and its vector–Jacobian products.
  • Multiple-shooting loss over segments and its gradient by backpropagation through RK4, checked by finite differences.
  • A polynomial library and sequentially thresholded least squares, tested on exact derivatives.

Practice.

  • Write down what you trust and keep it; put the network where the uncertainty is, with physically sensible inputs.
  • Constrain the network where physics says so (positivity, symmetries, zero at zero populations).
  • Train to a small error first, then recover: sparse regression on a poorly fitted network finds spurious terms.
  • Choose the library and threshold with care; scan thresholds and prefer models that are stable across noise draws and data subsets.
  • Validate the recovered law outside the training window and compare it with alternative candidate laws.
  • Tools: DiffEqFlux.jl and SciMLSensitivity.jl (the original UDE stack), DataDrivenDiffEq.jl, PySINDy, diffrax with Equinox, torchdiffeq.
import torch
from torchdiffeq import odeint

alpha, delta = 1.3, 1.8                                   # known growth and death rates
net = torch.nn.Sequential(torch.nn.Linear(2, 32), torch.nn.Tanh(), torch.nn.Linear(32, 2))

def ude(t, z):                                            # z = (prey, predators)
    known = torch.stack([alpha * z[..., 0], -delta * z[..., 1]], -1)
    return known + net(z / 2)

opt = torch.optim.Adam(net.parameters(), lr=1e-2)
for it in range(2000):
    pred = odeint(ude, y_obs[0], t_obs, method="rk4", options=dict(step_size=0.025))
    loss = ((pred - y_obs) ** 2).mean(); opt.zero_grad(); loss.backward(); opt.step()
# then: import pysindy as ps; ps.SINDy(feature_library=ps.PolynomialLibrary(2)).fit(states, x_dot=net(states))
🐍 Exercise 1: a hybrid field and sparse recovery
Write a Lotka–Volterra field with known linear terms plus a network, compute the multiple-shooting loss gradient through RK4 and check it, and recover the full equation from exact derivatives with sequentially thresholded least squares.
📝 Quick check (Level 2)
0/3 answered
  1. 1. A Python package for SINDy:
  2. 2. Before sparse recovery, the network should…
  3. 3. The original UDE software stack is in…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Why the network alone does not extrapolate. A trained network is accurate on the states it saw. In the exercise the training window t ∈ [0, 3] covers only part of the predator–prey cycle; beyond it the trajectory enters states the network never saw, its output is arbitrary there, and the integrated model left the cycle. The pure neural ODE, which must also learn the known terms, did the same. The recovered formula −0.88xy, by contrast, is defined everywhere and follows the cycle.

Sparse regression as model selection. Given samples of the learned term n_i = N_θ(z_i) and a library Θ(z), SINDy solves min ‖Θξ − n‖² with most ξ_j = 0, by alternating least squares and thresholding. It works when the library contains the true terms, the samples cover enough variety, and the target is accurate. In the exercise, 1% noise gave a network accurate enough for exactly −0.88·xy and 0.79·xy; with 5% noise the fitted network differed from the true term by more, and the regression added x, x² and y² terms with sizeable coefficients. A threshold that is too high removes true terms: on exact derivatives with threshold 1.0 every term was eventually dropped.

Identifiability. If the known part is wrong (say α is off), the network will absorb the difference and the recovered law will contain an extra x term. Learning α jointly and checking recovered terms against physical expectations guards against this.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The UDE network diverged beyond t = 3 because…
  2. 2. With 5% noise, sparse recovery…
  3. 3. If a known coefficient is wrong, the network…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

Can a hybrid model learn missing physics from three time units of data and recover a law that extrapolates?

History.

  • Hybrid ‘grey-box’ models combining mechanistic equations with neural networks date to the 1990s in chemical engineering (Psichogios and Ungar, 1992).
  • S. Brunton, J. Proctor and N. Kutz (2016) introduced SINDy for sparse identification of nonlinear dynamics.
  • C. Rackauckas et al. (2020), “Universal differential equations for scientific machine learning”, combined neural networks in differential equations with sparse recovery, using this Lotka–Volterra example.
  • D. Kochkov et al. (2021) and later NeuralGCM (2024) built hybrid fluid and climate models with learned corrections inside differentiable solvers.

Exercise 2. Lotka–Volterra x′ = 1.3x − 0.9xy, y′ = 0.8xy − 1.8y from (0.44, 4.6); 31 observations on [0, 3] with noise of 1% (or 5%) of each variable’s mean size. UDE: known 1.3x and −1.8y plus a width-16 tanh network; neural ODE: the same network alone. Both trained by multiple shooting with Adam (2000 iterations). Recovery: sequentially thresholded least squares (threshold 0.1) on the UDE network’s output over the training window, library x, y, x², xy, y². RMS errors from the true trajectory, states clipped to ±50; signal RMS on [3, 10] is 3.2.

model RMS on [0, 3] RMS on [3, 10]
UDE network 0.005 30
neural ODE 0.02 10
recovered equation 0.02 0.2
noise recovered term in x′ recovered term in y′
1% −0.88·xy 0.79·xy
5% −0.46·x + 0.27·x² + 0.43·xy − 0.11·y² 0.26·x − 0.31·x² + 0.78·xy
  • Inside the window everything fitted. The UDE network was the most accurate there.
  • Only the recovered law extrapolated. Both networks diverged once the trajectory left the states seen in training; the formula followed the cycle with error 0.2.
  • Recovery needs accurate fits. At 1% noise the coefficients were within 2.2% of the truth (8% at most across three seeds) with no extra terms; at 5% the recovered laws were wrong.
  • Seeds 1 and 2: the 1% recoveries were −0.88·xy, 0.74·xy and −0.88·xy, 0.77·xy, each again with RMS 0.2 on [3, 10]; at 5% noise both again contained spurious terms (for example 0.96·x − 0.49·x² − 4.09·xy in y′ on seed 1).
🐍 Exercise 2 (research): can a hybrid model learn missing physics from three time units of data and recover a law that extrapolates?
Train a universal differential equation and a pure neural ODE on three time units of predator–prey data, recover the learned interaction terms with sparse regression, and compare how far each model extrapolates.

Hybrid physics–ML models in practice

  • Climate and weather: NeuralGCM couples a differentiable dynamical core with learned physics; hybrid models learn subgrid closures for clouds and turbulence.
  • Pharmacology: pharmacokinetic compartments with learned absorption or response terms.
  • Batteries and energy: electrochemical models with learned degradation terms.
  • Spacecraft: orbit propagators with learned drag or solar-radiation-pressure corrections (J9-4).

References

  1. C. Rackauckas et al. (2020). “Universal differential equations for scientific machine learning.” arXiv:2001.04385.
  2. S. L. Brunton, J. L. Proctor and J. N. Kutz (2016). “Discovering governing equations from data by sparse identification of nonlinear dynamical systems.” PNAS.
  3. D. C. Psichogios and L. H. Ungar (1992). “A hybrid neural network–first principles approach to process modeling.” AIChE Journal.
  4. D. Kochkov et al. (2021). “Machine learning–accelerated computational fluid dynamics.” PNAS.
  5. D. Kochkov et al. (2024). “Neural general circulation models for weather and climate.” Nature.