3.1.7 · D2Neural Network Fundamentals

Visual walkthrough — Universal approximation theorem

1,920 words9 min readBack to topic

We work entirely in one input dimension (one number going in, one number coming out) because everything visual lives there. The higher-dimensional case is the same trick repeated per direction.


Step 0 — The words and symbols we are allowed to use

Before any formula, let us name every piece so nothing appears un-earned.

Everything below is assembled from just these seven names.


Step 1 — One sigmoid is a soft step

WHAT. The sigmoid is Here is whatever number we hand it, and is the exponential — a tool that grows or shrinks very fast, which is exactly what forces the output to slam toward or at the extremes.

WHY the exponential and not, say, a straight line? We want a shape that is far to the left, far to the right, and smoothly transitions in between — a "soft switch". A straight line would run off to ; the exponential in the denominator saturates, pinning the value between and . Read the endpoints straight off:

PICTURE. The single S-curve below: flat-low on the left, flat-high on the right, one smooth climb in the middle.

Figure — Universal approximation theorem

Step 2 — Weight and bias turn the soft step into a sharp step at a chosen place

WHAT. Feed the sigmoid the combination :

WHY. Two independent controls appear:

  • is the value of where the input to is zero, so — the middle of the climb. Changing slides the step left/right.
  • multiplies the distance , so a large means the input to races from very negative to very positive across a tiny window of — the climb becomes sharp. As the soft step becomes a hard step: then instantly at .

PICTURE. Three copies of the same sigmoid: gentle ( small), medium, and near-vertical ( large), all crossing height exactly at .

Figure — Universal approximation theorem

Step 3 — Subtract two steps to carve out a single bump

WHAT. Place one sharp step at and another at (with ), and subtract:

WHY. Track the value as sweeps right:

  • Left of : both steps are , so bump . Off.
  • Between and : first step is , second still , so bump . On.
  • Right of : both are , so bump . Off again.

The result is a rectangle that is high only on the window . We subtracted because subtraction is what cancels the "on" region we no longer want, leaving a localized block. This costs exactly 2 hidden neurons with output weights and .

PICTURE. The two steps drawn faintly, and their difference — a clean rectangular bump — drawn boldly on top.

Figure — Universal approximation theorem
Recall Why exactly two, not one?

One step alone stays high forever to the right; it can never come back down. A bump must go up and come back down, and each rise/fall is one sigmoid. ::: So the minimum is 2 sigmoids per bump.


Step 4 — Scale the bump to any height with the output weight

WHAT. Multiply the whole bump by :

WHY. The raw bump has height . We want to match whatever height the target curve has over that window. Scaling by (the output weight) stretches the rectangle to height — positive points up, negative points down (needed where dips below zero).

PICTURE. The same window, three bumps stacked in the drawing: one at height , one scaled to , one flipped to (below the axis).

Figure — Universal approximation theorem

Step 5 — Line up many bumps into a staircase

WHAT. Chop the domain into adjacent windows at cut points . On window set the height to the target value there, . Add all the scaled bumps:

WHY. Adjacent rectangles sit side by side with no gap (each window's right edge is the next window's left edge). Because each is high only on its own window, at any given essentially one bump is active, contributing its height . The sum therefore reads off like a histogram / staircase that traces step by step. Setting makes each stair land on the true curve.

PICTURE. The parabola in teal, with an orange staircase of bumps hugging it — each flat plateau touching the curve at its midpoint.

Figure — Universal approximation theorem

Step 6 — Refine: why the staircase must converge

WHAT. Shrink every window width and grow at the same time. Two errors shrink together:

  • Height error — how much varies within a window.
  • Edge error — how "soft" (non-vertical) each step still is.

WHY this is guaranteed and not just hoped-for. is continuous on the closed, bounded interval , which makes it uniformly continuous (see Uniform continuity): pick any tolerance , and there is one window width small enough that changes by less than across every window simultaneously. So the flat top of each stair is never more than from the curve. Meanwhile large squeezes the soft edges into near-vertical jumps, killing the edge error. Together: The symbol ("supremum") means the worst gap anywhere — not the average. We are promising closeness at every single point.

PICTURE. Two panels: left, a coarse 4-bump staircase with visible gaps; right, a fine 16-bump staircase pressed tight against the same parabola — the gap band shrinking.

Figure — Universal approximation theorem

Step 7 — Edge cases: where the picture breaks

Every case must be covered, including the ones that fail.

Case A — Domain not compact / function unbounded. Take on the open interval . As the curve shoots to . No finite pile of bounded bumps can reach infinite height, so no gives uniform -closeness. Why it breaks: uniform continuity needed a closed, bounded domain; drop that and the engine stalls.

Case B — Target below the axis. Where , just use (Step 4). Downward bumps handle it — nothing new needed. Covered.

Case C — ReLU instead of sigmoid. ReLU gives : a flat then a rising ramp. Subtracting two ReLUs, , does not give a rectangle — it gives a ramp that rises then plateaus at height . To carve a true localized bump you add a second downward ramp (more units). Universality survives (ReLU is non-polynomial), but each bump costs a few extra neurons.

PICTURE. Three mini-panels: (A) escaping to infinity with a red "unbounded" arrow; (B) a downward bump for negative ; (C) the ReLU ramp-plateau vs. the sigmoid rectangle side by side.

Figure — Universal approximation theorem

The one-picture summary

Figure — Universal approximation theorem

The whole story on one canvas: a lone sigmoid → sharpened into a step → paired into a bump → scaled → tiled into a staircase → refined until it kisses the target curve within everywhere.

Recall Feynman retelling — explain it to a 12-year-old

Imagine you want to draw a smooth hill but you're only allowed to stack LEGO blocks. Each sigmoid is a smooth ramp that goes from floor level up to one block high. If you make the ramp super steep it's basically a stair-step. Put one step going up and, a little further along, one step going down, subtract them, and you've built a single block that sits only where you want it. Now line up lots of blocks of different heights side by side — that's a staircase, and if you make the blocks skinny enough it looks just like the smooth hill from far away. The math promise ("universal approximation") is just: because the hill never jumps suddenly, skinny-enough blocks can copy it to any accuracy you like. The catch is you might need a HUGE number of blocks — which is why real networks stack layers (Depth vs Width tradeoff) instead of just widening one row. And copying the hill you were shown says nothing about hills you haven't seen — that's generalization, a different game, and actually finding the right blocks is yet another one (Backpropagation).


Recall

Recall Quick self-check

A single sigmoid becomes a hard step at which , and what controls its steepness? ::: Step at ; steepness controlled by . How many sigmoids for one bump, and what output weights? ::: Two, with weights and . What property of (from compactness) guarantees the staircase converges? ::: Uniform continuity. Why does on escape the theorem? ::: Domain isn't compact and the function is unbounded. Does give a bump? ::: No — a ramp that plateaus at height .