Recommended resources
The freely available resources this lesson will direct you to.
- Universal Approximation Theoremwww.youtube.com
- A shallow grip on neural networks (What is the "universal approximation theorem"?)www.youtube.com
- [PDF] Lecture 10 Expressivity and Universal Approximation Theorems Part 1mitliagkas.github.io
- How Neural Networks Approximate Any Function: A Mathematical Dive into Universal Approximation…medium.com
Welcome back. In our last lesson, we examined the crucial role of activation functions, tracing their evolution from the saturating Sigmoid and Tanh to the highly effective ReLU and the modern GELU. We saw how their mathematical properties, especially their gradients, directly impact a network's ability to be trained.
This raises a more fundamental question: why does the simple recipe of alternating linear transformations with any of these nonlinearities create such powerful models? Today, we will explore the theoretical answer provided by the Universal Approximation Theorem (UAT). This theorem is a cornerstone of deep learning theory, assuring us that neural networks possess the necessary expressive power to model a vast range of phenomena. We will state the theorem, build an intuition for why it's true, and critically discuss both its profound implications and its practical limitations.
The Power of a Single Hidden Layer
At its core, the Universal Approximation Theorem states that a surprisingly simple neural network—one with just a single hidden layer—is capable of approximating any continuous function to any desired degree of accuracy, provided it has enough neurons. This is a profound result. It tells us that the architecture of a feedforward network is, in principle, sufficient to represent an incredibly wide variety of functions.

Let's formalize this. One of the early and most cited versions of the theorem, proved by George Cybenko in 1989, can be stated as follows.
How Neural Networks Approximate Any Function: A Mathematical Dive into Universal Approximation…
This article provides an excellent overview of the theorem. We'll start with the formal statement to ground our discussion.
Please read the section titled "3. The Early Versions of Universal Approximation Theorem". You can find it after the brief introduction to function norms. Focus on the formal statement. It defines the function f(x) we want to approximate, the network F(x) doing the approximation, and the error bound ϵ.
To break this down:
- Target function : This is any continuous function defined on a compact (i.e., closed and bounded) domain, like the n-dimensional unit cube . Think of this as the "true" underlying process you want to model.
- Network approximation : This is a neural network with one hidden layer using a "squashing" activation function (like the sigmoid), hidden neurons, weights , biases , and output weights . Its form is:
- The Guarantee: For any desired error tolerance , there exists a number of neurons and a set of parameters such that the network's output is never more than away from the true function for any input in the domain.
While originally proven for sigmoid-like activations, the theorem has since been extended to a broader class of activation functions, including the now-ubiquitous ReLU. The key requirement is that the activation function must be non-polynomial.
Building Intuition: Approximating with "Steps" and "Pulses"
Stating the theorem is one thing; understanding why it holds is another. How can a collection of sigmoid functions possibly replicate any continuous shape? A highly intuitive constructive proof shows that we can use activation functions to build simple "building blocks" and then combine them to "pave" over the target function.
The following video provides an excellent, step-by-step walkthrough of this construction.
Universal Approximation Theorem
In this video, Jeff Orchard provides a clear, constructive proof of the UAT.
Please watch from the start of the proof. He demonstrates the core ideas: Approximating a step function: See how a sigmoid function with a very large weight (w \to \infty) behaves like a Heaviside step function. Creating a "box car" function: Observe how subtracting two shifted step functions creates a rectangular pulse, or "box car." This is our fundamental building block. Tiling the function: The most crucial part is seeing how any continuous function can be approximated by a series of these box cars, placed side-by-side. The height of each box approximates the function's value in a small region, and the width is chosen to ensure the approximation stays within the \epsilon error bound.
The key insight is that by adding enough of these "pulses"—each created by a couple of neurons in the hidden layer—we can create a step-wise approximation of any continuous function. The more neurons we use, the more pulses we can create, allowing us to make the steps smaller and the approximation more accurate, bringing the error below any we choose.
The article we looked at earlier presents the exact same intuition using static diagrams, which can be helpful for reinforcement.
How Neural Networks Approximate Any Function: A Mathematical Dive into Universal Approximation…
This section of the article visually demonstrates the pulse-based approximation.
Now, read Section 4, "Practical Illustration why Universal Approximation Theorem Works." It shows how two sigmoids create a pulse, and then how these pulses can be summed with different heights to approximate a target function. This directly corresponds to the video's explanation.
Implications and Limitations
The UAT provides the theoretical justification for using neural networks as general-purpose machine learning models. It tells us that the representational power of the network is not a limiting factor; a network can, in theory, represent the complex function mapping your inputs to your outputs.
However, the theorem comes with several critical caveats that are essential to understand in practice.
-
It's an Existence Proof, Not a Learning Algorithm: The UAT guarantees that a network with the right weights and biases exists, but it offers no help in finding them. The challenge of training a network—that is, finding the optimal parameters using an algorithm like gradient descent—is a completely separate and difficult problem.
-
The "Tyranny of Width": The theorem states a network can approximate any function if it has "enough" neurons. It is silent on how many is "enough." For highly complex functions or in high-dimensional spaces, the required number of hidden neurons in a single-layer network can grow exponentially. A network might need to be astronomically wide to achieve a good approximation, making it practically infeasible to create or train.
-
The Case for Depth: This is perhaps the most important practical takeaway. While a shallow (one hidden layer) network can theoretically approximate any function, a deep network (with multiple hidden layers) can often do so far more efficiently. Deep networks can learn a hierarchical composition of features. For instance, in image recognition, the first layer might learn to detect edges, the next to combine edges into simple shapes, the next to combine shapes into parts of objects (like an eye or a nose), and so on. This compositional structure allows deep networks to approximate complex, hierarchical functions with exponentially fewer neurons than a shallow network would require.
This is why modern AI is dominated by "deep learning." The power lies not just in function approximation, but in doing so efficiently.
How Neural Networks Approximate Any Function: A Mathematical Dive into Universal Approximation…
The conclusion of the article summarizes these limitations perfectly.
Please read Section 7, "Conclusion." Pay close attention to the discussion of the theorem being existential, not constructive, and the critical role of depth in creating more efficient representations.
A Glimpse into the Formal Proof
Given your interest in mathematical rigor, it's worth briefly touching on the logic behind the formal, non-constructive proof by Cybenko, which relies on concepts from functional analysis. It's an elegant proof by contradiction.
- The Setup: Consider the space of all continuous functions on a domain, . Now consider the subset of functions that can be generated by our single-hidden-layer network, let's call it . The theorem claims that is "dense" in , meaning any function in can be approximated by a function in .
- Proof by Contradiction: Assume the claim is false. If is not dense in , then there must be "gaps" between and the rest of . The Hahn-Banach theorem (a major result in functional analysis) then guarantees the existence of a non-zero linear functional that is zero for every function in our network's set , but non-zero for some other continuous functions.
- The Contradiction: The Riesz Representation Theorem states that this functional can be represented as an integral with respect to a signed measure . The condition that is zero for all functions in implies that for all possible weights and biases . However, a key property of functions like the sigmoid is that they are "discriminatory," meaning the only way this integral can be zero for all and is if the measure itself is the zero measure. This implies must be the zero functional, which contradicts our assumption.
- Conclusion: The initial assumption must be false. Therefore, must be dense in , and the theorem holds.
If you are interested in the full details, the article we've been using provides a more in-depth walkthrough in its section 6. This approach highlights the deep connection between neural network theory and abstract mathematics.
Conclusion
Today, we've tackled the Universal Approximation Theorem, which provides the theoretical guarantee for the expressive power of neural networks.
Key Takeaways:
- The Guarantee: A neural network with a single hidden layer and a non-polynomial activation function can approximate any continuous function on a compact domain to arbitrary precision, given enough neurons.
- The Intuition: This is possible because activations can be combined to form "pulse" functions, which can be used like building blocks to construct a step-wise approximation of any target function.
- The Implications: The theorem assures us that neural networks are powerful enough in principle to model any continuous mapping from inputs to outputs.
- The Limitations: The theorem is one of existence, not learning. It doesn't tell us how to find the network's parameters. Crucially, it hides the fact that a shallow network might need an infeasibly large number of neurons, which motivates the move towards deep networks that can learn hierarchical representations much more efficiently.
Now that we are assured that a network can represent our desired function, we must ask: how do we train it to find that representation? This requires a way to measure how "wrong" the network's current output is. In our next lesson, we will derive the two most fundamental loss functions used in machine learning—mean squared error and cross-entropy—from the powerful principle of maximum likelihood estimation.