Foundations to Frontier
Tests
E. Deep Learning › E6 Early and Energy-Based Networks

The Multilayer Perceptron

A multilayer perceptron (MLP) stacks layers of neurons with nonlinear activations, trained end to end by backpropagation. One hidden layer is already a universal approximator; extra depth can represent some functions with exponentially fewer units. This page covers the architecture, universal approximation, the depth-versus-width trade-off (Telgarsky's sawtooth), and why representing a function is not the same as learning it. In the exercises you build a one-hidden-layer ReLU network whose error on a smooth target falls like 1/n², and then show that a hand-built 4-layer network with 2 ReLUs per layer computes an 8-tooth sawtooth exactly, while gradient training of shallow and deep networks with more units fails to find anything like it.

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.

One hidden layer can draw any curve
target: units:
network with 6 hidden ReLU units · max error 0.1340 · bound h²·max|f″|/8 applies to smooth targets
Dashed: the target; orange: the network ĝ(x) = c + Σ vₖ·unitₖ(x); faint: each unit's contribution. Each ReLU adds a kink, so N of them trace the polyline through N + 1 knots, and doubling N cuts the error about 4× on smooth targets. Each steep sigmoid adds a step, which only halves the error. Neither can fix a jump exactly (try "step"), but the error region shrinks. This is the universal approximation theorem made concrete: width buys accuracy, though nothing here says how to find the weights from data, or how many units a high-dimensional target needs.
Why engineers care

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.

📝 Quick check (Level 0)
0/3 answered
  1. 1. An MLP's hidden layers need…
  2. 2. MLPs are trained by…
  3. 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.
📝 Quick check (Level 1)
0/3 answered
  1. 1. Parameters of 1–24–1:
  2. 2. Teeth from composing the tent map 4 times:
  3. 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))
🐍 Exercise 1: universal approximation made explicit
Build a one-hidden-layer ReLU network that interpolates a smooth function and measure how its error shrinks with the number of units.
📝 Quick check (Level 2)
0/3 answered
  1. 1. High-frequency targets on low-dimensional inputs need…
  2. 2. A reasonable start for tabular regression:
  3. 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.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The universal approximation theorem guarantees…
  2. 2. A one-hidden-layer ReLU net with n units in 1-D has at most…
  3. 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.
🐍 Exercise 2 (research): representing versus learning a sawtooth
Train shallow and deep ReLU networks on 2- and 8-tooth sawtooths, and compare with an exact hand-built deep network.

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

  1. D. E. Rumelhart, G. E. Hinton, R. J. Williams (1986). “Learning representations by back-propagating errors.” Nature 323.
  2. G. Cybenko (1989). “Approximation by superpositions of a sigmoidal function.” Mathematics of Control, Signals and Systems 2(4).
  3. M. Telgarsky (2016). “Benefits of depth in neural networks.” Proc. COLT.
  4. N. Rahaman et al. (2019). “On the spectral bias of neural networks.” Proc. ICML.
  5. M. Tancik et al. (2020). “Fourier features let networks learn high frequency functions in low dimensional domains.” Advances in NeurIPS.