Universal Approximation Theorem


Universal Approximation Theorem

Hope
Today we're exploring why deep neural networks can represent complicated patterns so efficiently. Our example is the remarkably intricate border between Belgium and the Netherlands in the municipality of Barlay Hertok.

Corey
And the key result is the universal approximation theorem. In the source, this result is attributed to George Sabeno in 1989, and it says that a sufficiently wide two-layer neural network can represent any continuous function to arbitrarily high precision.

Hope
That sounds almost like saying a neural network can learn anything, but that wording is too strong. The theorem says an appropriate network exists; it does not tell us how to find that network, how many neurons are required, or whether ordinary training will discover it.

Corey
Before adding the crucial activation function, though, a network with multiple layers doesn't gain much expressive power. Each neuron computes a weighted sum of its inputs and adds a bias. With two map coordinates, those computations form tilted planes.

Hope
The weights control the plane's steepness in each coordinate direction, while the bias shifts the entire plane up or down. For example, if a point has coordinates x1 equal to 0.6 and x2 equal to 0.4, the neuron multiplies each coordinate by its learned weight, adds the results, and then adds its bias. In the example, that produces a plane height of negative 0.14.

Corey
But if we simply feed the outputs of one plane-producing layer into another plane-producing layer, the layers collapse algebraically into one linear calculation. Adding and scaling tilted planes still gives us another tilted plane.

Hope
So without a nonlinear step, even a network that looks deep is effectively still a single-layer model. Its decision boundary remains a straight line formed where two planes intersect, which cannot capture the many separate pieces of the Barlay Hertok border.

Corey
The extra ingredient is an activation function. The example uses the rectified linear unit, or ReLU. ReLU outputs zero for an input below zero, and passes the input through unchanged when the input is zero or positive.

Hope
Geometrically, ReLU folds or clips every part of a plane that lies below height zero up to the zero plane. Instead of passing a flat plane to the next layer, the neuron passes along a bent surface with a fold line. The learned weights and bias determine where that fold line appears.

Corey
Let's apply that to the Belgium point with coordinates 0.6 and 0.4. The first layer produces heights of negative 0.14 and negative 0.33 for two neurons. ReLU turns both values into zero, so this point is mapped to the pair zero, zero.

Hope
The final layer then takes those activated values, multiplies them by another set of learned weights, and adds biases. In the example, the resulting heights are 0.03 for one country's surface and negative 0.89 for the other. Since the Belgium output is higher, the model classifies the point as Belgium.

Corey
For a Netherlands point, such as 0.3 and 0.7, the important difference is that it does not lie in the zeroed-out region of the second first-layer neuron. That activated value pushes the final Netherlands surface upward and the Belgium surface downward, producing the correct classification.

Hope
This surface picture is just another way to visualize the numerical computation. Each first-layer neuron folds the map along one line. The second-layer output neuron scales and adds those bent surfaces, creating a piecewise-linear surface whose height represents confidence in one country.

Corey
With two output neurons, one surface represents confidence in the Netherlands and the other represents confidence in Belgium. Where the two surfaces intersect, the model is equally confident. That intersection becomes the learned decision boundary.

Hope
Adding more neurons to the first layer gives the network more fold lines. Three fold lines can divide the input map into five regions, and each region becomes a separate plane in the output surface. The second output neuron creates another surface over the same regions, but with different heights.

Corey
As the width increases from eight neurons to 16, 32, 64, 128, 256, 512, and 1,024, the network can create increasingly detailed borders. A 10,000-neuron model gets closer still, and a 100,000-neuron model gets very close to the true border, although it still misses some pieces.

Hope
That apparent failure does not contradict the universal approximation theorem. The theorem concerns the existence of a representation, and the surfaces involved must be continuous. The town's border itself is a discontinuous classification boundary, but it can arise from the intersection of continuous piecewise-linear surfaces.

Corey
The practical problem is optimization. Neural networks are trained with back propagation and gradient descent, which make small iterative parameter updates. Those algorithms do not guarantee that training will find the best solution, or even a good solution.

Hope
A network begins with random weights, so its fold lines and output surfaces start in random positions. The loss, such as cross-entropy loss, measures how wrong the predictions are. Back propagation computes gradients telling us how changing each weight and bias would affect that loss.

Corey
For instance, if a first-layer plane is tilted too steeply in one direction, its gradient may tell gradient descent to increase the relevant weight, making the plane flatter. A bias gradient can tell the optimizer to shift the plane upward. That movement also shifts the ReLU fold line and changes the final decision boundary.

Hope
One unlucky initialization can create a serious problem. Suppose the model initially puts the Netherlands surface above the Belgium surface everywhere, even though we want the opposite orientation in the center. Training may push the surfaces in the right vertical direction, but in the process it can move the important decision boundaries outside the map.

Corey
Then the whole town can fall into the zeroed-out part of a ReLU plane. Once a neuron is zeroed everywhere, its gradient is also zero everywhere. That neuron becomes effectively dead, and gradient descent cannot easily recover the useful fold it needed to create.

Hope
So even when a good five-neuron solution exists, a particular training path may fail to reach it. Very wide networks can also be difficult to train successfully, and the theorem gives no exact neuron count for a particular problem. It is even possible that 100,000 neurons simply isn't enough for this shallow architecture.

Corey
Now compare that with depth. Instead of putting 128 neurons in one wide layer, arrange them as four layers of 32 neurons, passing each layer's output into the next. In the example, this five-layer network, with only about 130 total neurons, learns a more precise border than the 100,000-neuron shallow model.

Hope
The reason is that later layers do not fold simple planes. They fold surfaces that have already been folded by earlier layers. A first-layer neuron creates one fold, but a neuron in the next layer may encounter several separate planar pieces crossing the zero-height plane.

Corey
When ReLU folds that more complicated surface, each crossing creates a new fold line. The folds can occur at different angles and at the joints between the earlier planes. So one neuron in a later layer can produce multiple geometrically distinct folds in the original map.

Hope
In a small example with two neurons per layer, the first layer creates two folds and four regions. A second hidden layer can split those into ten regions. The final layer then combines the resulting pieces into confidence surfaces, whose intersection forms a more complex, piecewise-linear border.

Corey
A shallow network with the same six neurons might create seven regions by stacking separate line-based folds. Its decision boundary may still work, but its tiling has a simpler character. The deeper network repeatedly reuses the folding, scaling, and combining operations, so the patterns compound rather than merely accumulate.

Hope
This compounding effect appears in theoretical region-count results for ReLU networks. The maximum number of regions grows polynomially with width in a shallow network, but can grow exponentially with depth. For two neurons per layer and two inputs, the stated bound gives 16 possible regions for two hidden layers, 64 for four layers, 256 for five layers, and so on.

Corey
For comparison, putting 64 neurons into one shallow first layer gives a theoretical maximum of 281 regions, while arranging those neurons across four layers gives a theoretical maximum of more than 70 million regions. Those are upper bounds, not typical results, but they illustrate why depth can be so powerful.

Hope
In practice, the bounds are loose. Real networks usually do not achieve exponential region growth every time another layer is added. Some neurons can also be dead: their entire incoming surface lies below zero, so ReLU turns every input into zero and that neuron contributes no colored region.

Corey
That is another reminder that architecture alone does not guarantee efficient use of capacity. Gradient descent may leave some neurons inactive. Still, deeper networks can create useful arrangements of regions that would require an enormous number of neurons in a shallow model.

Hope
As the example scales to eight neurons in each of the first two layers, the first layer creates 19 regions, while the next layer can produce 102. Some of those folds become tiny polygons near the town's border, allowing the model to capture fine geographic details.

Corey
Adding another layer makes the recursive geometry even richer. During training, the model first captures the broad structure of the town, then progressively tightens the boundary and adds small regions around the fine details. With five layers and 32 neurons per layer, the final boundary captures every region in the example.

Hope
So the main lesson is not that a neural network magically understands a map. It builds a hierarchy of piecewise-linear transformations. Early layers create folds, later layers fold and recombine those already-transformed surfaces, and the final outputs compare confidence surfaces to produce a decision boundary.

Corey
And the universal approximation theorem tells us that sufficient width can provide the representational power in principle. Deep learning adds an efficiency advantage: composition lets later neurons create far more complicated partitions of the input space than the same neurons could create in one shallow layer.

Hope
That also explains the important distinction between representation and learning. A network may be capable of expressing an excellent border, yet random initialization, dead ReLUs, limited width, or the behavior of gradient descent may prevent training from finding it.

Corey
Ultimately, a surprisingly small collection of linear models, combined with nonlinear activation functions and stacked across layers, can represent extraordinarily complex patterns. We can visualize that process as repeated folding, scaling, and combining of the input space.

Hope
And that is why depth matters: not because each individual neuron becomes more complicated, but because simple operations composed repeatedly create geometry with much greater expressive power.

Ask anything
We've read this whole study set, so questions about it get the best answers.