Foundations to Frontier
Tests
E. Deep Learning › E0 Core Concepts (concept pages)

Universal Approximation (Intuition)

The universal approximation theorem says that a network with a single hidden layer and enough units can approximate any continuous function on a bounded domain as closely as you like. This page builds the intuition by construction: each ReLU unit adds one kink, so a one-hidden-layer ReLU network can trace a piecewise-linear interpolant of any curve, with error shrinking like one over the number of units squared for smooth targets, while sigmoid units can be paired into bumps. It then shows the theorem's limits: it says nothing about how many units are needed (sometimes exponentially many, where depth would need few), nothing about generalisation, and nothing about whether gradient descent will find the approximating weights. In the exercises you construct ReLU and sigmoid approximators and measure their error rates, then compare what deep and shallow networks can represent with what gradient descent actually learns.

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Bending a ruler

Imagine tracing a curve with a flexible ruler that you may bend only at chosen points. With enough bends you can follow any smooth curve as closely as you like. A ReLU unit is one such bend. A network with one hidden layer and enough units can therefore follow any continuous curve. That is the universal approximation theorem, in its simplest form.

Building functions out of ReLU units
max error 0.1340 with 6 units
Each unit adds a kink at its knot; the output weights set how much the slope changes there (thin lines, scaled down). For the smooth curves, doubling the units cuts the error by about four. The step is the hard case: a continuous ReLU network can only approximate the jump with a steep ramp, so the error stays large near the jump, however many units.
Why engineers care

The theorem is why neural networks can serve as general-purpose function approximators: learned dynamics models, aerodynamic surrogates, controllers. Its limits matter just as much. It does not say how big the network must be, whether it will generalise from data, or whether training will find the solution. These are the questions that decide whether a learned model is fit for an engineering task.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Universal approximation says one hidden layer can approximate…
  2. 2. Each ReLU unit contributes…
  3. 3. The theorem guarantees that training will find the weights.

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

Construction by hand

ReLU interpolation. Pick knots x₀ < x₁ < … < xₙ and the values f(xᵢ). The network

g(x) = f(x₀) + Σᵢ₌₀ⁿ⁻¹ aᵢ ReLU(x − xᵢ)

uses n hidden units. Here a₀ is the first slope, and each later aᵢ is the change of slope at knot xᵢ. For knots 0, 1, 2, 3 with values 0, 1, 1, 3, the slopes are 1, 0 and 2, so the output weights are (1, −1, 2).

Error. Piecewise-linear interpolation with spacing h has a maximum error of at most M₂h²/8, where M₂ = max |f″|.

  • For sin(2πx) on [0, 1] with 16 units, the bound is 4π²/(8 × 256) ≈ 0.019.
  • For an error of at most 0.001 you need n ≥ √(M₂/(8ε)), which is about 71 units.

Sigmoid bumps. σ(k(x − a)) − σ(k(x − b)) is about 1 on [a, b] and about 0 outside when k is large. A sum of bumps with heights f(midpoint) gives a staircase approximation. It uses 2 units per step, and its error falls only like 1/n.

📝 Quick check (Level 1)
0/3 answered
  1. 1. Halving the knot spacing reduces the ReLU interpolation error by about…
  2. 2. How many sigmoid units does one bump use?
  3. 3. The output weight at an interior knot equals…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Rates and depth

Exercise 1. ReLU interpolants of sin(2πx) on [0, 1]:

units 4 8 16 32 64
max error 0.2105 0.0704 0.0188 0.0048 0.0012

Each doubling cut the error by about 4. The measured 0.0188 at 16 units sits just under the h²/8 bound of 0.0193. Sigmoid bumps did much worse: 0.306 with 16 units and 0.079 with 64, an O(1/n) staircase.

Depth buys pieces exponentially. The tent map t(x) = 2 ReLU(x) − 4 ReLU(x − ½) folds [0, 1] onto itself using 2 units. Composing it L times gives a sawtooth with 2^L linear pieces from only 2L units. A single hidden layer needs a unit per kink, about 2^L units (Telgarsky, 2016).

import torch.nn as nn
shallow = nn.Sequential(nn.Linear(1, 64), nn.ReLU(), nn.Linear(64, 1))
deep = nn.Sequential(nn.Linear(1, 8), nn.ReLU(), nn.Linear(8, 8), nn.ReLU(), nn.Linear(8, 8), nn.ReLU(), nn.Linear(8, 1))
🐍 Exercise 1: constructing approximators
Build the one-hidden-layer ReLU network that interpolates sin(2πx) at n + 1 knots, measure its maximum error for n = 4…64, and compare with a sum of sigmoid bumps.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Composing the 2-unit tent map 5 times gives how many linear pieces?
  2. 2. Sigmoid-bump errors in exercise 1 fell like…
  3. 3. A one-hidden-layer ReLU network needs roughly how many units for 2^L pieces?

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

What the theorem says and does not say

Statements.

  • Cybenko (1989) proved it for sigmoids, and Hornik, Stinchcombe and White (1989) for any bounded non-constant activation.
  • Leshno et al. (1993) showed that it holds exactly when the activation is not a polynomial.
  • One-hidden-layer networks are dense in the continuous functions on compact sets (topic b4-1).
  • Width-bounded deep versions also exist (Lu et al., 2017): ReLU networks of width n + 4 are universal for n inputs.

Rates. For functions with s bounded derivatives in d dimensions, approximation to error ε needs about ε^(−d/s) parameters, the curse of dimensionality. Barron (1993) showed that functions with a finite Fourier moment can be approximated with O(1/ε²) units in any dimension.

What it does not give.

  1. Size: the required width can be enormous.
  2. Learnability: nothing about gradient descent finding the weights.
  3. Generalisation: fitting the training points is not the same as approximating the true function between them.
  4. Extrapolation: outside the bounded domain there is no guarantee. ReLU networks continue linearly.

Depth separations. Telgarsky (2016) built functions computable by depth-L networks of polynomial size that need exponentially many units at depth 2. Eldan and Shamir (2016) gave a 3-layer versus 2-layer separation in high dimension.

Interview questions.

  • If one layer suffices, why go deep? Efficiency: some functions need far fewer parameters with depth, and depth matches the compositional structure of real data.
  • Does universal approximation explain why deep learning works? No. It is about existence. Optimisation and generalisation are separate questions.
📝 Quick check (Level 3)
0/3 answered
  1. 1. Leshno et al. showed universality holds for activations that are…
  2. 2. The curse of dimensionality for smooth functions means parameters grow like…
  3. 3. Outside the training domain, a ReLU network…

Level 4: Expert

★★★★★ Expert⏱ 25 minResearchers: original papers and open problems.

Representable is not the same as learnable

History.

  • A. Kolmogorov (1957) and V. Arnold showed that continuous functions of several variables are compositions of one-variable functions.
  • G. Cybenko (1989) and K. Hornik et al. (1989) proved universal approximation.
  • A. Barron (1993) gave dimension-free rates.
  • M. Telgarsky (2016) proved depth separation with sawtooth functions.
  • N. Rahaman et al. (2019) documented the “spectral bias” of trained networks toward low frequencies.

Exercise 2. Sawtooth targets with 1–8 teeth on [0, 1] (128 training points). A shallow network (64 units) and a deep one (3 layers of 8) are each large enough to represent every target exactly. Each was trained with Adam for 1500 steps; the table gives test MSE averaged over 2 seeds. Predicting the mean gives 0.083.

teeth units needed (deep exact / shallow exact) trained shallow, 64 units trained deep, 3 × 8
1 2 / 2 0.0000 0.0000
2 4 / 4 0.0619 0.0336
4 6 / 8 0.0660 0.0568
8 8 / 16 0.0812 0.0777
  • A single tooth (a tent) was learned perfectly by both networks.
  • With more teeth, training failed even though the capacity was there. With 8 teeth both networks ended close to predicting the mean (0.083). The shallow network has four times the units needed, and the deep one is enough for an exact fold.
  • The deep network did somewhat better on 2 and 4 teeth, but nowhere near its exact construction. Gradient descent from random weights rarely finds the precise folding weights.
  • Lesson: universal approximation, and even depth separation, are statements about existence. What a network learns depends on optimisation, initialisation and the data, which is why the rest of section E is about training.
🐍 Exercise 2 (research): representable versus learnable
Build sawtooth targets by composing the tent map, compare the units an exact deep or shallow construction needs, and train shallow and deep ReLU networks with Adam to see what gradient descent actually fits.

Universal approximation in AI, robotics and aerospace

  • Surrogate models: networks approximate expensive simulations (CFD, finite-element models) inside the region where training data exist. Do not trust them outside it.
  • Learned dynamics and control: universal approximation justifies network policies and dynamics models, but certification needs explicit error bounds on the operating envelope.
  • Sizing: approximation rates give a first estimate of the network size needed for a required accuracy on smooth physical maps.

References

  1. G. Cybenko (1989). “Approximation by superpositions of a sigmoidal function.” Mathematics of Control, Signals and Systems 2.
  2. K. Hornik, M. Stinchcombe, H. White (1989). “Multilayer feedforward networks are universal approximators.” Neural Networks 2.
  3. A. R. Barron (1993). “Universal approximation bounds for superpositions of a sigmoidal function.” IEEE Trans. Information Theory 39(3).
  4. M. Telgarsky (2016). “Benefits of depth in neural networks.” Proc. COLT.
  5. N. Rahaman et al. (2019). “On the spectral bias of neural networks.” Proc. ICML.