PINNs step by step: one point, two points, three points…
What really happens inside a physics-informed neural network? We shrink everything until it fits on paper — one neuron, two collocation points, one iteration written out in numbers — and then grow it back, watching what changes.
A PINN is a flexible curve (a network) that we bend until it obeys an equation at some chosen points. If we check the equation at only one or two points, many wrong curves pass the check. As we add points, the wrong curves are ruled out one by one, and only the true solution survives. Everything else — layers, learning rate, Adam — is about bending the curve efficiently.
- the PINN recipe with every intermediate step written out;
- what a network does when fitting $y = x^2$ from 1, 2, 3, 4… points;
- what a PINN does when solving $y' = x$ with 1, 2, 3… collocation points — and why few points give wrong answers with zero loss;
- one complete PINN iteration by hand: forward pass, derivative, residual, loss, gradient, update;
- parameters versus hyperparameters, and a practical list of hyperparameters for PINNs;
- what "deep" means, and how to count parameters.
1. The PINN recipe, with nothing skipped
Problem: find $y(x)$ on $[0,1]$ with $y'(x) = x$ and $y(0) = 0$. (Exact answer: $y = x^2/2$. We pretend not to know it.)
- Choose a network $u_\theta(x)$: a formula with adjustable numbers $\theta$ (weights and biases). Before training it is a random curve.
- Choose collocation points $x_1,\dots,x_N$ in $[0,1]$ — places where we will check the equation. They are just numbers; no measurements are needed.
- Forward pass: compute $u_\theta(x_j)$ at every collocation point, and $u_\theta(0)$.
- Differentiate the network with respect to its input (automatic differentiation, Chapter 14) to get $u_\theta'(x_j)$.
- Residual: how badly the equation fails at each point, $r_j = u_\theta'(x_j) - x_j$. For the true solution all $r_j = 0$.
- Loss: $\displaystyle \mathcal L(\theta) = \frac1N\sum_{j=1}^{N} r_j^2 + \lambda\,\big(u_\theta(0) - 0\big)^2$ — equation misfit plus initial-condition misfit, weighted by $\lambda$.
- Backward pass: compute $\partial\mathcal L/\partial\theta$ for every weight (backpropagation through the derivative of step 4).
- Update: $\theta \leftarrow \theta - \eta\,\partial\mathcal L/\partial\theta$ (or Adam).
- Repeat steps 3–8 until the loss is tiny. The trained $u_\theta(x)$ is the approximate solution — defined for every $x$, not just at the points.
2. Warm-up without physics: fit $y = x^2$ from a few points
First the plain, data-only case. We give a network some points $(x_i, x_i^2)$ on $[-1,1]$ and minimise the mean squared error.

- 1 point $(0.5, 0.25)$: infinitely many curves pass through one point. The loss can be made exactly zero by the constant $u = 0.25$, or a line, or anything. The network returns one of them, chosen by its random start.
- 2 points: still infinitely many curves. Training error zero, test error large.
- 3 points: a parabola through 3 points is unique — but a network is not a parabola. A 16-neuron network has 49 parameters, far more than 3 equations, so it can still wiggle between points.
- Many points: the wiggles are squeezed out; all three networks agree. Their smooth tanh building blocks (their inductive bias) also help.
$N$ data points give $N$ equations $u_\theta(x_i) = y_i$. A network has $P$ unknowns (parameters). If $P > N$ (almost always!), the equations alone do not determine the weights. What we get depends on the starting weights, the optimiser and the architecture. This is why "zero training loss" proves very little.
3. Now with physics: solve $y' = x$ from a few collocation points

Why do few points fail? Because wrong functions can have zero loss:
| collocation points | what the loss demands | a wrong function with loss exactly 0 | its error |
|---|---|---|---|
| $\{0.5\}$ | $u(0) = 0$, $u'(0.5) = 0.5$ | $u(x) = x/2$ | at $x = 0.5$: $0.25$ instead of $0.125$ |
| $\{0, 1\}$ | $u(0) = 0$, $u'(0) = 0$, $u'(1) = 1$ | $u(x) = x^3/3$ (then $u' = x^2$) | at $x = 1$: $0.333$ instead of $0.5$ |
| $\{0, 0.5, 1\}$ | $u(0) = 0$ and $u' = x$ at three points | $u' = x + c\,x(x - 0.5)(x - 1)$ for any $c$ | grows with $c$ |
| many, spread over $[0,1]$ | $u' = x$ almost everywhere | only functions close to $x^2/2$ | small |
A finite set of points never pins down the solution mathematically; in practice, a smooth network trained on enough well-spread points behaves like the true solution between them. How many is "enough" depends on how wiggly the solution is — the PINN version of choosing a mesh size.
Finite differences with 2 grid points cannot resolve a curve either. Collocation points play the role of the grid: they decide where the equation is enforced. Unlike a grid, they can be scattered randomly and moved during training.
4. One complete PINN iteration, in numbers
Smallest possible network: one hidden neuron, $$u(x) = a\,\tanh(w x + b) + c,\qquad \text{so}\quad u'(x) = a\,w\,\big(1 - \tanh^2(wx + b)\big).$$ Four parameters $\theta = (a, w, b, c)$, starting at $a = 1$, $w = 1$, $b = 0$, $c = 0$. Collocation points $x_1 = 0.5$, $x_2 = 1$; $\lambda = 1$; plain gradient descent with $\eta = 0.1$.
Step 3 — forward pass. $u(0) = \tanh 0 = 0$, $\;u(0.5) = \tanh 0.5 = 0.4621$, $\;u(1) = \tanh 1 = 0.7616$.
Step 4 — derivative w.r.t. the input (here by the formula; a library would use autodiff): $u'(0.5) = 1 - 0.4621^2 = 0.7864$, $\;u'(1) = 1 - 0.7616^2 = 0.4200$.
Step 5 — residuals $r = u' - x$: $\;r_1 = 0.7864 - 0.5 = 0.2864$, $\;r_2 = 0.4200 - 1 = -0.5800$.
Step 6 — loss. $\mathcal L = \tfrac12(0.2864^2 + 0.5800^2) + 1\cdot(0 - 0)^2 = \tfrac12(0.0821 + 0.3364) = 0.2092$.
Step 7 — gradient (what backpropagation returns; checked against finite differences): $$\frac{\partial\mathcal L}{\partial a} = -0.0183,\quad \frac{\partial\mathcal L}{\partial w} = 0.2486,\quad \frac{\partial\mathcal L}{\partial b} = 0.1628,\quad \frac{\partial\mathcal L}{\partial c} = 0.$$ For example $\dfrac{\partial\mathcal L}{\partial a} = \dfrac1N\sum_j 2r_j\,\dfrac{\partial u'(x_j)}{\partial a} = \dfrac12\big[2(0.2864)(0.7864) + 2(-0.5800)(0.4200)\big] = -0.0183$, using $\partial u'/\partial a = w(1-\tanh^2) = u'/a$. ($\partial\mathcal L/\partial c = 0$ because $u'$ does not depend on $c$ and the initial-condition error is already $0$.)
Step 8 — update. $a \leftarrow 1 - 0.1(-0.0183) = 1.0018$, $\;w \leftarrow 1 - 0.1(0.2486) = 0.9751$, $\;b \leftarrow 0 - 0.1(0.1628) = -0.0163$, $\;c$ unchanged.
Check. With the new weights the loss is $0.2006$ — smaller than $0.2092$. One iteration done. A real PINN repeats this thousands of times with thousands of weights; the lab below shows the same table, live.
$u'(x) = aw(1-\tanh^2(wx+b))$ is a bump, never a straight line, so one neuron can never make $u' = x$ exactly on $[0,1]$. It can only make the residual small at the two chosen points. More neurons = more flexible $u'$ — try it in the lab.
5. Lab: tiny PINN, every number visible
6. Parameters and hyperparameters
Parameters are the numbers the training learns — weights and biases. Hyperparameters are the choices you make before training, which training does not change. For PINNs:
| hyperparameter | what it is | typical starting choice | effect if badly chosen |
|---|---|---|---|
| width | neurons per hidden layer | 20–100 | too few: underfits |
| depth | number of hidden layers | 3–6 | too many: slow, harder to train |
| activation | the bend $\sigma$ | tanh (or sine) | ReLU: second derivatives vanish |
| learning rate $\eta$ | step size | $10^{-3}$ for Adam | too large: diverges; too small: slow |
| optimiser | update rule | Adam, then L-BFGS | plain GD: slow on stiff problems |
| iterations | number of updates | $10^4$–$10^5$ | stop early: inaccurate |
| collocation points | how many, where | $10^3$–$10^4$, random or uniform; resample | too few: wrong solutions with zero loss (section 3) |
| loss weights $\lambda$ | balance of equation, boundary and data terms | 1–100, or adaptive | one term dominates; boundary ignored |
| initialisation | random starting weights | Xavier/Glorot | saturation, slow start |
| input/output scaling | map $x, t$ to about $[-1, 1]$ | always | unscaled inputs train badly |
Hyperparameters are chosen by experience and by validation: compare settings on a separate check (a reference solution, held-out data, or a physical law such as energy conservation) — never on the final test set (Chapter 15).
Best practice: a checklist that avoids most beginner failures
The recipe below is what the training literature recommends again and again (reviews and studies from 2021–2026). Each item fixes a known way PINNs fail.
| # | do this | why |
|---|---|---|
| 1 | Non-dimensionalise the equation and scale inputs and outputs to about $[-1,1]$ | otherwise the residual, boundary and data terms differ by orders of magnitude and one of them is ignored |
| 2 | Enforce boundary conditions exactly when you can (hard constraints) | soft penalties can leave the boundary slightly wrong and compete with the residual |
| 3 | Use tanh or sine, add Fourier features if the solution oscillates or has several scales | plain networks learn high frequencies last (spectral bias) |
| 4 | Resample or adaptively place collocation points where the residual is large | too few or badly placed points can give a small loss and a wrong solution |
| 5 | Adam first, then L-BFGS | Adam finds the basin; L-BFGS polishes to high accuracy |
| 6 | Train in float64 when you need small errors or the problem is stiff | float32 can make L-BFGS stop early; some reported "failures" vanish in float64 |
| 7 | Use adaptive loss weights (or treat boundary conditions as constraints) | fixed weights rarely suit every term at every stage of training |
| 8 | For time-dependent problems, respect causality: train early times first or march in windows | fitting late times before early ones gives wrong trajectories |
| 9 | Run several random seeds and compare with a classical solver | a single lucky run proves little; a strong baseline keeps you honest |
To solve $y' = x$ with $y(0) = 0$, do not penalise $y(0)$ in the loss. Write the trial solution $$y_\theta(x) = x\,N_\theta(x),$$ which is zero at $x = 0$ for every choice of weights. The loss now has only the residual term $\big(y_\theta'(x_j) - x_j\big)^2$. For $u(0) = a$, $u(1) = b$ use $u_\theta(x) = a(1-x) + b\,x + x(1-x)\,N_\theta(x)$.
Sources: S. Wang, Y. Teng & P. Perdikaris, SIAM J. Sci. Comput. 43, 2021; P. Rathore et al., ICML 2024; Xu et al., NeurIPS 2025 (float64); S. Wang, S. Sankaran & P. Perdikaris, CMAME 421, 2024 (causality); C. Wu et al., CMAME 403, 2023 (sampling); J. Wang et al., "Exact Dirichlet boundary PINN", CMAME, 2023; I. E. Lagaris, A. Likas & D. I. Fotiadis, IEEE Trans. Neural Netw. 9(5), 1998 (trial solutions).
7. What "deep" means
A network with layers of widths $d_0 \to d_1 \to \dots \to d_L$ computes $$h_1 = \sigma(W_1 x + b_1),\quad h_2 = \sigma(W_2 h_1 + b_2),\quad\dots,\quad u = W_L h_{L-1} + b_L .$$ Deep learning simply means using networks with several hidden layers (and the methods to train them). Each layer re-combines the features of the previous one: features of features.
Layer $k$ has a $d_k\times d_{k-1}$ weight matrix and $d_k$ biases: $d_k(d_{k-1} + 1)$ parameters. A PINN for $u(x,t)$ with 3 hidden layers of 50: $50\cdot3 + 50\cdot51 + 50\cdot51 + 1\cdot51 = 150 + 2550 + 2550 + 51 = 5301$ parameters. The one-neuron network of section 4 had 4.
- Wide and shallow: one hidden layer can approximate anything (universal approximation) but may need very many neurons.
- Deep: compositions can represent many functions with far fewer parameters, but gradients must travel through many layers and can vanish (Chapter 13).
- For PINNs, moderate depth (3–8 layers) and smooth activations are the common choice; very deep plain networks rarely help.
8. The full algorithm on one page
input : PDE residual operator R[u], boundary/initial operator B[u], optional data (x_k, y_k)
choose: network u_θ, collocation points {x_j}, boundary points {x_b}, weights λ_b, λ_d,
optimiser (Adam, learning rate η), number of iterations K
initialise θ randomly
for k = 1 … K:
(optionally) resample collocation points
forward pass: u_θ(x_j), u_θ(x_b), u_θ(x_k)
autodiff in x, t: ∂u/∂x, ∂²u/∂x², ∂u/∂t … at x_j
residuals: r_j = R[u_θ](x_j), s_b = B[u_θ](x_b), d_k = u_θ(x_k) − y_k
loss: L(θ) = mean(r_j²) + λ_b·mean(s_b²) + λ_d·mean(d_k²)
backward pass: g = ∂L/∂θ (backpropagation through the derivatives)
update: θ ← θ − η·g (or the Adam rule)
(optionally) refine with L-BFGS
check : error against a reference solution / conservation laws on fresh points
output: u_θ(x) for any x in the domain
| finite differences for $y' = x$ | PINN for $y' = x$ | |
|---|---|---|
| unknowns | values $y_0, \dots, y_M$ at grid points | network weights $\theta$ |
| equation enforced | $(y_{i+1} - y_i)/h = x_i$ on the grid | $u_\theta'(x_j) = x_j$ at collocation points |
| how solved | march / linear solve, exact algebra | minimise a loss by gradient descent |
| error control | proven: $O(h)$ for this scheme | empirical; theory partial (Chapter 21) |
| result | numbers at grid points | a formula valid everywhere |
- A PINN = network + automatic derivatives + residual loss at collocation points + gradient descent.
- With few points, many wrong functions have zero loss; enough well-spread points rule them out.
- Every iteration: forward pass → derivatives in $x,t$ → residual → loss → backward pass → update.
- Parameters are learned; hyperparameters are chosen — by validation, not by the test set.
- "Deep" = several hidden layers; count parameters as $\sum d_k(d_{k-1}+1)$.
Further reading
- M. Raissi, P. Perdikaris & G. E. Karniadakis, J. Comput. Phys. 378, 2019, 686–707.
- L. Lu, X. Meng, Z. Mao & G. E. Karniadakis, "DeepXDE: a deep learning library for solving differential equations", SIAM Review 63(1), 2021, 208–228.
- S. Wang, S. Sankaran, H. Wang & P. Perdikaris, "An expert's guide to training physics-informed neural networks", arXiv:2308.08468, 2023.
- B. Moseley, "So, what is a physics-informed neural network?" (blog, 2021) — a gentle visual introduction.