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.

⏱ 40 minNeeds: Chapters 10, 14 and 161 lab · 2 animations
In plain words

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.

You will learn
Level 1 · basicThe recipe; fitting $y = x^2$ with few points; solving $y' = x$ with few points Level 2 · standardOne iteration in numbers; the lab; hyperparameters Level 3 · advancedDepth, parameter counts, the full algorithm, what can go wrong

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.)

  1. Choose a network $u_\theta(x)$: a formula with adjustable numbers $\theta$ (weights and biases). Before training it is a random curve.
  2. 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.
  3. Forward pass: compute $u_\theta(x_j)$ at every collocation point, and $u_\theta(0)$.
  4. Differentiate the network with respect to its input (automatic differentiation, Chapter 14) to get $u_\theta'(x_j)$.
  5. 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$.
  6. 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$.
  7. Backward pass: compute $\partial\mathcal L/\partial\theta$ for every weight (backpropagation through the derivative of step 4).
  8. Update: $\theta \leftarrow \theta - \eta\,\partial\mathcal L/\partial\theta$ (or Adam).
  9. 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.

Animation: three networks trained from different random starts on 1, 2, 3, 4, 6, 10 and 20 points of y equals x squared; with few points they disagree between points, with many they agree.
Watch: three networks, three random starting weights, the same data. All pass through the points; only with enough points do they agree with each other and with $x^2$ in between.
Count equations and unknowns

$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

Animation: PINNs for y prime equals x with 1, 2, 3, 5, 10 and 30 collocation points; with one or two points the three runs disagree with the exact parabola, with ten or more they match it.
Watch: no data at all — only the equation at the orange ticks and $y(0) = 0$. With 1–2 points the PINN finds curves that satisfy the check but are wrong; from about 5–10 points the answer is right everywhere.

Why do few points fail? Because wrong functions can have zero loss:

collocation pointswhat the loss demandsa wrong function with loss exactly 0its 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 everywhereonly 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.

The same lesson as finite differences

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.

Notice what the one neuron cannot do

$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

Lab · a PINN you can watchchange the points, then Train or step once
exact (dashed)network · collocation pointsdata / initial valueslope u′ at each point (≤ 6 points)
The table is steps 3–6 of the recipe for the current weights. Experiments: (1) PINN, 2 points — train, then change the seed: different wrong answers, all with tiny loss. (2) Raise to 10 points: the answer becomes right and seed-independent. (3) ReLU: $u'$ is piecewise constant, the fit is poor. (4) 1 neuron with 2 points vs 30 points. (5) $y' = y$: the equation involves $u$ itself, and the initial condition matters even more.

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:

hyperparameterwhat it istypical starting choiceeffect if badly chosen
widthneurons per hidden layer20–100too few: underfits
depthnumber of hidden layers3–6too many: slow, harder to train
activationthe bend $\sigma$tanh (or sine)ReLU: second derivatives vanish
learning rate $\eta$step size$10^{-3}$ for Adamtoo large: diverges; too small: slow
optimiserupdate ruleAdam, then L-BFGSplain GD: slow on stiff problems
iterationsnumber of updates$10^4$–$10^5$stop early: inaccurate
collocation pointshow many, where$10^3$–$10^4$, random or uniform; resampletoo few: wrong solutions with zero loss (section 3)
loss weights $\lambda$balance of equation, boundary and data terms1–100, or adaptiveone term dominates; boundary ignored
initialisationrandom starting weightsXavier/Glorotsaturation, slow start
input/output scalingmap $x, t$ to about $[-1, 1]$alwaysunscaled 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 thiswhy
1Non-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
2Enforce boundary conditions exactly when you can (hard constraints)soft penalties can leave the boundary slightly wrong and compete with the residual
3Use tanh or sine, add Fourier features if the solution oscillates or has several scalesplain networks learn high frequencies last (spectral bias)
4Resample or adaptively place collocation points where the residual is largetoo few or badly placed points can give a small loss and a wrong solution
5Adam first, then L-BFGSAdam finds the basin; L-BFGS polishes to high accuracy
6Train in float64 when you need small errors or the problem is stifffloat32 can make L-BFGS stop early; some reported "failures" vanish in float64
7Use adaptive loss weights (or treat boundary conditions as constraints)fixed weights rarely suit every term at every stage of training
8For time-dependent problems, respect causality: train early times first or march in windowsfitting late times before early ones gives wrong trajectories
9Run several random seeds and compare with a classical solvera single lucky run proves little; a strong baseline keeps you honest
Hard constraint in one line

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.

Counting parameters

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.

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$
unknownsvalues $y_0, \dots, y_M$ at grid pointsnetwork 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 solvedmarch / linear solve, exact algebraminimise a loss by gradient descent
error controlproven: $O(h)$ for this schemeempirical; theory partial (Chapter 21)
resultnumbers at grid pointsa formula valid everywhere
Key takeaways

Further reading