What a Network Can Represent
One neuron can only draw a line, so it can't compute XOR; add a hidden layer and it can. With enough hidden neurons, sums of shifted ReLUs or sigmoids bend into steps and bumps that trace any continuous curve as closely as you like, which is the universal approximation idea.
What the symbols mean
- Counting neuron
How many of the two inputs are on: 0, 1 or 2.
- Both-on neuron
Positive only when both inputs are on.
- Output
The count, minus a penalty of 2 for each unit of h₂.
What the symbols mean
- Kink location
Where hidden neuron k switches on; set by its bias, x_k = −b_k/w_k.
- Output weight
How much the slope changes at the kink x_k.
- Hidden neurons
One ReLU per bend.
What the symbols mean
- Spacing
The distance between neighboring kinks.
Explanation
Universal approximation is simply the fact that a network with one hidden layer of enough neurons can imitate any continuous curve as closely as you want. "Universal" because it doesn't matter which curve; "approximation" because the match is close rather than exact, and gets closer with more neurons. The idea fits in one sentence: each ReLU neuron adds one bend at a place you choose, and a curve made of enough short straight pieces can look like any shape, the same way a polygon with many sides looks like a circle. Before we get there, there's a smaller question that stumped people for years: why can't one neuron compute XOR?
XOR, and why one neuron can't do it. XOR ("exclusive or") outputs when exactly one of its two inputs is :
| XOR | ||
|---|---|---|
| 0 | 0 | 0 |
| 1 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
Picture the four inputs as corners of a square. The s sit on one diagonal and the s on the other, and no straight line can put two opposite corners on one side and the other two on the other side. Here's the algebra behind that picture. Suppose a perceptron with weights and bias worked, firing when . Then:
- needs ;
- needs ;
- needs ;
- needs .
Add the middle two: , so . But means , so , which contradicts the last line. No choice of weights works, and adding more linear layers doesn't help either, since they collapse into one (Activation Functions).
A hidden layer fixes it. Take the network in the formulas. Every hidden neuron sees the same sum . At , , both hidden neurons are and . At or , , so , and . At , , so , and . Think about why it works: counts how many inputs are on, only wakes up when both are, and the output takes the count and subtracts a big penalty in exactly that case. Geometrically, the hidden layer moves the four corners to new spots, , , and in coordinates. The two inputs that should give now land on the same point, and a straight line like separates it from the rest. The hidden layer bends the space so that a line can finish the job. There's an animation further down that runs all four inputs through this network.
Building curves out of ReLUs. One neuron is flat until and then a ramp of slope . Multiply it by and add it to a running total, and the total's slope changes by exactly at and nowhere else. So any connect-the-dots (piecewise linear) function can be written as
For example, has slope on , on , and after that: a triangle of height , a "hat". Now take any continuous , mark points on its graph a distance apart, and connect the dots with ReLUs. As shrinks, the dots-curve hugs .
How fast does the error shrink? Try on one piece . The chord's height at the midpoint is the average of the endpoint heights, , and the curve's height there is . Subtract:
Since for this curve, that's . The same Taylor-style reasoning as in linear approximations gives the general bound . Halve the spacing and the error drops by a factor of . With neurons spread over an interval of length , and the error is at most about .
Sigmoids build steps and bumps. A sigmoid neuron with a large steepness is nearly a step at . Subtract two of them and you get a bump: is close to between and and close to elsewhere. Line up bumps of heights side by side and you've drawn as a bar chart. Either way you land on the universal approximation theorem: for any continuous on a closed interval (or a closed box in dimensions) and any tolerance , some network with one hidden layer stays within of everywhere on it.
What the theorem doesn't say. It promises that good weights exist, not that training will find them, and the number of neurons it needs can be enormous: covering an -dimensional box with a grid of spacing takes about cells. In practice depth helps. Deep networks reuse features built by earlier layers and can represent some functions with exponentially fewer neurons than a single wide layer, which is why real networks are deep rather than just wide.
A common mistake. It's tempting to read "universal" as "a network can learn anything from any data". It doesn't mean that. The theorem is about which weights exist, not how to find them, and it says nothing about how well the network will predict on examples it hasn't seen; that's overfitting, later in the course.
See it
Worked examples
Check that the network , , computes XOR on all four inputs.
- 1
Both hidden neurons see the same sum , so compute it first for each input: , , , .
Write the connect-the-dots function through , and , flat at height after , as for .
- 1
Find the slope of each straight piece. From to : .
Practice
Type your answer and check it. Solve them all to complete the lesson.
A step-activation network computes , and on inputs that are or , where for and otherwise. Which logic gates do and compute?
Why can't a single perceptron compute XOR?
Evaluate the hat function at .
Which sum of ReLUs equals for every ?
A sensor chip converts readings with the calibration curve on , approximated by a ReLU network that connects equally spaced dots. Since , each piece is off by at most . What is the smallest number of pieces (hidden neurons) that keeps the error at or below ?
A sigmoid neuron should act like a step at . How large must the steepness be so that already at the output reaches ? Give 2 decimal places.
To fix XOR, a student stacks five layers of neurons with no activation function. What can the network's decision boundary look like?
The hardest one here. Get it, and you've got this lesson.
A motor controller wants a speed profile that is for , rises in a straight line to at , falls in a straight line to at , and stays after that. Build it as and give .
Where it's used
Networks earn their keep as function approximators. Engineers replace slow physics simulations (airflow over a wing, heat in a chip) with a network trained on the simulator's outputs that answers in microseconds; a robot's controller learns the curve from sensor readings to motor commands; and image and speech models are, underneath, enormous functions from pixels or sound to labels. Universal approximation is the guarantee that a big enough network has room for the right answer, and the error bound is a reminder that more accuracy costs more neurons.