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

Neural Networks, Universal Approximation, and the Power of Depth

1. Universal approximation

The universal approximation theorem states that a sufficiently wide neural network with a single hidden layer can represent any continuous function on a bounded domain to arbitrarily high precision, provided the network uses a suitable nonlinear activation function.

In simplified terms:

A two-layer neural network can represent extremely complicated relationships, but the theorem does not guarantee that training will find the required parameters or that the network will do so efficiently.

The theorem concerns the network’s representational capacity—what functions can exist within the architecture—not the practical ability of an optimization algorithm to discover those functions.

Geographic example

Consider the complicated border between Belgium and the Netherlands in the municipality of Baarle-Hertog. The border is highly irregular and divides the map into many separate regions.

A neural network can receive the coordinates of a point:

  • x1x_1x1​: one geographic coordinate, such as latitude

  • x2x_2x2​: another geographic coordinate, such as longitude

It then produces confidence values for the point belonging to each country.

A sufficiently wide two-layer network theoretically exists that can approximate this irregular border as closely as desired. Increasing the number of neurons in the first layer gives the network more geometric pieces with which to construct the border.


2. Why a single linear layer is limited

Each neuron in a basic single-layer model computes a linear function of the input coordinates:

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

where:

  • m1m_1m1​ and m2m_2m2​ are learned weights

  • bbb is a learned bias

  • the weights control the plane’s slope in different directions

  • the bias shifts the plane vertically

When the two input coordinates are plotted horizontally, the neuron’s output can be visualized as a tilted plane.

Linear decision boundaries

If one neuron represents Belgium and another represents the Netherlands, the model compares the heights of two planes. The boundary between the two countries is where the planes have equal height.

Two planes intersect in a straight line. Therefore, a model made only from linear operations can create only a linear decision boundary in the input space.

This is insufficient for Baarle-Hertog because its border is not a single straight line. It contains multiple separated regions and intricate boundaries.

Example calculation

Suppose a point has coordinates:

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

A first-layer neuron computes:

z=m1(0.6)+m2(0.4)+bz = m_1(0.6) + m_2(0.4) + bz=m1​(0.6)+m2​(0.4)+b

For one particular set of learned parameters, the result may be:

z=−0.14z = -0.14z=−0.14

This value represents the height of that neuron’s plane at the selected point.


3. Why stacking linear layers alone does not help

Adding layers does not automatically make a neural network nonlinear.

Suppose the first layer contains two linear neurons:

h1=m1(1)x1+m2(1)x2+b1(1)h_1 = m_1^{(1)}x_1 + m_2^{(1)}x_2 + b_1^{(1)}h1​=m1(1)​x1​+m2(1)​x2​+b1(1)​
h2=m1(1,2)x1+m2(1,2)x2+b2(1)h_2 = m_1^{(1,2)}x_1 + m_2^{(1,2)}x_2 + b_2^{(1)}h2​=m1(1,2)​x1​+m2(1,2)​x2​+b2(1)​

A neuron in the next layer might compute:

y=w1h1+w2h2+by = w_1h_1 + w_2h_2 + by=w1​h1​+w2​h2​+b

Substituting the first-layer equations into the second-layer equation gives:

y=w1(m1(1)x1+m2(1)x2+b1(1))+w2(m1(1,2)x1+m2(1,2)x2+b2(1))+by = w_1\left(m_1^{(1)}x_1 + m_2^{(1)}x_2 + b_1^{(1)}\right) + w_2\left(m_1^{(1,2)}x_1 + m_2^{(1,2)}x_2 + b_2^{(1)}\right) +by=w1​(m1(1)​x1​+m2(1)​x2​+b1(1)​)+w2​(m1(1,2)​x1​+m2(1,2)​x2​+b2(1)​)+b

After distributing and collecting terms, this becomes:

y=M1x1+M2x2+By = M_1x_1 + M_2x_2 + By=M1​x1​+M2​x2​+B

This is still just a plane.

Composing linear functions produces another linear function.

Therefore, a network with multiple layers of only linear neurons is effectively equivalent to a single linear layer. Nonlinear activation functions are necessary for depth to provide additional expressive power.


4. The ReLU activation function

The most important activation function in the example is the rectified linear unit, or ReLU.

It is defined as:

ReLU⁡(z)=max⁡(0,z)\operatorname{ReLU}(z) = \max(0,z)ReLU(z)=max(0,z)

Equivalently:

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

Examples:

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

Geometric interpretation

Before ReLU, a neuron produces a complete tilted plane. ReLU modifies this plane:

  • Regions below height 000 are clipped upward to height 000

  • Regions above height 000 remain unchanged

  • The plane is therefore folded along the line where its height equals zero

The line satisfying

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

is the neuron’s fold line or activation boundary.

The location and orientation of this fold line are learned through the neuron’s weights and bias.

Folding, scaling, and combining

A hidden neuron performs three important operations:

  1. Folding: ReLU clips all negative values to zero.

  2. Scaling: The next layer multiplies the activated output by a learned weight.

  3. Combining: Several activated outputs are added together.

A negative weight in the next layer can flip a folded region upside down. A positive weight can raise or scale it. The sum of many such bent surfaces produces a more complex piecewise-linear surface.


5. Two-layer networks as folded geometric surfaces

A two-layer network can be understood geometrically as follows:

  1. The first layer creates several fold lines in the input map.

  2. ReLU folds the input planes along those lines.

  3. The second layer scales and adds the folded surfaces.

  4. Separate output neurons create separate confidence surfaces.

  5. The intersection of those surfaces becomes the decision boundary.

Example with three hidden neurons

Suppose the first layer has three neurons. Each neuron creates one fold line. These three lines divide the map into multiple regions.

In the illustrated arrangement, the three fold lines divide the map into five regions. Within each region, the output surface is planar, but neighboring regions can have different slopes and heights.

The first output neuron creates one surface, and the second output neuron creates another. Their heights represent confidence in the two countries:

  • One surface represents confidence in the Netherlands

  • The other represents confidence in Belgium

The model assigns a point to the country whose output surface is higher.

The decision boundary is the set of points where the two surfaces have equal height:

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​)

At this intersection, the model is equally confident in both countries.

Piecewise-linear surfaces

Each ReLU neuron is piecewise linear:

  • One linear behavior occurs where its input is negative

  • Another linear behavior occurs where its input is nonnegative

When many ReLU neurons are combined, the resulting function remains piecewise linear but can contain many connected regions with different planes.

This allows a neural network to approximate curved or irregular boundaries using many small linear pieces.


6. Increasing width in a shallow network

A two-layer network becomes more expressive as more neurons are added to its first layer.

Progressively wider models

The geometric progression is:

  • 8 neurons: a small collection of folds creates a more detailed border

  • 16 neurons: more regions and more complex intersections

  • 32 neurons: increasingly detailed piecewise-linear surfaces

  • 64 neurons: finer subdivisions of the map

  • 128 neurons: increasingly close approximation

  • 256, 512, and 1,024 neurons: many additional fold lines and regions

  • 10,000 neurons: a much more detailed border

  • 100,000 neurons: an even closer approximation, though still not perfect in the experiment

The final decision boundary becomes more detailed as the first-layer width increases. Each additional hidden neuron provides another potential fold line and another piece with which the output surfaces can be shaped.

However, even a very wide network may fail to reproduce the exact border after training.


7. What the universal approximation theorem does not guarantee

The theorem is often misunderstood as saying that neural networks can automatically learn anything. Its actual meaning is more limited.

The theorem guarantees representability

For a suitable continuous target function, the theorem says that there exists a sufficiently wide two-layer network whose output can approximate that function arbitrarily well.

It does not specify:

  • How many neurons are required

  • What the correct weights and biases are

  • How to initialize the network

  • Which optimizer or learning rate to use

  • How long training will take

  • Whether gradient descent will find a useful solution

  • Whether the required shallow network is computationally practical

The border itself is not continuous

A classification border is often discontinuous if it is represented as a hard country label. The theorem instead concerns the continuity of the output surfaces whose intersection defines the border.

The two confidence surfaces can be continuous even when the final classification changes abruptly from one country to another.

Representability versus learnability

There is a fundamental distinction:

  • Representability: A set of parameters exists that can express the desired function.

  • Learnability: The training procedure can find those parameters from a random initialization.

The universal approximation theorem addresses the first question, not the second.


8. Training with backpropagation and gradient descent

Modern neural networks generally learn their parameters through backpropagation and gradient descent.

Training process

  1. The network is initialized with random weights and biases.

  2. Input coordinates are passed forward through the network.

  3. The network produces confidence values.

  4. A loss function measures the prediction error.

  5. Backpropagation computes how much each parameter contributed to the error.

  6. Gradient descent changes the parameters in directions expected to reduce the loss.

  7. The process repeats over many training steps.

For classification, the error can be measured using cross-entropy loss.

The parameters are updated according to the general rule:

θnew=θold−η∇θL\theta_{\text{new}} = \theta_{\text{old}} - \eta \nabla_\theta Lθnew​=θold​−η∇θ​L

where:

  • θ\thetaθ represents all weights and biases

  • LLL is the loss

  • ∇θL\nabla_\theta L∇θ​L is the gradient of the loss

  • η\etaη is the learning rate

Gradient descent makes local, iterative adjustments. It does not directly search through all possible parameter configurations.


9. A successful gradient update

Consider a randomly initialized five-neuron network. A particular point in Belgium may initially be classified incorrectly as belonging to the Netherlands.

Backpropagation might produce large negative gradients for a neuron’s weight and bias.

Suppose a weight mmm is currently negative, causing the corresponding plane to slope downward too sharply in the x1x_1x1​ direction. If the gradient indicates that mmm should increase, the plane becomes flatter.

A negative bias gradient can indicate that the plane should move upward. Together, these changes can:

  • Alter the slope of the plane

  • Move the ReLU fold line

  • Shift the boundary between active and zeroed regions

  • Lower the incorrect country’s confidence

  • Move the final decision boundary toward the correct location

Repeating these updates allows the network to adjust both:

  • The positions of the hidden-layer folds

  • The ways in which the final layer combines the folded surfaces

Eventually, the output surfaces may form a useful border around the Belgian regions.


10. The dying ReLU problem

A different random initialization can lead to a serious training failure.

Suppose the network initially places the Netherlands surface above the Belgium surface throughout the central region, even though the desired arrangement is the opposite.

Gradient descent may begin correcting the orientation by:

  • Lowering the Netherlands surface

  • Raising the Belgium surface

  • Moving their intersection boundaries

However, the updates can push the relevant fold lines outside the town. If all the town’s input points fall into the negative side of a ReLU neuron, that neuron outputs zero everywhere on the map.

Zero gradients

For negative inputs, ReLU has derivative:

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

Therefore, if an entire relevant region is zeroed out, the gradient cannot effectively pass backward through that neuron.

The neuron becomes inactive, or dead.

A dead neuron:

  • Outputs zero for the relevant inputs

  • Receives zero or negligible gradients

  • Cannot easily move its fold line back into a useful location

  • Contributes no useful nonlinear structure

If enough neurons become inactive, the network may be left with something close to a single linear plane. It then converges to a suboptimal linear boundary rather than the desired complex border.

A solution may exist within the architecture, yet gradient descent may be unable to reach it from a particular initialization.

This explains why a five-neuron network can sometimes learn successfully and sometimes fail, despite having the same architecture.


11. Why a very wide network can still fail

A 100,000-neuron network has enormous representational capacity, but its training may still fail to reproduce the border.

Possible explanations include:

  • The desired parameter configuration may be difficult to reach

  • Many neurons may be poorly positioned after initialization

  • ReLU units may become inactive

  • The optimization process may stop before finding a better configuration

  • The architecture may still require more neurons than expected

  • The chosen optimizer settings may be unsuitable

The failure is not necessarily caused by becoming trapped in a conventional local minimum. In very high-dimensional models, the probability of getting stuck in a simple isolated local minimum can be small. Training difficulties may instead arise from inactive units, poorly conditioned regions, optimization plateaus, or other structures in the loss landscape.

The important point is that more width does not automatically make optimization easy.


12. Deep networks versus wide networks

A major result illustrated by the example is that arranging neurons in multiple layers can be much more efficient than placing all of them in one very wide layer.

Comparison of architectures

A shallow model may use:

  • One hidden layer

  • Many neurons in that layer

  • A single sequence of folds applied directly to the input map

A deep model may use:

  • Several hidden layers

  • Fewer neurons per layer

  • Repeated transformations of already-transformed representations

For example:

  • A shallow model with 128 hidden neurons may struggle to represent the entire border

  • A deeper model with four hidden layers of 32 neurons each, or approximately 130 total neurons including the output layer, can learn a more precise border

The deeper network is more powerful because later layers do not merely fold the original map. They fold the already-folded and recombined representation produced by earlier layers.


13. Geometry of a deeper network

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

First layer

The first layer creates two fold lines. Together, these can divide the original two-dimensional map into four regions.

The second layer then receives the two bent surfaces produced by the first layer.

Second layer

Without another nonlinear activation, the second layer would simply combine the first-layer outputs linearly. With ReLU, however, each second-layer neuron folds an already-complex surface.

A first-layer output surface may contain three separate planar regions that cross the height-000 plane. Applying ReLU creates one fold for each region crossing that plane.

Thus, a single second-layer neuron can create several new fold lines, rather than only one simple fold line in the original input space.

These new folds:

  • Occur at different angles

  • Bend at the joints of the earlier piecewise-linear surfaces

  • Divide existing regions into additional subregions

  • Produce a more complex tiling of the input map

In the example:

  • The first layer creates four regions

  • The second layer divides them into ten regions

  • The final layer combines these regions into confidence surfaces

  • The intersection of those surfaces forms a more detailed border

Repeated composition

Each layer repeats a sequence:

  1. Scale existing features

  2. Add them together

  3. Apply ReLU

  4. Create new folds in the transformed representation

Because each layer operates on the output of the previous layer, the geometric complexity compounds.

This is why deep networks can produce structures that are qualitatively different from simply stacking many lines or planes in the original input space.


14. Region-count growth

The number of linear regions a ReLU network can create provides a way to quantify the advantage of depth.

A linear region is an area of the input space within which the network behaves according to one particular linear function. Different ReLU activation patterns define different regions.

Shallow networks

For a two-dimensional input, each first-layer ReLU neuron contributes a fold line. A shallow network is therefore related to the problem of dividing a plane with several lines.

The maximum number of regions formed by ddd lines in general position is:

Rshallow=∑j=02(dj)=1+d+d(d−1)2R_{\text{shallow}} = \sum_{j=0}^{2}\binom{d}{j} = 1+d+\frac{d(d-1)}{2}Rshallow​=∑j=02​(jd​)=1+d+2d(d−1)​

This grows polynomially with the number of neurons.

For example, with d=64d=64d=64 neurons:

Rshallow=1+64+64⋅632=2,081R_{\text{shallow}} = 1+64+\frac{64\cdot 63}{2} = 2{,}081Rshallow​=1+64+264⋅63​=2,081

The source’s illustrative count uses a related theoretical upper-bound calculation and reports approximately 2,8112{,}8112,811 possible regions; the exact value depends on the precise bound and architectural assumptions. The central conclusion is that shallow region counts grow polynomially with width.

Deep networks

For a network with input dimension did_idi​, width ddd per hidden layer, and KKK hidden layers, a commonly used theoretical upper bound has the form:

Rdeep≤∏k=1K(∑j=0di(dj))R_{\text{deep}} \leq \prod_{k=1}^{K} \left( \sum_{j=0}^{d_i} \binom{d}{j} \right)Rdeep​≤∏k=1K​(∑j=0di​​(jd​))

For two-dimensional inputs and two neurons per layer, the relevant factor is:

∑j=02(2j)=1+2+1=4\sum_{j=0}^{2}\binom{2}{j} = 1+2+1 = 4∑j=02​(j2​)=1+2+1=4

Therefore, the illustrative maximum grows as:

  • Two hidden layers:

42=164^2 = 1642=16
  • Three hidden layers:

43=644^3 = 6443=64
  • Four hidden layers:

44=2564^4 = 25644=256

Each additional layer can theoretically multiply the number of regions by another factor of four in this configuration.

The source also contrasts a network with 64 neurons in one hidden layer with a four-layer arrangement of those neurons. The shallow architecture has only a few thousand possible regions under the relevant bound, whereas the deep architecture can have a theoretical upper bound exceeding tens of millions.

Important limitation

These are theoretical upper bounds, not typical observed counts.

In practice:

  • Neurons may create overlapping or redundant folds

  • Some neurons may be dead

  • The learned parameters may not place folds optimally

  • Many theoretically possible activation patterns may never occur

  • The network may not use its full geometric capacity

Consequently, deep networks do not necessarily produce an exponential number of useful regions during ordinary training. Nevertheless, depth gives the architecture access to much richer compositions than a comparably sized shallow network.


15. Empirical progression of deeper models

The geometric examples demonstrate how complexity develops as the network becomes deeper and wider.

Three-layer, six-neuron model

A model with two neurons in each of three hidden layers can:

  • Create four regions after its first layer

  • Produce ten regions after its second layer

  • Generate final confidence surfaces with piecewise-linear curvature

  • Form a more detailed decision boundary than a similarly sized shallow network

Four-layer model with eight neurons per layer

Increasing the first two layers to eight neurons produces:

  • Nineteen regions after the first layer

  • Approximately 102 regions after the second layer

  • More intricate patterns of folds and joints

  • A decision boundary that captures the two largest sections of the town

Some second-layer neurons may have no active colored regions. This indicates that their entire input surface lies below zero and is mapped to zero by ReLU. Such neurons are examples of dead neurons.

Four-layer model and fine border details

Adding another hidden layer allows the network to repeatedly fold its intermediate surfaces. Some later-layer neurons create tiny regions around the town’s border.

These small polygons are important because they allow the model to capture:

  • Narrow sections of the border

  • Small irregularities

  • Separate regions

  • Fine-scale geometric details

The network is not explicitly told to create these tiny shapes. Backpropagation adjusts its parameters so that these structures reduce the classification loss.

Five-layer model with 32 neurons per layer

A deeper model with five total layers and 32 neurons per layer can learn a highly detailed border.

Compared with smaller models, it benefits more from additional training steps:

  • Early training identifies the broad structure of the town

  • Later training tightens the boundary

  • Additional regions form around fine details

  • The final boundary can capture nearly every region in the map

This illustrates how depth allows a relatively modest number of neurons to produce a highly complex function.


16. Why depth is efficient

The key advantage of depth is feature reuse through composition.

A shallow network must create every fold directly in the original input space. A deep network can:

  1. Create simple regions in an early layer

  2. Combine those regions into more complex surfaces

  3. Fold the new surfaces into additional regions

  4. Reuse earlier structure in later transformations

  5. Continue this process across many layers

The same operations—scaling, adding, and applying ReLU—become much more powerful when repeatedly composed.

A shallow network may need many independent neurons to approximate a complicated function. A deep network can construct the same complexity hierarchically, using earlier computations as building blocks.

Depth enables efficient composition: later layers operate on increasingly rich representations rather than repeatedly starting from the raw input.

This is one reason deep learning can solve complex problems with far fewer parameters than an equivalent shallow architecture might require.


17. Main conclusions

  • Linear layers alone are insufficient for complex classification because their composition remains linear.

  • ReLU introduces nonlinearity by clipping negative values to zero and geometrically folding planes.

  • A two-layer network can combine many folds into piecewise-linear confidence surfaces.

  • The universal approximation theorem guarantees representational capacity under suitable conditions, not successful training.

  • Gradient descent is not guaranteed to find the best available solution.

  • Dead ReLU neurons can create zero gradients and prevent recovery from poor configurations.

  • Increasing width gives a shallow model more fold lines, but may be inefficient and difficult to train.

  • Increasing depth allows later layers to fold already-complex surfaces, causing geometric complexity to compound.

  • Deep networks can create far more linear regions than shallow networks with comparable neuron counts, at least in theoretical upper bounds.

  • Theoretical region counts are loose bounds and do not directly predict how many useful regions a trained model will actually form.

  • The central power of deep learning comes from repeatedly composing simple operations into increasingly expressive representations.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent