The Geometry of ReLU Networks
Piecewise-linear functions and counting linear regions.
A ReLU network is, exactly, a continuous piecewise-linear function: it chops its input space into convex polyhedra and computes one affine function on each. That single fact turns questions about networks into questions about polyhedra. This lesson proves the correspondence in both directions, counts the pieces a network can produce and the far fewer it typically does, and shows how the same geometry makes exact verification possible, and NP-hard.
What you’ll learn
- Prove that a ReLU network is affine on each activation region, a convex polyhedron, and that every continuous piecewise-linear function on is a ReLU network with at most hidden layers.
- Derive Zaslavsky's bound for one hidden layer, the product upper bound for deep networks, and the exponential lower bound of Montúfar, Pascanu, Cho & Bengio.
- Explain why networks at initialization, and in practice after training, have far fewer regions than the maximum (Hanin & Rolnick).
- Encode a ReLU network exactly as a mixed-integer linear program, derive its LP relaxation, and explain why complete verification is NP-hard.
Activation patterns and polyhedra
Fix an input . Every hidden ReLU unit is either on () or off (); the list of on/off states of all hidden units is the activation pattern . Write for the diagonal 0/1 matrix of layer 's states. Wherever the pattern is constant, every ReLU acts as a fixed linear map, either the identity or zero, so the network is a product of matrices:
By induction over layers, with the pattern held at , every pre-activation is an affine function of : if is affine, so is , and hence .
The pattern is defined by sign conditions on those pre-activations, each an affine inequality in , so is an intersection of half-spaces: a convex polyhedron (possibly empty).
So is a continuous piecewise-linear (CPWL) function: continuous as a composition of continuous maps, and affine on each of finitely many convex polyhedra that cover . Neighboring regions may carry the same affine map, so the number of linear regions of is at most the number of non-empty activation regions, itself at most .
Wang & Sun (2005) showed that every CPWL function on is a signed sum of maxima of at most affine functions:
A maximum of two numbers costs one hidden layer of three ReLUs, since :
A binary tree of pairwise maxima computes the maximum of affine functions in layers (shorter branches are carried along with the same identity trick), and the output layer forms the signed sum. The size can be large; only the depth is logarithmic.
Is that depth necessary? For one hidden layer suffices, and any one-hidden-layer network representing a function with pieces needs at least units. Hertrich, Basu, Di Summa & Skutella (2021) conjectured that hidden layers are necessary in general, and Haase, Hertrich & Loho (2023) proved this for networks with integer weights: they need hidden layers to compute the maximum of numbers. With real weights the conjecture is false: Bakaev, Brunck, Hertrich, Stade & Yehudayoff (2025) showed that two hidden layers compute the maximum of five numbers, and that hidden layers suffice for every CPWL function on when . Whether real weights need any depth that grows with at all is open.
Counting regions: one hidden layer
With one hidden layer of units on , unit switches on one side of the hyperplane , so the activation regions are exactly the regions of the arrangement of hyperplanes. Counting them is a classical problem.
Add the hyperplanes one at a time. When is added, each old region it passes through is split in two, so the number of new regions equals the number of pieces into which the other hyperplanes cut . Those cuts form an arrangement of at most hyperplanes inside :
Pascal's rule shows that satisfies this recursion with equality and the same boundary values, so it bounds by induction. In general position every inequality is an equality.
A ReLU network on has one hidden layer of 8 units in general position. At most how many linear regions does it have?
Show the answer
37 regions
. Only 37 of the activation patterns can occur: in the plane, 8 lines cannot realize every combination of sides. In one dimension the count would be .
Depth multiplies regions
An upper bound. Inside one region of the first layers, layer 's pre-activations are affine in , with a linear part of rank at most . Their zero sets form an arrangement of hyperplanes whose normals span at most dimensions, so by Zaslavsky each region splits into at most pieces. Multiplying over layers:
Serra, Tjandraatmadja & Ramalingam (2018) sharpened this, with bounds that are exact for one-dimensional inputs, and showed that a deep network can have more regions than every one-hidden-layer network with the same number of units only if that number exceeds the input dimension. They also counted regions exactly by mixed-integer programming.
In one dimension, ReLUs can form a zigzag that maps each of consecutive intervals onto , alternately increasing and decreasing (for this is the tent map ). Use units on each of the coordinates: the layer maps cells of the input cube onto the same cube .
Everything computed after is computed identically, mirrored, in every cell, so each region drawn by the later layers appears times in the input. Fold times and let the last layer draw an arrangement of hyperplanes in general position on the cube:
| Architecture on (32 hidden units) | Regions |
|---|---|
| One hidden layer of 32 units: maximum (Zaslavsky) | |
| Four layers of 8: guaranteed by Montúfar et al.'s construction | |
| Four layers of 8: product upper bound |
Typical networks have few regions
Exponential counts require carefully arranged weights, folding the space into precise mirror images. Hanin & Rolnick asked what happens for networks people actually train:
- Along lines (Hanin & Rolnick, 2019a): for networks with random weights and biases at initialization, the expected number of regions crossed by a one-dimensional segment grows linearly in the total number of neurons, not exponentially in depth, and the average distance from a point to the nearest region boundary scales like the inverse of the number of neurons.
- In volume (Hanin & Rolnick, 2019b): the expected number of activation regions per unit volume of input space at initialization is bounded by roughly the total number of neurons raised to the input dimension, , independent of depth. Experiments found this scaling tight at initialization and throughout training, even on memorization tasks that should reward many regions.
So, as measured by regions, gradient-trained networks use a tiny fraction of the capacity that depth makes available. Region counts are also a coarse measure of complexity: many regions can carry nearly the same affine map, and a network with few regions can still represent sharp, intricate boundaries where it needs them.
Think first A network with hidden units in 10 layers receives two-dimensional inputs. Compare the maximum region counts with the typical count at initialization.
The maximum is astronomically large: with 10 layers of 100 units, Montúfar et al.'s construction alone gives regions. The typical density at initialization scales like per unit area, up to constants. The gap of about 28 orders of magnitude is the difference between what a network can express and what random or trained weights actually produce.
Exact verification
Because a ReLU network is piecewise linear, questions such as "is there an input within distance of that the network classifies differently?" can be answered exactly by mixed-integer linear programming. The objective and the input set are linear; each ReLU is encoded with linear constraints and one binary variable, given bounds computed beforehand (for example by propagating intervals through the network).
For an unstable unit, , introduce and require:
If , the second and fourth constraints give , and forces . If , the first and third give , and forces . So the feasible are exactly the graph of the ReLU on . Stable units need no binary variable: if and if .
Relax to . For fixed the largest feasible is , attained where the two bounds meet, at . The relaxation is the triangle with vertices , , : the convex hull of the ReLU's graph.
Solving the relaxed linear program is cheap and sound: if it certifies that no adversarial input exists, none does. It is incomplete: a failed certificate may come from the relaxation's slack rather than a real counterexample. The exact MILP is complete but exponential in the worst case, since branching on binary variables can explore up to cases. Tight bounds help twice, by making more units stable and by shrinking every triangle. With such tight formulations and presolving, Tjeng, Xiao & Tedrake (2019) verified networks with an order of magnitude more ReLUs than earlier complete verifiers; for one MNIST classifier at they found adversarial examples for 4.38% of the test samples and certified robustness for all the rest.
No complete verifier runs in polynomial time on every network unless P = NP: Katz, Barrett, Dill, Julian & Kochenderfer (2017) showed that verifying properties of this kind for ReLU networks is NP-complete, by a reduction from 3-SAT, while introducing their Reluplex solver.
You check a classifier's robustness at an input using the LP relaxation (every ReLU replaced by its triangle). The LP finds a "counterexample" whose relaxed variables are not all on the ReLU graph. What can you conclude?
- The network is not robust at that input
- The network is robust at that input
- Nothing yet: the relaxation is sound but incomplete, so you must tighten bounds or branch (or solve the MILP) to decide
- The interval bounds must be wrong
Show the answer
C. Nothing yet: the relaxation is sound but incomplete, so you must tighten bounds or branch (or solve the MILP) to decide
A relaxed point that is not on the ReLU graph is not an input the network can actually receive, so it proves nothing about the network. The LP can only certify robustness (when its optimum shows no violation); when it fails, the truth is undecided until tighter bounds, branching on unstable units, or the exact MILP settle it.
Key takeaways
- On each activation region, a convex polyhedron, a ReLU network is affine: . Conversely, every CPWL function on is a ReLU network with at most hidden layers (Arora et al.); integer weights need that much depth, real weights need less ( layers suffice for ), and whether they need any growing depth is open.
- One hidden layer of units on has at most regions (Zaslavsky); deep networks satisfy and can reach by folding space (Montúfar et al.).
- Typical networks have far fewer regions: linear in the number of neurons along a line and about per unit volume, independent of depth, at initialization and in practice after training (Hanin & Rolnick).
- A ReLU with bounds is encoded exactly by a big-M constraint with one binary; its LP relaxation is the triangle hull. Relaxations are sound but incomplete; exact verification is NP-complete.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why is the set of inputs that share one activation pattern of a ReLU network convex?
- Because ReLU is a convex function
- Because with the pattern fixed, every pre-activation is an affine function of the input, and the pattern is a list of sign conditions on them: an intersection of half-spaces
- Because the network's output is convex in its input
- It is not convex in general; only the first layer's regions are
Show the answer
B. Because with the pattern fixed, every pre-activation is an affine function of the input, and the pattern is a list of sign conditions on them: an intersection of half-spaces
Holding the pattern fixed replaces every ReLU by the identity or zero, so each pre-activation is affine on the region. The region is for on-units, for off-units, an intersection of half-spaces.
A one-hidden-layer ReLU network on has 5 hidden units in general position. How many linear regions can it have at most?
- 32
- 16
- 26
- 6
Show the answer
C. 26
. Five planes in cannot realize all on/off combinations.
What did Hanin & Rolnick find about the number of regions of randomly initialized deep ReLU networks?
- It grows exponentially with depth, matching the maximal constructions
- It is always exactly one region
- Along a line it grows linearly in the total number of neurons, and per unit volume roughly like (neurons), independent of depth
- It decreases as networks get deeper
Show the answer
C. Along a line it grows linearly in the total number of neurons, and per unit volume roughly like (neurons), independent of depth
Typical counts are governed by the total number of neurons, not by depth, far below the exponential maxima, and experiments found the same scaling during training. Depth's exponential capacity is mostly unused by gradient-trained networks, as measured by regions.
In the MILP encoding of a ReLU network for verification, which units need a binary variable?
- Every unit in the network
- Only units in the last hidden layer
- Only units whose output is used by the next layer
- Only unstable units, whose pre-activation bounds satisfy
Show the answer
D. Only unstable units, whose pre-activation bounds satisfy
If the unit is always off (), and if it is always on (): both are linear. Only units that can be either need the binary switch, so tighter bounds mean fewer binaries and a smaller search.
Further reading
- R. Arora, A. Basu, P. Mianjy & A. Mukherjee, "Understanding deep neural networks with rectified linear units," International Conference on Learning Representations (ICLR) (2018).
- G. Montúfar, R. Pascanu, K. Cho & Y. Bengio, "On the number of linear regions of deep neural networks," Advances in Neural Information Processing Systems 27 (2014).
- T. Serra, C. Tjandraatmadja & S. Ramalingam, "Bounding and counting linear regions of deep neural networks," International Conference on Machine Learning (ICML) (2018).
- B. Hanin & D. Rolnick, "Complexity of linear regions in deep networks," ICML (2019); and "Deep ReLU networks have surprisingly few activation patterns," NeurIPS (2019).
- V. Tjeng, K. Xiao & R. Tedrake, "Evaluating robustness of neural networks with mixed integer programming," ICLR (2019).