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.
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 and divide the interval into subintervals with nodes . Write for . Define
On the interval indexed , exactly the hinges with are active. Thus the slope is . Since and it is continuous, induction shows it matches at all nodes: it is the linear interpolant. We used ReLU neurons, including on this domain. If the architecture allows a direct affine connection , interior hinges suffice; the two counts should not be mixed.
Let be the modulus of continuity. On each subinterval, is a convex combination of values of at its endpoints, both at distance at most from . Hence
Convergence follows from uniform continuity of on the compact set. Given , choose with and set the weights above. This proves existence and also provides weights if can be evaluated at the nodes.
If additionally and , error is at most . To see this, on interval consider , which vanishes at both endpoints and satisfies . Functions are concave and vanish at endpoints, so they are nonnegative. Thus . Rate 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 under the uniform norm. For every continuous function and a finite sum achieves uniform error below . 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 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 -dimensional cube with intervals per axis has 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 , a probability measure and a function with finite first spectral moment , there exists a sigmoid network with terms whose integrated squared error is bounded by . The corresponding norm is of order . This is not a uniform bound for all continuous functions: 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 ReLUs in the plane, each boundary is a line. In general position, with no parallel lines or three concurrent lines, line crosses the previous lines at distinct points and is divided into segments. Each segment adds a region, so the maximum number of arrangement cells is
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.
In multiple layers, each preceding pattern transforms the next layer’s boundaries; fragments appear in different areas. For input dimension and widths , a general upper bound on open patterns comes from multiplying , taking if : within each previous region, the 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
On it equals and on it equals : each segment maps its interval bijectively onto . Outside this formula equals zero. Let be composed with itself times.
Proof
For there are two segments, each monotone with image . If has that property on each segment, exactly one interior point has value . Composing with splits the segment there: on each half the composition is affine, monotone and traverses . Slopes change sign at the new points and earlier boundaries, so the segments do not merge. Induction completes the proof.
A neuron with has at most one kink; with it adds none. The sum of neurons and an affine term has at most interior kinks and segments. Representing the segments requires .
∎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 : for uniform approximation of all continuous functions, minimum hidden-layer width is . For vector output of dimension they give a construction of width 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 , its empirical version and a class . If an algorithm returns with empirical excess , then, provided the quantities are finite,
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 , whose second derivative has magnitude at most . A grid maximum is a measurement and may be below the true supremum.
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 for the first slope; outside we have not claimed it agrees with linear extrapolation on both sides. Cell numbers check one example, not the general bound already proved.
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
Step 1 of 3. What does the first neuron contribute on [0,1]?
Step 1 of 3. What happens when composing a segment that traverses [0,1]?
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):
passReLU 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.