1. Home
  2. Explore
  3. Computer Science
  4. Universal Approximation Theorem

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Universal Approximation Theorem

How Deep Neural Networks Learn Complex Geometric Boundaries

A neural network can begin with very simple mathematical pieces—linear functions, folds, scaling, and addition—and combine them into remarkably complex decision boundaries. The key idea is that depth allows these simple operations to be repeatedly composed, so that later layers can transform patterns created by earlier layers.

This lesson develops that idea geometrically using a classification problem: separating Belgium from the Netherlands in the municipality of Baarle-Hertog, whose border contains many intricate pieces.

1. The classification problem as a geometric problem

Suppose each location on a map is represented by two input values:

  • x1x_1x1​: one coordinate, such as latitude
  • x2x_2x2​: another coordinate, such as longitude

The neural network receives the point (x1,x2)(x_1,x_2)(x1​,x2​) and must decide whether it belongs to Belgium or the Netherlands.

The network can produce one output representing confidence that the point is in the Netherlands and another representing confidence that it is in Belgium. The classification is determined by comparing those two outputs:

  • If the Belgium output is higher, the point is classified as Belgium.
  • If the Netherlands output is higher, the point is classified as the Netherlands.
  • The set of points where the two outputs are equal forms the decision boundary.

This boundary is the model’s learned approximation of the real geographic border.

Why one linear layer is insufficient

A single neuron without a nonlinear activation function computes a linear expression of the form

z=m1x1+m2x2+b,z = m_1x_1 + m_2x_2 + b,z=m1​x1​+m2​x2​+b,

where:

  • m1m_1m1​ and m2m_2m2​ are learned weights
  • bbb is a learned bias
  • zzz is the neuron’s output

Geometrically, this expression describes a tilted plane above the two-dimensional map. The weights determine the plane’s slope in the two coordinate directions, while the bias shifts the entire plane upward or downward.

If two neurons produce two planes—one for Belgium and one for the Netherlands—their intersection is a straight line on the map. One side of that line is assigned to Belgium, and the other side is assigned to the Netherlands.

That works for a simple border, but Baarle-Hertog’s border is not a single straight line. It contains many separated regions and irregular turns. No matter how the two planes are tilted, their intersection remains a single straight line.

A network made only from linear operations cannot create a genuinely nonlinear decision boundary, because composing linear functions produces another linear function.

2. Why stacking linear layers alone does not help

It might seem that adding another layer of neurons should make the network more powerful. However, if the layers only perform linear operations, the additional layer does not create new geometric complexity.

Consider two first-layer neurons:

z1=m1(1)x1+m2(1)x2+b(1)z_1 = m_1^{(1)}x_1 + m_2^{(1)}x_2 + b^{(1)}z1​=m1(1)​x1​+m2(1)​x2​+b(1)

and

z2=m1(2)x1+m2(2)x2+b(2).z_2 = m_1^{(2)}x_1 + m_2^{(2)}x_2 + b^{(2)}.z2​=m1(2)​x1​+m2(2)​x2​+b(2).

A neuron in the next layer might compute

y=w1z1+w2z2+b(2).y = w_1z_1 + w_2z_2 + b^{(2)}.y=w1​z1​+w2​z2​+b(2).

Substituting the first two equations into the second gives

y=w1(m1(1)x1+m2(1)x2+b(1))+w2(m1(2)x1+m2(2)x2+b(2))+b(2).y = w_1\left(m_1^{(1)}x_1+m_2^{(1)}x_2+b^{(1)}\right) + w_2\left(m_1^{(2)}x_1+m_2^{(2)}x_2+b^{(2)}\right) + b^{(2)}.y=w1​(m1(1)​x1​+m2(1)​x2​+b(1))+w2​(m1(2)​x1​+m2(2)​x2​+b(2))+b(2).

After distributing and collecting terms, this becomes

y=Ax1+Bx2+C,y = Ax_1 + Bx_2 + C,y=Ax1​+Bx2​+C,

where AAA, BBB, and CCC are new constants formed from the original weights and biases.

This has exactly the same form as a single plane. Therefore, several layers of linear neurons collapse mathematically into one linear transformation.

The essential role of activation functions

A neural network becomes substantially more powerful when a nonlinear activation function is inserted between layers. The activation changes the shape of the information before the next layer processes it.

Without an activation function:

  • planes remain planes;
  • straight boundaries remain straight;
  • extra layers mainly reparameterize the same type of linear relationship.

With an activation function:

  • planes can be folded or clipped;
  • later layers receive shapes that are no longer simple planes;
  • repeated transformations can create complex regions and boundaries.

Think About It

Why would adding ten layers of purely linear neurons fail to solve a border problem that one nonlinear layer cannot solve? The reason is that all ten layers still collapse into one overall linear transformation.

3. The rectified linear unit and geometric folding

One widely used activation function is the rectified linear unit, usually called ReLU. It is defined by

ReLU⁡(z)={0,z<0,z,z≥0.\operatorname{ReLU}(z)= \begin{cases} 0, & z<0,\\ z, & z\ge 0. \end{cases}ReLU(z)={0,z,​z<0,z≥0.​

ReLU leaves positive values unchanged but replaces negative values with zero.

For example,

ReLU⁡(−1)=0\operatorname{ReLU}(-1)=0ReLU(−1)=0

and

ReLU⁡(1)=1.\operatorname{ReLU}(1)=1.ReLU(1)=1.

ReLU applied to a plane

Before activation, a neuron produces a plane. Some parts of that plane may lie above height 000, while other parts lie below height 000.

ReLU clips every part below height 000 up to the horizontal plane z=0z=0z=0. The result is no longer one uninterrupted tilted plane:

  • the positive part remains tilted;
  • the negative part is flattened at zero;
  • the boundary between these parts is a fold line.

This is why the geometric interpretation describes ReLU as folding the map along a line.

The location of the fold line is determined by the neuron’s weights and bias. The line is where

m1x1+m2x2+b=0.m_1x_1+m_2x_2+b=0.m1​x1​+m2​x2​+b=0.

Changing the weights changes the orientation of the line. Changing the bias shifts its location.

Each ReLU neuron in the first hidden layer therefore creates one possible fold in the input map.

4. Walking through a numerical example

Suppose a point on the map has coordinates

x1=0.6,x2=0.4.x_1=0.6,\qquad x_2=0.4.x1​=0.6,x2​=0.4.

Assume the first neuron computes

z1=m1x1+m2x2+b=−0.14.z_1=m_1x_1+m_2x_2+b=-0.14.z1​=m1​x1​+m2​x2​+b=−0.14.

A second neuron computes

z2=−0.33.z_2=-0.33.z2​=−0.33.

These values represent the heights of the point on the two neurons’ original planes.

Applying ReLU gives

ReLU⁡(−0.14)=0\operatorname{ReLU}(-0.14)=0ReLU(−0.14)=0

and

ReLU⁡(−0.33)=0.\operatorname{ReLU}(-0.33)=0.ReLU(−0.33)=0.

Thus, the original point (0.6,0.4)(0.6,0.4)(0.6,0.4) is transformed by the first layer into the point

(0,0)(0,0)(0,0)

in the next layer’s representation.

The final layer then takes these activated values, multiplies them by learned weights, and adds biases. For example, one output might become 0.030.030.03, while another might become −0.89-0.89−0.89.

The output associated with Belgium is higher in this example, so the model classifies the point as Belgium.

The geometric picture and the numerical calculation describe the same process:

  • Numerically, the point passes through formulas and activation functions.
  • Geometrically, the map is folded and the point moves across the resulting surfaces.

The geometric view is useful because it shows how the network transforms all points in the map simultaneously.

5. From folded planes to confidence surfaces

Consider a network with two neurons in its first hidden layer and two output neurons, one associated with each country.

Each first-layer neuron creates a ReLU-folded plane. The output neuron for Belgium takes the two folded surfaces, scales them by learned weights, and adds them together. Depending on the signs of its weights, it can:

  • raise parts of the surfaces;
  • lower parts of the surfaces;
  • flip a folded region upside down;
  • shift the entire result using its bias.

The result is a piecewise-linear surface representing the model’s confidence in Belgium.

The Netherlands output neuron performs a similar combination using different learned parameters. It creates a second surface representing confidence in the Netherlands.

The two surfaces can be imagined as heights above the map:

  • a higher Belgium surface means greater Belgium confidence;
  • a higher Netherlands surface means greater Netherlands confidence.

The decision boundary occurs where the two surfaces intersect:

fBelgium(x1,x2)=fNetherlands(x1,x2).f_{\text{Belgium}}(x_1,x_2) = f_{\text{Netherlands}}(x_1,x_2).fBelgium​(x1​,x2​)=fNetherlands​(x1​,x2​).

On one side of the intersection, the Belgium surface is higher. On the other side, the Netherlands surface is higher.

How the number of neurons changes the boundary

If the first layer has several ReLU neurons, each one contributes a fold line. These lines divide the input map into separate regions.

Within each region, every neuron has a fixed activation pattern:

  • some neurons are active and pass positive values through;
  • others are inactive and output zero.

Because the activation pattern is fixed inside a region, the network behaves linearly within that region. The overall output surface is therefore piecewise linear: one plane in one region, another plane in a neighboring region, and so on.

More first-layer neurons mean more fold lines and potentially more regions. More regions allow the output surfaces to change slope repeatedly, which allows their intersection to trace a more complicated border.

6. The universal approximation theorem

The content attributes a result from 1989 to George Sabeno, commonly referred to as the universal approximation theorem.

In simplified form, the theorem says that a sufficiently wide neural network with one hidden layer can represent any continuous function to arbitrarily high precision, assuming an appropriate nonlinear activation function.

The important phrase is represent. The theorem says that a suitable network exists. It does not automatically say that ordinary training will find that network.

For the map problem, the theorem suggests that by adding enough neurons to a two-layer network, the network should be capable of producing surfaces whose intersection approximates the geographic border as closely as desired.

This explains why increasingly wide models can produce increasingly detailed boundaries:

  • a model with a small number of neurons creates only a few folds;
  • a model with more neurons creates more regions;
  • a very wide model can, in principle, approximate a highly intricate border.

A crucial qualification: the theorem is not “neural networks can learn anything”

The theorem is often misunderstood. It does not say that neural networks automatically learn every possible task, nor does it specify an effective training procedure.

It says that a sufficiently wide network is capable of representing a broad class of continuous functions.

Several limitations matter:

  1. The required width is not specified.
    The theorem does not tell how many neurons a particular problem requires.

  2. Representation is different from learning.
    A good set of parameters may exist, but gradient descent may fail to find it.

  3. The target border itself may be discontinuous.
    A hard classification boundary jumps from one class to another. The relevant continuous objects are the confidence surfaces whose intersection creates the boundary.

  4. A shallow solution may be extremely inefficient.
    Some functions require exponentially more neurons in a shallow network than in a deep one.

7. Why wide networks may still fail during training

A two-layer network with 100,000100{,}000100,000 first-layer neurons may have enough representational capacity in principle, yet still fail to learn the exact border in practice.

The reason is the training process.

Modern networks are commonly trained using:

  1. Forward propagation, which computes the outputs.
  2. Loss calculation, which measures the error.
  3. Backpropagation, which computes how each parameter contributed to that error.
  4. Gradient descent, which adjusts parameters in a direction expected to reduce the loss.

For a parameter θ\thetaθ, a gradient-descent update has the general form

θnew=θold−η∂L∂θ,\theta_{\text{new}} = \theta_{\text{old}} - \eta\frac{\partial L}{\partial \theta},θnew​=θold​−η∂θ∂L​,

where:

  • LLL is the loss;
  • ∂L∂θ\frac{\partial L}{\partial \theta}∂θ∂L​ is the loss gradient;
  • η\etaη is the learning rate.

The update is local: it makes a small change based on the current configuration. It does not inspect every possible configuration and choose the globally best one.

Random initialization matters

Before training begins, the weights and biases are usually initialized randomly. This places the fold lines randomly across the map and creates random confidence surfaces.

Two networks with the same architecture can therefore begin in very different geometric states.

One initialization may place the surfaces in an orientation that gradient descent can improve efficiently. Another may place them in a configuration from which the desired arrangement is difficult or impossible to reach through the available gradients.

A failure caused by inactive ReLU regions

Suppose a region of the map lies entirely below zero for a particular first-layer neuron. ReLU maps the entire region to zero.

Within that inactive region, the derivative of ReLU is also zero:

ddzReLU⁡(z)=0when z<0.\frac{d}{dz}\operatorname{ReLU}(z)=0 \qquad\text{when }z<0.dzd​ReLU(z)=0when z<0.

As a result, gradient information cannot pass backward through that neuron for those inputs. The neuron may stop contributing useful changes to the model. Such a unit is often called a dead neuron.

A training failure can unfold geometrically as follows:

  1. The initial confidence surfaces have the wrong orientation.
  2. Gradient descent tries to reverse them by moving one surface down and another up.
  3. The fold boundaries are pushed away from the town.
  4. The entire town falls into the zero-output portion of one or more ReLU units.
  5. The gradients through those inactive units become zero.
  6. The network loses the ability to reposition those fold lines.
  7. The remaining active structure behaves approximately like a single plane.
  8. The model settles on a suboptimal, mostly linear boundary.

Thus, the existence of a good solution does not guarantee that gradient descent can reach it from a particular starting point.

Local minima are not the only concern

In very high-dimensional models, the standard explanation of training failure as being trapped in a small local minimum is often too simple. For large networks, the chance of encountering a traditional isolated local minimum may be relatively small.

Other difficulties can still prevent successful training:

  • poor parameterization;
  • inactive neurons;
  • unfavorable orientations;
  • slow or poorly directed optimization;
  • a very large number of parameters needed by a shallow representation.

The central distinction remains:

The universal approximation theorem guarantees expressive capacity, not successful optimization.

8. Why depth is more efficient than width

A shallow network can create many fold lines directly in the original input space. A deep network does something more powerful: it folds the already folded representation.

Suppose the first layer creates two folds. These folds divide the map into several regions. The next layer does not receive the original flat map. It receives surfaces that already contain joints and bends.

When ReLU is applied in the second layer, it clips these more complicated surfaces at height zero. A single neuron can therefore create multiple new fold lines—one wherever one of the surface’s planar pieces crosses the zero plane.

This is the key geometric advantage of depth:

  • a first-layer neuron folds a simple plane;
  • a later-layer neuron folds a surface made from earlier folds;
  • repeated folding creates increasingly intricate partitions.

A three-layer example

Consider a network with two neurons in each of three hidden layers.

First hidden layer

The first two neurons create two fold lines in the original map. These folds divide the map into approximately four activation regions.

Second hidden layer

The second layer combines the first-layer outputs into bent surfaces. These surfaces can contain several planar pieces joined along edges.

When ReLU is applied to one such surface, every planar piece that crosses z=0z=0z=0 can create a separate fold. The folds occur at different angles because the underlying pieces came from different first-layer regions.

Thus, one second-layer neuron can create several new folds rather than only one simple straight fold in the original map.

The second neuron in that layer creates another set of folds with different parameters.

Final layer

The final layer scales and combines the second-layer surfaces into the Belgium and Netherlands confidence surfaces. Their intersection becomes the learned border.

In the example described by the source, the first layer creates four regions, while the second layer transforms them into ten regions. The extra regions are not merely more straight strips; they form a much more intricate tiling of the map.

9. Region-count growth

The number of regions that a ReLU network can theoretically create grows much faster with depth than with width.

For a shallow network, the first-layer fold lines divide a two-dimensional map. If there are ddd lines in general position, the maximum number of regions is

∑j=02(dj)=1+d+(d2).\sum_{j=0}^{2}\binom{d}{j} = 1+d+\binom{d}{2}.j=0∑2​(jd​)=1+d+(2d​).

This is a polynomial function of ddd. For example, with 646464 neurons acting as 646464 fold lines, the theoretical maximum number of regions is

1+64+(642)=2081.1+64+\binom{64}{2} = 2081.1+64+(264​)=2081.

The source describes a broader theoretical expression for equal-width networks in terms of:

  • ddd: neurons per hidden layer;
  • did_idi​: input dimension;
  • KKK: number of hidden layers, excluding the final output layer.

The important structural feature is that the bound contains:

  • a polynomial factor associated with dividing the input space;
  • an exponential factor associated with repeated layers.

For the example with d=2d=2d=2 neurons per layer and di=2d_i=2di​=2 input dimensions, the source gives the sequence

22⋅4=162^2\cdot 4=1622⋅4=16

for two hidden layers, followed by

24⋅4=642^4\cdot 4=6424⋅4=64

for three hidden layers, and then larger values such as 256256256 as more layers are added.

The exact theoretical maximum is not necessarily achieved by a trained network. In the example, the model creates ten regions rather than the theoretical maximum of sixteen. The formula is an upper bound, not a promise.

The essential comparison is:

  • Width: more neurons add more folds, producing polynomial growth in the number of regions.
  • Depth: later folds act on earlier folds, producing exponential growth in the theoretical number of possible regions.

This difference is one reason deep learning can represent complicated functions using far fewer total neurons than a very wide shallow network.

A striking comparison

The source compares two arrangements of 646464 neurons:

  • placing all 646464 neurons in one wide first layer allows a theoretical maximum of about 281281281 regions under the stated setup;
  • arranging the neurons across four layers allows a theoretical maximum of more than 707070 million regions.

These values are theoretical upper bounds and can be very loose. Real networks do not generally achieve the full exponential rate. Nevertheless, the comparison illustrates the potential efficiency of composition.

Think About It

Why does a later neuron have more power than an earlier neuron even though both use the same ReLU operation? The later neuron acts on a surface that already contains multiple planes and joints, so one activation can create several new folds.

10. Deep networks learn reusable geometric structure

A deep network does not need to construct the final border in one step. Instead, it can build the border progressively.

A possible sequence is:

  1. The first layer captures broad divisions of the map.
  2. The next layer creates larger structural regions.
  3. Later layers add small folds around complicated parts of the border.
  4. The final layer combines those transformed regions into confidence surfaces.
  5. The intersection of those surfaces forms the final classification boundary.

This explains why a network with only a few layers can capture details that would require an enormous shallow layer.

In the described experiments:

  • a shallow model with 128128128 neurons struggles to match the entire border;
  • a deeper model with roughly 130130130 total neurons learns a more precise boundary;
  • models with progressively more hidden layers and neurons create increasingly detailed tilings;
  • a five-layer model with 323232 neurons per layer captures every region of the town’s border in the demonstration.

The deeper model’s progress can be understood during training. Early in optimization, it identifies the broad structure of the town. With additional gradient-descent steps, it creates and adjusts smaller regions near the border, tightening the fit around fine details.

11. Dead neurons and inefficient architecture use

Not every neuron contributes meaningfully after training. Some neurons may produce negative pre-activation values for every input. ReLU then sends every input to zero.

Such neurons are dead neurons. They are evidence that the network’s architecture has more capacity than the particular optimization process is using effectively.

Their presence also reinforces an important point: the number of neurons in an architecture is not the same as the number of useful geometric operations actually learned. Gradient descent does not guarantee that every neuron will be used efficiently.

A model may contain many parameters and still fail to represent a boundary well if:

  • important neurons become inactive;
  • fold lines are placed in unhelpful locations;
  • the network remains in a poor configuration;
  • the optimizer does not discover the useful arrangement.

12. Softmax and the location of the boundary

Classification networks often use a softmax function at the output to convert raw scores into probability-like values that sum to one.

For two classes, the raw output surfaces determine which class has the larger score. Softmax changes the numerical values into normalized confidence values, but it does not change where the two raw outputs are equal.

If

zBelgium=zNetherlands,z_{\text{Belgium}}=z_{\text{Netherlands}},zBelgium​=zNetherlands​,

then the two corresponding softmax probabilities are also equal. Therefore, softmax changes the appearance and interpretation of the outputs but not the location of the decision boundary.

For geometric reasoning about the border, the raw confidence surfaces are therefore sufficient.

13. The complete geometric picture

The entire network can now be understood as a sequence of transformations.

First layer: create folds

Each neuron computes a plane and applies ReLU. The result is a folded or clipped plane. Multiple neurons divide the original map into regions.

Middle layers: fold already-folded surfaces

Each later layer receives piecewise-linear surfaces rather than simple planes. ReLU folds these surfaces along multiple joints, creating many new regions with different shapes and orientations.

Final layer: create class-confidence surfaces

The final layer scales and adds the transformed surfaces. One resulting surface represents Belgium confidence, and another represents Netherlands confidence.

Decision boundary: intersect the surfaces

The model assigns each point to the class with the higher output. The set of equal-confidence points forms the learned boundary.

In compact form:

Neural networks learn complex boundaries by recursively folding, scaling, and combining their representations. Depth makes each new operation act on the complexity created by all previous operations.

Comprehensive review

The main ideas can be tied together as follows:

  1. A neuron without an activation function computes a plane over the input map.
  2. Two linear output surfaces intersect in a straight decision boundary.
  3. Stacking linear layers alone does not help because compositions of linear functions remain linear.
  4. ReLU introduces the essential nonlinearity by clipping negative values to zero.
  5. Geometrically, ReLU folds a surface along the location where its value equals zero.
  6. A first hidden layer creates fold lines that divide the input map into regions.
  7. Output neurons combine the folded representations into class-confidence surfaces.
  8. The decision boundary is where the confidence surfaces intersect.
  9. The universal approximation theorem states that a sufficiently wide network can represent broad classes of continuous functions to arbitrary precision.
  10. The theorem does not specify the required number of neurons or guarantee that gradient descent will find the appropriate parameters.
  11. Random initialization and zero gradients in inactive ReLU regions can lead to poor solutions and dead neurons.
  12. Deep networks are more efficient because later layers fold representations that are already piecewise linear and geometrically complex.
  13. Width generally increases the number of regions polynomially, while depth can create exponential growth in the theoretical number of regions.
  14. These theoretical bounds are upper limits, not guarantees, but they explain why deep networks can express intricate patterns with relatively few neurons.
  15. The ultimate power of deep learning comes not from any single neuron, but from composing simple transformations across many layers until a highly complex decision boundary emerges.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent