Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Layers of neurons that can bend
A single neuron can only draw a straight dividing line. Put a layer of neurons in front of it, each with a nonlinear activation, and the network can bend that line, or build any curve out of many small straight pieces. Stack more layers and each layer can reuse and fold what the previous one built, so some complicated shapes need far fewer neurons. The whole stack is trained together by backpropagation.
MLPs are everywhere: the feed-forward blocks inside transformers, the heads of vision networks, policy and value networks in reinforcement learning, neural fields such as NeRF, and surrogate models of physics and aerodynamics. Understanding what they can represent, and what training will actually find, guides how big and how deep to make them.
- 1. An MLP's hidden layers need…
- 2. MLPs are trained by…
- 3. Transformers contain MLPs as…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Forward pass: h₀ = x, hₗ = φ(hₗ₋₁Wₗ + bₗ), output = h_(L−1)W_L + b_L.
- Parameters: Σ(nₗ₋₁nₗ + nₗ). Examples:
- 1–24–1 has 73;
- 1–6–6–6–1 has 103;
- 784–100–10 has 79 510.
- Without nonlinearity a stack of linear layers collapses into one linear map.
- ReLU interpolation: n ReLUs in one layer can reproduce the piecewise-linear interpolant through n + 1 points; for smooth targets the error shrinks by 4 each time n doubles.
- Depth trick: the tent map t(x) = 2·ReLU(x) − 4·ReLU(x − ½) maps [0, 1] onto itself with one peak; composing it k times gives 2^(k−1) peaks (8 for k = 4) with only 2 ReLUs per layer. A single hidden layer needs a number of units that grows with the number of peaks.
- 1. Parameters of 1–24–1:
- 2. Teeth from composing the tent map 4 times:
- 3. Doubling ReLUs in a piecewise-linear fit cuts the error by…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.MLPs in code
Exercise 1. A one-hidden-layer ReLU network built to interpolate sin(6x) + 0.5x² at n + 1 points had largest error 0.24, 0.071, 0.018, 0.0045 and 0.0011 for n = 4, 8, 16, 32 and 64: ratios of 3.92, 4.00 and 3.99 per doubling.
Practice.
- Use ReLU or GELU hidden units, He initialisation, Adam or AdamW, and normalisation for deep stacks.
- Start wide-and-shallow (2–4 hidden layers) for tabular and low-dimensional regression; depth pays off when the target has compositional structure.
- Low-dimensional inputs with high-frequency structure (coordinates in neural fields) need Fourier features or sinusoidal activations; plain MLPs are biased towards smooth functions (exercise 2).
mlp = torch.nn.Sequential(torch.nn.Linear(d, 256), torch.nn.GELU(), torch.nn.Linear(256, 256), torch.nn.GELU(), torch.nn.Linear(256, out))- 1. High-frequency targets on low-dimensional inputs need…
- 2. A reasonable start for tabular regression:
- 3. In exercise 1 the error ratio per doubling was about…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Universal approximation. Cybenko (1989) and Hornik, Stinchcombe and White (1989) proved that one hidden layer with a sigmoidal activation can approximate any continuous function on a compact set to any accuracy; Leshno et al. (1993) extended it to any non-polynomial activation, including ReLU. The theorem says nothing about how many units are needed, or whether training finds them.
Depth separation. Telgarsky (2016) showed that functions computed by networks of depth k³ with polynomially many units need exponentially many units at depth k. The sawtooth is the standard example: depth k gives 2^k linear pieces, while a one-hidden-layer network with n ReLUs has at most n + 1 pieces in one dimension.
Representation versus learning. Gradient descent on MLPs is biased towards low-frequency functions (spectral bias; Rahaman et al., 2019): it fits smooth components first and high-frequency ones slowly, if at all. Exercise 2 shows a network that can exactly represent an 8-tooth sawtooth, while training of larger networks fails to find one.
Why MLPs still work. Real targets are usually smooth along most directions and compositional, which matches both what MLPs represent cheaply and what gradient descent finds easily.
- 1. The universal approximation theorem guarantees…
- 2. A one-hidden-layer ReLU net with n units in 1-D has at most…
- 3. Spectral bias means training fits first…
Level 4: Expert
★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.Representing versus learning a sawtooth
History.
- D. Rumelhart, G. Hinton and R. Williams (1986) popularised backpropagation for MLPs.
- G. Cybenko (1989) and K. Hornik et al. (1989) proved universal approximation; M. Leshno et al. (1993) extended it.
- M. Telgarsky (2016) proved depth separation with the sawtooth.
- N. Rahaman et al. (2019) described spectral bias.
Exercise 2. Fit a sawtooth with 2 or 8 teeth on [0, 1] by full-batch Adam (3000 steps, 512 points), two seeds; predicting the mean gives MSE 1/12 ≈ 0.083.
| network | teeth | test MSE | parameters |
|---|---|---|---|
| shallow, 1 × 24 | 2 | 0.023 | 73 |
| deep, 3 × 6 | 2 | 0.057 | 103 |
| shallow, 1 × 24 | 8 | 0.080 | 73 |
| deep, 3 × 6 | 8 | 0.080 | 103 |
| hand-built, 4 × 2 (tent map) | 8 | 0.000 (largest error below 10⁻¹⁵) | 4 layers |
- A hand-built network with 2 ReLUs per layer represents the 8-tooth sawtooth exactly.
- Trained networks with more units fitted 8 teeth hardly better than a constant, shallow or deep, and only partly fitted 2 teeth.
- Lesson: expressive power is not learnability. Depth can represent oscillatory functions cheaply, but gradient descent from random initialisation does not find those solutions; such targets need better inputs (Fourier features), different activations or more data and steps.
MLPs in AI, robotics and aerospace
- Policies and value functions in reinforcement learning for robots and drones are usually MLPs.
- Surrogate models of aerodynamics, thermal behaviour and structures replace expensive simulations in design loops.
- Neural fields (NeRF, signed distance functions) for mapping and 3-D reconstruction are MLPs on coordinates, with Fourier features to beat spectral bias.
References
- D. E. Rumelhart, G. E. Hinton, R. J. Williams (1986). “Learning representations by back-propagating errors.” Nature 323.
- G. Cybenko (1989). “Approximation by superpositions of a sigmoidal function.” Mathematics of Control, Signals and Systems 2(4).
- M. Telgarsky (2016). “Benefits of depth in neural networks.” Proc. COLT.
- N. Rahaman et al. (2019). “On the spectral bias of neural networks.” Proc. ICML.
- M. Tancik et al. (2020). “Fourier features let networks learn high frequency functions in low dimensional domains.” Advances in NeurIPS.