AI / ML Theory
Chapter 2 · 20 min

2.2 — Universal approximation: what one hidden layer can and cannot do

Goal: State and unpack the universal approximation theorem: one hidden layer approximates any continuous function on a compact set — with important caveats.

1. Why this session exists

XOR (1.6) showed that one hidden layer is enough to compute a non-linear-separable Boolean function. The natural question — how powerful is one hidden layer in general? — was answered by Cybenko (1989) and Hornik (1991)[2]: arbitrarily powerful, in a precise approximation sense. This is the universal approximation theorem (UAT).

The theorem is important for what it asserts (existence of an approximator) and equally important for what it doesn't assert (efficient training, reasonable size, depth efficiency). This session does both halves.


2. Statement

Theorem (Cybenko, 1989, sigmoidal case)[1]. Let σ:R→[0,1]\sigma : \mathbb{R} \to [0, 1] be a continuous sigmoidal function: σ(z)→1\sigma(z) \to 1 as z→+∞z \to +\infty, σ(z)→0\sigma(z) \to 0 as z→−∞z \to -\infty. Let K⊂RdK \subset \mathbb{R}^d be compact and f:K→Rf : K \to \mathbb{R} continuous. Then for every ε>0\varepsilon > 0 there exist N∈NN \in \mathbb{N}, weights W∈RN×dW \in \mathbb{R}^{N \times d}, biases b∈RNb \in \mathbb{R}^N, output weights v∈RNv \in \mathbb{R}^N such that the one-hidden-layer network

FN(x)  =  ∑i=1Nvi σ(Wi⊤x+bi)F_N(x) \;=\; \sum_{i=1}^N v_i\, \sigma(W_i^\top x + b_i)

satisfies

sup⁡x∈K∣f(x)−FN(x)∣  <  ε.\sup_{x \in K} \bigl|f(x) - F_N(x)\bigr| \;<\; \varepsilon.

Hornik's extension (1991). Replace "sigmoidal" by "any non-polynomial continuous activation". The theorem still holds. So ReLU, GELU, tanh, swish — all are universal approximators.

In words: with enough hidden units, a single hidden layer can approximate any continuous function on any bounded region to any accuracy.[5, 6, 7]


3. What the theorem says and does not say

Four things to internalise.

(a) Universality is existential, not constructive. The theorem promises that some (W,b,v)(W, b, v) realising ε\varepsilon-approximation exists. It says nothing about how to find them. Training, optimisation, generalisation — none of those questions are addressed.

(b) The width NN is uncontrolled. The theorem says "for every ε\varepsilon, there exists NN". It does not bound NN in terms of ε\varepsilon or in terms of the complexity of ff. For pathological ff (high oscillation, sharp transitions) NN can be astronomically large. Universality is not efficiency.

(c) It is shallow universality. UAT is a statement about one hidden layer. It doesn't say a deep network is needed or even helpful. The reason we use depth in practice is not that shallow nets cannot represent the target — they can — but that deep nets often represent natural targets with exponentially fewer parameters. This is a separation result (Telgarsky 2016 and follow-ups)[3], not a universality result.

(d) Continuity matters. UAT covers continuous targets on compact domains. It says nothing about discontinuous functions, unbounded domains, or functions on discrete spaces. The right tool for piecewise-constant or discrete targets is a different theory (decision trees / boosting).


4. Why it's true: intuition only

We won't prove UAT — the original arguments use the Hahn–Banach theorem (Cybenko) and the Stone–Weierstrass theorem (Hornik). The intuition is short.

Pick a sigmoidal σ\sigma. By scaling and shifting, σ(W⊤x+b)\sigma(W^\top x + b) is a soft indicator of a half-space: it ramps from ≈0\approx 0 on one side of {W⊤x+b=0}\{W^\top x + b = 0\} to ≈1\approx 1 on the other, with a sharp transition that gets sharper as we scale WW.

A sum of two such soft indicators — one with positive weight, one with negative weight — gives a soft bump that is ≈1\approx 1 inside a slab and ≈0\approx 0 outside. Sums of soft bumps approximate any function that is approximately constant on small slabs. Continuous functions are uniformly approximable by such slab-step functions on a compact set (the Stone–Weierstrass step). Hence sums of sigmoids approximate continuous functions. QED, very roughly.

ReLU and other non-polynomial activations admit similar constructions: sums of ReLU⁡(w⊤x+b)\operatorname{ReLU}(w^\top x + b) produce piecewise-affine continuous functions, and those are dense in C(K)C(K).


5. The depth-width trade-off

UAT leaves an obvious follow-up question: for the same approximation accuracy, can we use fewer total parameters by going deep instead of wide?

Yes. Two concrete results.

  • Telgarsky (2016). There exist functions on [0,1][0, 1] that a depth-LL ReLU net realises with Θ(L)\Theta(L) units, but any depth-O(1)\mathcal{O}(1) net needs Ω(2L)\Omega(2^L) units to approximate within ε\varepsilon. Depth can be exponentially parameter-efficient.
  • Eldan & Shamir (2016)[4]. A separation between depth-2 and depth-3 networks in Rd\mathbb{R}^d: certain targets require eΩ(d)e^{\Omega(d)} hidden units at depth 2 but only polynomial size at depth 3.

These results say: depth is a parameter-efficient knob for representing functions that compose simple pieces. Empirically this matches what we observe — deep nets on hierarchical data (images, text) use orders of magnitude fewer parameters than the shallow equivalents.


6. Where this is going

The rest of the chapter is about making such networks work in practice:

  • 2.3 — choosing g(ℓ)g^{(\ell)}.
  • 2.4 — vectorising the forward pass over a batch.
  • 2.5–2.8 — backprop: computing gradients through the composition.
  • 2.9–2.10 — training pathologies (vanishing/exploding gradients) and initialisation.
  • 2.11–2.12 — automatic differentiation and an end-to-end NumPy implementation.

UAT tells us the function we want is in the family. The rest of the chapter is about how to find it.


7. Takeaways

  • Universal approximation. One hidden layer with a non-polynomial continuous activation can approximate any continuous function on a compact set to arbitrary precision.
  • What UAT does not say. How big the network must be; how to train it; whether deep is better than wide; anything about generalisation from a finite sample.
  • Depth–width trade-off. Depth can be exponentially parameter-efficient for naturally compositional targets (Telgarsky, Eldan–Shamir).
  • Empirically, depth is preferred — UAT is the floor of network expressivity, not the ceiling.

Self-test

(a) Sketch a one-hidden-layer ReLU network that approximates f(x)=x2f(x) = x^2 on [−1,1][-1, 1] to within ε=0.01\varepsilon = 0.01. How many hidden units does your construction use? (Hint: approximate x2x^2 by a piecewise-affine function with enough ReLU "kinks".)

(b) Match each statement to "yes, UAT covers it" or "no, UAT does not":

  • Training a network with SGD converges to the approximator.
  • There exists a network of size at most poly⁡(1/ε)\operatorname{poly}(1/\varepsilon) achieving accuracy ε\varepsilon.
  • There exists a finite-sized network with sup⁡x∣f(x)−F(x)∣<ε\sup_x |f(x) - F(x)| < \varepsilon.
  • The approximator generalises from a finite training set.

(c) Why doesn't UAT extend to polynomial activations? (Hint: what is the function class spanned by sums of σ(W⊤x+b)\sigma(W^\top x + b) when σ\sigma is a polynomial of degree kk?)

(d) Read Telgarsky's separation theorem out loud and translate it into one sentence about the practical advantage of depth.


References

  1. [1]

    Cybenko, G. (1989). "Approximation by superpositions of a sigmoidal function". Mathematics of Control, Signals, and Systems, 2(4), 303–314. — UAT for sigmoidal activations (2.2).

    ↩
  2. [2]

    Hornik, K. (1991). "Approximation capabilities of multilayer feedforward networks". Neural Networks, 4(2), 251–257. — UAT for general non-polynomial activations (2.2).

    ↩
  3. [3]

    Telgarsky, M. (2016). "Benefits of depth in neural networks". COLT. arXiv:1602.04485 — Depth-vs-width separation (2.2).

    ↩
  4. [4]

    Eldan, R., & Shamir, O. (2016). "The power of depth for feedforward neural networks". COLT. arXiv:1512.03965 — Depth-2 vs depth-3 separation (2.2).

    ↩
  5. [5]

    Xiao, G., Tian, Y., Chen, B., Han, S., & Lewis, M. (2023). "Efficient streaming language models with attention sinks" (StreamingLLM). arXiv:2309.17453 — Attention sinks for constant-memory streaming (6.13 §2.2).

    ↩
  6. [6]

    Xie, S. M., Pham, H., Dong, X., et al. (2023). "DoReMi: Optimizing data mixtures speeds up language model pretraining". arXiv:2305.10429 — Worst-domain-perplexity optimisation for data mixtures (7.5 §2.2).

    ↩
  7. [7]

    Lee, H., Phatale, S., Mansoor, H., et al. (2023). "RLAIF: Scaling reinforcement learning from human feedback with AI feedback". arXiv:2309.00267 — Empirical comparison RLHF vs RLAIF (9.13 §2.2).

    ↩