What networks can draw
Last updated
How much can a network with one hidden layer represent? The surprising answer, proved around 1990, is: almost anything, given enough units. This lesson builds that answer out of ReLU kinks you can add one at a time, states the universal approximation theorem carefully, and then looks at the three things it doesn't promise, which matter more in practice: how many units, whether training finds them, and why depth helps.
By the end of this lesson you can
- Build a bent line from ReLU units, and explain how more units make closer fits
- State what the universal approximation theorem promises, and what it doesn’t
- Show that a network that fits its training range can still be wrong outside it
- Explain, with an example, why a deep network can draw shapes a shallow one needs far more units for
ReLU units make kinks
Take a network with one input , one hidden layer of ReLU units, and one output with no activation. Hidden unit computes : a line that is flat at 0 until , then rises (or falls). That point is the unit's kink. The output adds the units up with weights :
A sum of bent lines is a bent line: straight pieces joined at the kinks. Three units already make a hat, up from to 0 and down to 1:
The first unit starts rising at ; the second, with weight , turns the rise into a fall at 0; the third levels it off at 1.
Adding kinks makes any curve
Hats can be placed anywhere, at any height and width. So a curve can be drawn as a row of hats, like a join-the-dots picture: the more units, the more dots, and the closer the fit. Try it: the output weights are chosen by least squares (lesson 3.5) for kinks spread evenly across the range.
3 units: 3 kinks, so up to 3 straight pieces. The biggest gap between the network and the curve is 1.1. Too few kinks to follow the wiggles.
The same in NumPy, for the curve on :
2 and 4 units can't follow three wiggles: the biggest gap is over 1. 8 units get within 0.48, 16 within 0.095, 32 within 0.022. Doubling the units roughly quarters the gap, and nothing stops you going on.
The theorem
That observation has a theorem behind it, proved for sigmoid units by George Cybenko in 1989 and extended by Kurt Hornik in 1991, and for any activation that isn't a polynomial, ReLU included, by Leshno and others in 1993. Informally:
A network with one hidden layer and enough units can approximate any continuous function on a bounded region as closely as you like.
This is the universal approximation theorem. "As closely as you like" means: pick any gap , and there is some number of units, and some weights, that keep the network within of the function everywhere in the region. The step 2 figure is the idea of the proof for one input; with several inputs, the hats become bumps.
It's a reassuring result. It says a network's shape isn't what limits it: the functions you want are in there somewhere.
It says nothing about learning
Read the theorem again for what it leaves out:
- How many units. "Enough" can be astronomically many, especially with many inputs.
- Whether training finds the weights. It says the weights exist, not that gradient descent will reach them.
- What happens outside the region. It's about a bounded region, the one the data covers.
All three show up on the same curve. Here scikit-learn's MLPRegressor learns its weights from 200 points:
Even 64 learned units only get within 0.867 of the curve, while step 2's 32 hand-placed kinks got within 0.022: the good weights exist, and training didn't find them. And at , outside the training range, the networks say 2.26, 5.98 and 10.02 when the truth is 1.05. A ReLU network carries on in a straight line past its last kink, so the more confidently it fitted, the further off it can go. The theorem promised nothing there, and nothing was delivered.
Depth against width
If one layer is enough in principle, why do real networks have many? Because some shapes cost far fewer units when layers are stacked. Here's a famous example (Telgarsky, 2016). The tent, made of 2 ReLU units, maps onto itself: up from 0 to 1, then back down. Feed its output into another tent, and the result goes up and down twice; again, four times. Each layer folds the line in half, like folding paper:
1 layer, 2 units: 2 straight pieces. One hidden layer would need at least 1 units for the same zigzag.
With 2 units per layer, every layer doubles the number of straight pieces: 12 units in 6 layers make 64 pieces. One hidden layer needs a kink per piece, so 63 units or more, for the same zigzag; 30 layers would need about a billion. Deeper networks can reuse what earlier layers computed, which a single wide layer can't.
That's the honest case for depth: not that shallow networks can't, but that deep ones can far more cheaply, for the kinds of structure real data has. Training deep networks well is Stage 7.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Cybenko, Approximation by superpositions of a sigmoidal function, Mathematics of Control, Signals and Systems 2, 1989: one hidden layer of sigmoid units can approximate any continuous function on a box
- Hornik, Approximation capabilities of multilayer feedforward networks, Neural Networks 4(2), 1991: it’s the layered structure that matters, not the particular activation
- Leshno, Lin, Pinkus and Schocken, Multilayer feedforward networks with a nonpolynomial activation function can approximate any function, Neural Networks 6(6), 1993: any activation that isn’t a polynomial will do, ReLU included
- Telgarsky, Benefits of depth in neural networks, 2016: the composed tent map: functions deep networks draw cheaply and shallow ones can’t
- Prince, Understanding Deep Learning, chapters 3 and 4: shallow networks as piecewise linear functions, and what depth adds