Module contents
Lesson 5 of 22Advanced 90 min

Expressivity: universal approximation and the value of depth

Construct one-dimensional ReLU approximations, study universal approximation and linear regions, and examine an exact depth separation through compositions of a tent map.

After this lesson you can

  • Construct a one-hidden-layer ReLU network approximating any continuous function on [0,1] to error ε.
  • State universal approximation theorems precisely and distinguish existence from learnability.
  • Count linear regions of a small ReLU network and bound them by width and depth.
  • Demonstrate depth separation using compositions of a tent function.
  • Explain approximation, estimation and optimization error in networks.

Before you start

Approximation and learning

Suppose you want to approximate a continuous function of one variable. A ReLU MLP is a curve formed by segments: each hidden neuron can introduce a kink. With enough chosen kinks, you can follow a curve as accurately as desired. This construction is concrete: it does not say an optimizer will discover those kinks from a finite sample.

InteractiveBuilding with kinks
  • Target
  • ReLU network
  • Network nodes
  • Grid maximum
The network exactly represents the orange curve on [0,1][0,1]: y0+s0ReLU⁡(x)+∑i=1n−1(si−si−1)ReLU⁡(x−ti)y_0+s_0\operatorname{ReLU}(x)+\sum_{i=1}^{n-1}(s_i-s_{i-1})\operatorname{ReLU}(x-t_i). The first weight gives the initial slope and each bend changes it. Output weights with magnitude greater than 10−1010^{-10} count as nonzero. The editable target is linear between five points; after changing it, interpolate again if you want it to match at the nodes.
For f(x)=4x(1−x)f(x)=4x(1-x), we have sup⁡∣f′′∣=8\sup|f''|=8. If equally spaced nodes interpolate the parabola, the error over all of [0,1][0,1] is at most 8/(8n2)=1/n28/(8n^2)=1/n^2. The displayed maximum is calculated only on a grid and may be less than the continuous error.
Target
4
1
Maximum error on 1001-point grid0.06250
Location of grid maximum0.125
ReLU neurons4 at most
Nonzero coefficients4 of 4
Initial slope s0s_03.000
Bend 1: position and slope change0.250; −2.000
Continuous bound 1/n21/n^20.06250
Adjust the kinks and compare the curve with the target. Displayed error is calculated on a finite grid; for equally spaced interpolation of a smooth function, compare it with the theoretical bound.

Universal approximation is a density statement for a precise class of functions and notion of error. Changing domain, activation or norm can change the theorem. Begin with a complete one-dimensional proof before discussing general results.

ReLU construction on [0, 1]

Let f∈C([0,1])f\in C([0,1]) and divide the interval into n≥1n\ge1 subintervals with nodes xi=i/nx_i=i/n. Write mi=n(f(xi+1)−f(xi))m_i=n(f(x_{i+1})-f(x_i)) for i=0,…,n−1i=0,\ldots,n-1. Define

pn(x)=f(0)+m0ReLU⁡(x)+∑i=1n−1(mi−mi−1)ReLU⁡(x−xi),x∈[0,1].p_n(x)=f(0)+m_0\relu(x)+\sum_{i=1}^{n-1}(m_i-m_{i-1})\relu(x-x_i),\qquad x\in[0,1].

On the interval indexed jj, exactly the hinges with i≤ji\le j are active. Thus the slope is m0+∑i=1j(mi−mi−1)=mjm_0+\sum_{i=1}^j(m_i-m_{i-1})=m_j. Since pn(0)=f(0)p_n(0)=f(0) and it is continuous, induction shows it matches ff at all nodes: it is the linear interpolant. We used nn ReLU neurons, including ReLU⁡(x)=x\relu(x)=x on this domain. If the architecture allows a direct affine connection m0xm_0x, n−1n-1 interior hinges suffice; the two counts should not be mixed.

Let ωf(δ)=sup⁡{∣f(x)−f(y)∣:x,y∈[0,1], ∣x−y∣≤δ}\omega_f(\delta)=\sup\{|f(x)-f(y)|:x,y\in[0,1],\ |x-y|\le\delta\} be the modulus of continuity. On each subinterval, pn(x)p_n(x) is a convex combination of values of ff at its endpoints, both at distance at most 1/n1/n from xx. Hence

sup⁡x∈[0,1]∣f(x)−pn(x)∣≤ωf(1/n)⟶0.\sup_{x\in[0,1]}|f(x)-p_n(x)|\le\omega_f(1/n)\longrightarrow0.

Convergence follows from uniform continuity of ff on the compact set. Given ε>0\eps>0, choose nn with ωf(1/n)<ε\omega_f(1/n)<\eps and set the weights above. This proves existence and also provides weights if ff can be evaluated at the nodes.

If additionally f∈C2([0,1])f\in C^2([0,1]) and sup⁡∣f′′∣≤M\sup|f''|\le M, error is at most M/(8n2)M/(8n^2). To see this, on interval [a,b][a,b] consider g=f−png=f-p_n, which vanishes at both endpoints and satisfies ∣g′′∣≤M|g''|\le M. Functions M2(x−a)(b−x)±g(x)\frac M2(x-a)(b-x)\pm g(x) are concave and vanish at endpoints, so they are nonnegative. Thus ∣g(x)∣≤M2(x−a)(b−x)≤M(b−a)2/8|g(x)|\le\frac M2(x-a)(b-x)\le M(b-a)^2/8. Rate n−2n^{-2} requires this extra assumption: an arbitrary continuous function need not satisfy it.

What the general theorems say

In the following statements width may grow with the function and accuracy; biases are free and an affine output combines hidden neurons.

  • Cybenko: a continuous sigmoid with limits zero and one at the extremes generates a dense family in C([0,1]d)C([0,1]^d) under the uniform norm. For every continuous function and ε>0\eps>0 a finite sum achieves uniform error below ε\eps. See Cybenko’s theorem 2.
  • Hornik: for a continuous, bounded, nonconstant activation, one-hidden-layer networks uniformly approximate continuous functions on compact sets. Continuity matters in this uniform version; other results in the paper use convergence in LpL^p under different assumptions. See Hornik, 1991.
  • Leshno and colleagues: for continuous activation, non-polynomiality characterizes density of these networks in uniform approximation on compact sets, with biases available. ReLU is not a polynomial and falls under this result. See the original article.

One idea of the abstract proof is contradiction. If the space generated by neurons were not dense, Hahn-Banach would provide a continuous linear functional that annihilates all those combinations but not some target function. In the space of continuous functions on a compact set, the Riesz representation theorem identifies that functional with a finite signed measure. Assumptions on activation and biases establish that a measure annihilating every neuron must be zero, a contradiction. This outline shows where each assumption works; it does not replace the technical proof that the measure is zero.

Cost of approximation

Existence does not say how many neurons are practical. A regular partition of an dd-dimensional cube with nn intervals per axis has ndn^d cells: although not a universal lower bound for every network, this illustrates why a generic strategy can suffer the curse of dimensionality.

The Barron bound offers another perspective for functions with Fourier structure. In the paper’s formulation, for a domain contained in a ball of radius rr, a probability measure and a function with finite first spectral moment CfC_f, there exists a sigmoid network with nn terms whose integrated squared error is bounded by (2rCf)2/n(2rC_f)^2/n. The corresponding L2L^2 norm is of order n−1/2n^{-1/2}. This is not a uniform bound for all continuous functions: CfC_f may depend on function and dimension, and the result does not claim a particular optimization will find the network.

Regions of a ReLU network

A finite ReLU network is piecewise affine. Once a sign pattern of all preactivations is fixed, each ReLU is identity or zero and the composition reduces to an affine map. Inequalities defining that pattern are affine once previous patterns are fixed. A linear region is an area where the function has the same affine expression; two distinct patterns can produce the same expression and their areas can merge.

For one layer of nn ReLUs in the plane, each boundary is a line. In general position, with no parallel lines or three concurrent lines, line jj crosses the previous lines at j−1j-1 distinct points and is divided into jj segments. Each segment adds a region, so the maximum number of arrangement cells is

1+∑j=1nj=1+n(n+1)2.1+\sum_{j=1}^{n}j=1+\frac{n(n+1)}2.

This bounds activation cells, and the maximum is attained for a generic choice of lines. The output can remove a kink if its weights cancel contributions; therefore an activation cell is not always a maximal affine region of the output function.

InteractiveActivation patterns in the plane
Network A: 1 hidden layer of 9
x₁: −1 to 1x₂: 1 top, −1 bottom
Distinct sampled patterns15
Parameters including biases and output37
Network B: 3 hidden layers of 3
x₁: −1 to 1x₂: 1 top, −1 bottom
Distinct sampled patterns24
Parameters including biases and output37

Each cell corresponds to the center of a square in the 48 × 48 grid over [−1, 1]². Its color encodes which ReLUs are active across all hidden layers; the palette has only eight colors, so distinct patterns may share a color. Points with a preactivation less than 10⁻¹⁰ from zero are marked gray and excluded from the count.

The displayed number counts distinct observed patterns, not exact linear regions: the grid may miss some regions and several patterns may yield the same affine output map. The networks have two inputs, the indicated width in each hidden layer and an affine output. Each weight is drawn as a standard normal divided by the square root of its layer input count, and each bias as 0.4 times a standard normal; the seed fixes all draws. The initial configuration selects a realization illustrating the contrast; it does not prove a general advantage of depth. Change the seed and compare budgets too.

9
1
3
3
28
Parameter budgetEqual: 37 in each network
Compare width and depth and observe detected patterns. The count visits a finite grid: it may miss small regions and does not automatically identify maximal affine regions of the output.

In multiple layers, each preceding pattern transforms the next layer’s boundaries; fragments appear in different areas. For input dimension dd and widths n1,…,nLn_1,\ldots,n_L, a general upper bound on open patterns comes from multiplying ∏ℓ=1L∑j=0d(nℓj)\prod_{\ell=1}^{L}\sum_{j=0}^{d}\binom{n_\ell}{j}, taking (nj)=0\binom{n}{j}=0 if j>nj>n: within each previous region, the nℓn_\ell preactivations are affine in the input and a hyperplane arrangement creates at most that many cells. It can be very loose due to bottlenecks and dependencies between layers. Montúfar and colleagues study bounds and constructions showing how composition reuses regions; an empirical count of one network does not establish its architecture’s maximum.

The composed tent map

Consider the tent function

T(x)=2ReLU⁡(x)−4ReLU⁡(x−1/2)+2ReLU⁡(x−1).T(x)=2\relu(x)-4\relu(x-1/2)+2\relu(x-1).

On [0,1/2][0,1/2] it equals 2x2x and on [1/2,1][1/2,1] it equals 2−2x2-2x: each segment maps its interval bijectively onto [0,1][0,1]. Outside [0,1][0,1] this formula equals zero. Let T∘kT^{\circ k} be TT composed with itself kk times.

InteractiveComposing the tent

The tent T(x)=2ReLU⁡(x)−4ReLU⁡(x−12)+2ReLU⁡(x−1)T(x)=2\operatorname{ReLU}(x)-4\operatorname{ReLU}(x-\tfrac12)+2\operatorname{ReLU}(x-1) rises from 0 to 1 and falls to 0 on [0,1][0,1]. TkT^k means composing it kk times, not raising its value to the kkth power.

k = 1
  • Current composition TkT^k
  • Previous stage Tk−1T^{k-1}

Each piece of TkT^k traverses [0,1][0,1] once. Applying TT divides it in two: by induction there are 2k2^k pieces and 2k−12^k-1 interior bends. A single layer with mm ReLUs has at most mm bends on the line, even with a direct affine output. To represent this function exactly on [0,1][0,1] it needs m≥2k−1m\ge 2^k-1.

The neuron count is a lower bound for exact representation, not a claim about approximation error or the exact minimum across all architectures. Each composition uses at most three ReLUs; chaining them gives a construction of width 3 and k hidden layers.

0.300
Compositions kk1
Pieces on [0,1][0,1]2
Interior bends1
ReLUs needed in one layer≥ 1
Tk(x)T^k(x)0.6000
Advance through compositions. Each segment of the previous function traverses all of [0,1] and splits in two through the next tent. The shallow-neuron count bounds exact representation on [0,1].
Proof

For k=1k=1 there are two segments, each monotone with image [0,1][0,1]. If T∘kT^{\circ k} has that property on each segment, exactly one interior point has value 1/21/2. Composing with TT splits the segment there: on each half the composition is affine, monotone and traverses [0,1][0,1]. Slopes change sign at the new points and earlier boundaries, so the 2k+12^{k+1} segments do not merge. Induction completes the proof.

A neuron ReLU⁡(ax+b)\relu(a x+b) with a≠0a\ne0 has at most one kink; with a=0a=0 it adds none. The sum of mm neurons and an affine term has at most mm interior kinks and m+1m+1 segments. Representing the 2k2^k segments requires m+1≥2km+1\ge2^k.

∎

This construction shows a depth separation for exact representation of a particular family. Telgarsky proves approximation-separation results for more general families and network classes; the elementary kink argument alone does not prove every bound in that article. Depth can save width in this example, but does not guarantee that every task is solved better with more layers.

Width, data and optimization

Hanin and Sellke study feedforward ReLU networks without skip connections, arbitrary depth and affine scalar output on [0,1]d[0,1]^d: for uniform approximation of all continuous functions, minimum hidden-layer width is d+1d+1. For vector output of dimension doutd_{\mathrm{out}} they give a construction of width d+doutd+d_{\mathrm{out}} and bounds, not that same general equality. Changing architecture, domain or norm changes the question. Lu and colleagues study related width and depth results with their own formulations.

To understand why representation does not imply learning, compare population risk RR, its empirical version R^\hat R and a class H\mathcal H. If an algorithm returns ft∈Hf_t\in\mathcal H with empirical excess δt=R^(ft)−inf⁡h∈HR^(h)\delta_t=\hat R(f_t)-\inf_{h\in\mathcal H}\hat R(h), then, provided the quantities are finite,

R(ft)−inf⁡fR(f)≤inf⁡h∈HR(h)−inf⁡fR(f)⏟aproximacioˊn+2sup⁡h∈H∣R(h)−R^(h)∣⏟estimacioˊn+δt⏟optimizacioˊn.R(f_t)-\inf_f R(f)\le \underbrace{\inf_{h\in\mathcal H}R(h)-\inf_f R(f)}_{\text{aproximación}} +\underbrace{2\sup_{h\in\mathcal H}|R(h)-\hat R(h)|}_{\text{estimación}} +\underbrace{\delta_t}_{\text{optimización}}.

To obtain this, add and subtract empirical risks and bound each discrepancy by the supremum; if an infimum is not attained, use a sequence approaching it. Expressivity can reduce the first term, but a wider class can make the second harder to control and incomplete optimization leaves the third. The excess-risk decomposition and required statistical assumptions are studied in another module. No universal approximation theorem promises generalization or gradient-descent convergence.

Lab: interpolation and pattern counts

First construct weights from node values. Compare error on a dense grid with the continuous bound for f(x)=sin⁡(2πx)f(x)=\sin(2\pi x), whose second derivative has magnitude at most 4π24\pi^2. A grid maximum is a measurement and may be below the true supremum.

[ ]Interpolant as a ReLU sumBrowser
import numpy as np

def relu_interpolant(nodes, values, x):
    nodes = np.asarray(nodes, dtype=float)
    values = np.asarray(values, dtype=float)
    x = np.asarray(x, dtype=float)
    slopes = np.diff(values) / np.diff(nodes)
    out = values[0] + slopes[0] * np.maximum(x - nodes[0], 0)
    for i in range(1, len(slopes)):
        out = out + (slopes[i] - slopes[i-1]) * np.maximum(x - nodes[i], 0)
    return out

grid = np.linspace(0, 1, 10001)
for n in (4, 8, 16, 32):
    nodes = np.linspace(0, 1, n+1)
    pred = relu_interpolant(nodes, np.sin(2*np.pi*nodes), grid)
    err = np.max(np.abs(pred-np.sin(2*np.pi*grid)))
    bound = np.pi**2 / (2*n*n)
    print('intervalos', n, 'error en malla', round(err, 8), 'cota continua', round(bound, 8))

The formula uses ReLU⁡(x−x0)\relu(x-x_0) for the first slope; outside [0,1][0,1] we have not claimed it agrees with linear extrapolation on both sides. Cell numbers check one example, not the general bound already proved.

[ ]Patterns detected on a gridBrowser
def sampled_patterns(width, depth, seed=11, side=81):
    rng = np.random.default_rng(seed)
    axis = np.linspace(-1, 1, side)
    gx, gy = np.meshgrid(axis, axis)
    H = np.column_stack((gx.ravel(), gy.ravel()))
    patterns = []
    input_width = 2
    for _ in range(depth):
        W = rng.normal(size=(input_width, width))
        b = rng.normal(size=width) * 0.3
        Z = H @ W + b
        patterns.append(Z > 0)
        H = np.maximum(Z, 0)
        input_width = width
    packed = np.packbits(np.hstack(patterns), axis=1)
    return len(np.unique(packed, axis=0))

def nparams(width, depth):
    return 3*width + (depth-1)*width*(width+1) + width+1

for width, depth in ((6, 1), (3, 2)):
    print('anchura, capas, parámetros, patrones observados', width, depth,
          nparams(width, depth), sampled_patterns(width, depth))
print('máximo de 10 rectas en posición general', 1 + 10*11//2)

The two architectures have the same number of parameters, including an affine scalar output. Matrices are random and untrained; change seed or resolution to check sensitivity. The grid reports only patterns it visits, may miss small regions and measures neither generalization nor the number of maximal affine expressions.

Exercises

ProofBuild all the kinks
Prove: Show that an interpolant with n intervals on [0,1] is represented by n ReLU neurons.
0
Interval slopes are m₀, …, mₙ₋₁ and interior kinks are x₁, …, xₙ₋₁.

Step 1 of 3. What does the first neuron contribute on [0,1]?

ProofDouble the segments
Prove: Show that T composed k times has 2^k segments and one hidden layer needs at least 2^k−1 ReLUs to represent it exactly.
0
Each of the two segments of T maps its interval monotonically onto [0,1].

Step 1 of 3. What happens when composing a segment that traverses [0,1]?

NumericRegions of ten lines
What is the maximum number of regions created by ten lines in general position in the plane?
QuizWhat does universality guarantee?
A family is dense in continuous functions on a compact set under the uniform norm. What can you conclude?
CodeCompose the tent
Implement tent_power(x, k) for nonnegative integer k. T(x)=2ReLU(x)−4ReLU(x−1/2)+2ReLU(x−1); return T composed k times, and return x for k=0. Accept NumPy arrays.
import numpy as np

def tent_power(x, k):
  pass
Shift+Enter to run
Key idea

ReLU kinks construct interpolants and uniform continuity gives approximation on a compact set. Depth can compose a function with exponentially more segments than a shallow layer, but region count alone does not measure generalization. Existence of a good network, estimation from data and optimization are distinct guarantees.