Physics-Informed Neural Networks
The writeup of a talk I gave at TU München: putting a differential equation inside the loss function, and three solvers built that way, a damped oscillator (forward, then inverted for an unknown parameter) and the heat equation in 1D and 2D.
Most of machine learning learns a function from data and nothing else. A physics-informed neural network learns a function from data and from the differential equation that function is supposed to obey. You take the governing equation, move everything to one side so the true solution makes it zero, and add that residual to the loss. The network is then punished twice: once for disagreeing with your measurements, and once for disagreeing with physics.
I gave a talk on this at TU München in early 2025, walking through the theory and then building three solvers from scratch. This is the writeup of that talk. The slides, with all the plots, are linked at the end.
The idea: put the equation in the loss
A PINN is an ordinary neural network trained to satisfy a differential equation, not just to fit points. The whole trick lives in the loss, a weighted sum of two terms:
The data loss is ordinary supervised error against whatever you actually know: measurements, initial values, boundary values.
The physics loss is the part that earns the name. Write the equation as , so is its residual: plug the true solution in and you get zero. Now scatter a cloud of collocation points across the domain, evaluate the residual on the network's prediction at each one, and penalise it for being nonzero.
The derivatives inside come from automatic differentiation, the same machinery that computes gradients for training, turned on the inputs instead of the weights. No mesh, no finite differences: you get the equation's derivatives exactly, anywhere you ask. And collocation points are effectively free, since they carry no labels, only coordinates, so you can enforce the physics across the whole domain even where you have no data at all.
Application I: a damped harmonic oscillator
The cleanest place to start is an ODE with a closed form you can check against. The under-damped harmonic oscillator, with and :
I took , , , so and the system rings while it decays. The loss has three pieces: the ODE residual on the interior collocation points, and the two initial conditions pinned at .
A small network was enough: four layers, two of them hidden with 32 units each, activations, ADAM at a learning rate of for 25k epochs. The prediction lands on top of the analytic solution across the whole interval, decaying oscillation and all, trained from two boundary points and a scatter of unlabelled collocation points.
Turning it around: recovering a parameter you do not know
The forward problem is the boring half. The reason PINNs are interesting is that the same loss runs backwards. Suppose you do not know the damping , but you have some noisy measurements of the motion. Make a trainable parameter and hand it to the optimiser alongside the network weights:
In code this is almost anticlimactic, torch.optim.Adam(list(pinn.parameters()) + [mu], lr=1e-3). The network learns the trajectory that fits the noisy data while obeying the ODE, and to do that it has to settle on the value of that makes both terms small. Over training the estimate climbs and converges to the theoretical . The physics term acts as a regulariser strong enough to pull a physical constant back out of noisy data, using nothing but the same architecture with one extra scalar in the parameter list.
Application II: the heat equation
From an ODE to a PDE. The 1D heat equation,
with a cosine initial profile and insulating Neumann boundaries, at both ends. Neumann conditions are a nice stress test, because they constrain a derivative at the boundary, which for a PINN is just one more autodiff residual to drop into the loss, with no special treatment. A slightly larger network handled it: four hidden layers of 64 units, , 10k epochs, with 5000 interior collocation points plus 1000 on the boundaries and 1000 on the initial line. The absolute error against the analytic solution stays small across space and time, worst where the gradients are sharpest, exactly where you would expect.
Two dimensions, and where it starts to strain
The 2D heat equation is the same idea with one more Laplacian term,
again with Neumann boundaries on every side. Here I switched the activation to SiLU and added a learning-rate schedule (decay every 1000 steps), with 5000 collocation points and 5000 more each on the boundaries and the initial slice.
The interesting part was measuring where it fails. Instead of collapsing everything into one error number, I took the 2D Fourier transform of the error field,
to see which spatial frequencies the network was getting wrong. That is a far more honest diagnostic than a mean error: it shows the model smoothing over the high-frequency structure rather than failing uniformly, which points straight at the fix. A network carries a spectral bias toward low frequencies, and the error spectrum is where you catch it. More collocation points, another layer or two, or wider hidden layers, 128 units instead of 64, all buy the detail back.
What I took from it
PINNs are not a free lunch. Training is finicky, the loss weights genuinely matter, and a stiff or high-frequency problem will punish an undersized network. But the core move, that you can write a physical law as a residual and make a network respect it, is real, and the inverse problem is the part that sold me: recovering a physical constant from noisy data by insisting the answer obey the equation. That is the physicist's instinct, refusing a fit you cannot justify, written down as a loss function.
These were slides I presented at TU München on 29 January 2025. The full deck, with every plot and result, is here: Physics-Informed Neural Networks (PINNs): Theory and Applications in Computational Physics.
Cheers.