Tutorials › Statistical Learning (Graduate) › Approximating Maxima And Minima With ReLU Networks

Neural Approximation Theory · Tutorial 911 of 989

Approximating Maxima And Minima With ReLU Networks

Learn how ReLU identities implement maxima and minima, how their network costs scale with the number of inputs, and how to use these operations to build structured approximations.

Advanced 12 min read

What You'll Learn

  • Derive exact ReLU formulas for the maximum and minimum of two real-valued quantities.
  • Build maxima and minima of finite collections using binary trees and count their nonlinear units.
  • Represent a maximum of affine functions as a convex piecewise-affine function.
  • Bound the uniform error when approximate component functions are combined by a maximum or minimum.
  • Construct a ReLU approximation to a maximum of two quadratic functions on a bounded interval.

Why Maxima and Minima Fit ReLU Networks

Many targets in approximation theory are assembled by choosing the largest or smallest among several simpler functions. A maximum of affine functions, for example, is a convex piecewise-affine function. ReLU networks are well suited to these constructions because the ReLU activation itself can express a maximum exactly. This gives both a direct representation and a way to combine approximations without losing control of their error.

Here, a ReLU network means a feedforward network whose hidden units apply \(\rho(t)=\max\{t,0\}\) to affine combinations, with an affine output layer. We count ReLU units, not affine operations. For size statements, depth means the number of hidden layers. Exact identities for real-valued quantities will first be derived; we then connect those identities to network size and approximation error.

Definition: For real-valued functions \(g_1,\ldots,g_m\) on a domain \(\Omega\), their pointwise maximum and minimum are the functions \(\max_{1\leq i\leq m}g_i(x)\) and \(\min_{1\leq i\leq m}g_i(x)\), respectively. A function is piecewise affine if its domain can be divided into finitely many regions on each of which the function agrees with an affine function.

Exact ReLU Identities

For any real numbers \(a\) and \(b\), the difference \(a-b\) determines which is larger. If \(a\geq b\), then \(\rho(a-b)=a-b\), and if \(a<b\), then \(\rho(a-b)=0\). Thus

$$ \max\{a,b\}=b+\rho(a-b). $$

The corresponding minimum follows by subtracting the positive part of the same difference from \(a\):

$$ \min\{a,b\}=a-\rho(a-b). $$

These identities are exact, including at \(a=b\). Applied pointwise, they show that the maximum or minimum of two functions can be formed with one ReLU of their difference and affine combinations of the results. The two-function maximum is convex as a function of the pair \((a,b)\), but the identity itself requires no convexity assumption on the functions being combined.

Worked Example: The Maximum of Two Affine Functions

Let \(g_1(x)=2x+1\) and \(g_2(x)=1-x\). Their difference is \(g_1(x)-g_2(x)=3x\). The identity gives

$$ \max\{2x+1,1-x\}=1-x+\rho(3x). $$

For \(x<0\), \(\rho(3x)=0\), so the result is \(1-x\), which is larger than \(2x+1\) because their difference is \(3x<0\). For \(x\geq0\), \(\rho(3x)=3x\), so the result is \(1-x+3x=2x+1\). At \(x=0\), both affine functions equal \(1\). The two affine pieces meet there, and the expression is exact on the whole real line.

Finite Maxima, Minima, and Network Size

A finite maximum can be computed by repeatedly applying the two-input identity. For \(m\) inputs, a binary tree combines pairs, then combines the resulting values, until one remains. If the tree is balanced, it has at most \(\lceil\log_2 m\rceil\) levels. A binary tree with \(m\) leaves has exactly \(m-1\) internal nodes, so the construction uses \(m-1\) max operations. Each operation uses one ReLU of a difference. Replacing every maximum by the minimum identity gives the analogous result for minima.

When the inputs are affine functions of \(x\), the computation can be implemented as a ReLU network. More generally, the binary-tree identities can be applied to outputs of networks. In a standard layered network, a value passed between hidden layers can be represented by the pair \((\rho(z),\rho(-z))\), since their difference is \(z\). This may add a constant number of units per intermediate value, but does not change the order of the size bound. Consequently, for \(m\) affine inputs, a balanced construction has \(O(m)\) ReLU units and \(O(\log m)\) depth. These are upper bounds; a particular collection of functions may admit a smaller network.

Theorem: If \(\ell_1,\ldots,\ell_m\) are affine functions on \(\mathbb{R}^d\), then \(f(x)=\max_{1\leq i\leq m}\ell_i(x)\) is represented exactly by a ReLU network with \(O(m)\) ReLU units and \(O(\log m)\) hidden layers. The constants in these bounds do not depend on \(d\) or \(m\).

Proof. For \(m=1\), the function is affine and can be represented by the output layer. For \(m\geq2\), arrange the \(\ell_i\) as leaves of a binary tree, padding with repeated leaves if necessary to reach a power of two. At each internal node, apply \(\max\{u,v\}=v+\rho(u-v)\) to the functions at its two children. Induction up the tree shows that the value at each node is the maximum of the affine functions among its descendant leaves. Therefore, the root is \(f\). The tree has fewer than \(2m\) leaves after padding and hence fewer than \(2m\) internal nodes. It has at most \(\lceil\log_2 m\rceil\) levels. Each node requires one ReLU in the computation, and passing values between layers in a standard network uses at most a constant number of additional units per intermediate value through the positive-negative representation above. Thus the total number of ReLU units is \(O(m)\), and the depth is \(O(\log m)\). \(\square\)

The theorem also describes an important class of piecewise-affine functions. Each \(\ell_i\) is affine, so their maximum is continuous and piecewise affine: at a point where a particular \(\ell_i\) is largest, the maximum agrees with that affine function, and the regions are determined by the inequalities \(\ell_i(x)\geq\ell_j(x)\). The regions may be empty, and multiple pieces may tie on their boundaries. The theorem is a representation result for maxima of affine functions; it does not assert that every piecewise-affine function is a maximum of affine functions.

Worked Example: A Convex Piecewise-Affine Envelope

Consider the three affine functions \(\ell_1(x)=x\), \(\ell_2(x)=1-x\), and \(\ell_3(x)=0\). Their maximum is

$$ f(x)=\max\{x,1-x,0\}. $$

For \(x\leq0\), \(1-x\geq1\) while \(x\leq0\), so \(1-x\) is the maximum. For \(0\leq x\leq \tfrac12\), \(1-x\geq x\) and \(1-x\geq0\), so again the maximum is \(1-x\). For \(\tfrac12\leq x\leq1\), \(x\geq1-x\) and \(x\geq0\), so the maximum is \(x\). For \(x\geq1\), \(x\) is also the maximum. Hence

$$ f(x)= \begin{cases} 1-x, & x\leq \tfrac12,\\ x, & x\geq \tfrac12. \end{cases} $$

The zero function does not become the maximum on any interval, but it is still a valid input to the envelope. One network expression is \(\max\{\max\{x,1-x\},0\}\), using two two-input max operations. This illustrates that an envelope can be built by successive exact comparisons even when some candidate pieces are never active.

Uniform Approximation Error Through Maxima and Minima

Maxima and minima are also stable under uniform approximation. This matters when the functions being combined cannot themselves be represented exactly, or when they have already been approximated by networks. The key fact is that changing every candidate value by at most \(\varepsilon\) can change the largest or smallest value by no more than \(\varepsilon\).

Theorem: Let \(f_1,\ldots,f_m\) and \(g_1,\ldots,g_m\) be real-valued functions on \(\Omega\), and suppose \(\sup_{x\in\Omega}|f_i(x)-g_i(x)|\leq\varepsilon\) for every \(i\), where \(\varepsilon\geq0\). Then \[ \sup_{x\in\Omega}\left|\max_i f_i(x)-\max_i g_i(x)\right|\leq\varepsilon, \qquad \sup_{x\in\Omega}\left|\min_i f_i(x)-\min_i g_i(x)\right|\leq\varepsilon. \]

Proof. Fix \(x\in\Omega\). For each \(i\), \(f_i(x)\leq g_i(x)+\varepsilon\), so taking the maximum over \(i\) gives \(\max_i f_i(x)\leq\max_i g_i(x)+\varepsilon\). Interchanging \(f_i\) and \(g_i\) gives \(\max_i g_i(x)\leq\max_i f_i(x)+\varepsilon\). Together these inequalities imply \(\left|\max_i f_i(x)-\max_i g_i(x)\right|\leq\varepsilon\). Taking the supremum over \(x\) proves the maximum bound. For minima, \(f_i(x)\leq g_i(x)+\varepsilon\) for every \(i\) implies \(\min_i f_i(x)\leq\min_i g_i(x)+\varepsilon\); interchanging the functions gives the reverse bound. Taking the supremum proves the minimum bound. \(\square\)

In particular, if each \(g_i\) is a network approximation to \(f_i\) with uniform error at most \(\varepsilon\), then an exact ReLU maximum of the \(g_i\) approximates the maximum of the \(f_i\) with error at most \(\varepsilon\). The number of candidates does not multiply this error. A larger number of components may increase network size, but the uniform error bound remains unchanged.

Worked Example: Approximating a Maximum of Two Quadratics

On \([0,1]\), consider \(F(x)=\max\{x^2,(1-x)^2\}\). We construct a network approximation using a piecewise-affine approximation to the square. Divide \([0,1]\) into \(N\) equal intervals, with \(h=1/N\), and let \(q_N\) linearly interpolate \(x^2\) at the points \(k/N\), for \(k=0,\ldots,N\).

The slope on the interval \([k/N,(k+1)/N]\) is \[ \frac{((k+1)/N)^2-(k/N)^2}{1/N}=\frac{2k+1}{N}. \] The initial slope is \(1/N\), and each successive slope increases by \(2/N\). Therefore the interpolant has the hinge representation

$$ q_N(x)=\frac{x}{N}+\frac{2}{N}\sum_{k=1}^{N-1}\rho\left(x-\frac{k}{N}\right). $$

On an interval \([a,a+h]\), write \(x=a+t\) with \(0\leq t\leq h\). The chord joining the values of \(x^2\) at the endpoints exceeds \(x^2\) by \(t(h-t)\). Since \(t(h-t)\leq h^2/4\), it follows that \(|q_N(x)-x^2|\leq 1/(4N^2)\) throughout \([0,1]\). The same bound holds for \(q_N(1-x)\) as an approximation to \((1-x)^2\). By the maximum error theorem,

$$ \sup_{x\in[0,1]} \left|\max\{q_N(x),q_N(1-x)\}-F(x)\right| \leq \frac{1}{4N^2}. $$

The hinge formula uses \(N-1\) ReLU units for \(q_N(x)\). The transformed function \(q_N(1-x)\) has the same order of size, and one additional max operation combines the two approximations. For example, \(N=10\) gives a uniform error bound of \(1/(4\cdot100)=0.0025\). This calculation separates the approximation cost for the quadratic components from the small additional cost of taking their maximum.

Minima, Envelopes, and a Common Pitfall

Minima need no separate approximation machinery: for any functions \(g_i\), \(\min_i g_i=-\max_i(-g_i)\). Negating the affine output of a network therefore converts a maximum construction into a minimum construction. More generally, a finite envelope formed by taking maxima or minima of network outputs can be represented by composing the pairwise identities. If the component networks each have a uniform approximation guarantee, the stability result gives a corresponding guarantee for the combined envelope.

Common pitfall: It is tempting to argue that if each of \(m\) component functions has error at most \(\varepsilon\), then the maximum has error at most \(m\varepsilon\), on the grounds that errors accumulate across the \(m\) candidates. That reasoning treats a maximum like a sum. At a fixed input, every candidate lies between its approximation minus \(\varepsilon\) and its approximation plus \(\varepsilon\); taking a maximum preserves those two bounds. The correct uniform error is at most \(\varepsilon\), independent of \(m\). Network size can grow with \(m\), but this particular error bound does not.

A second point to keep distinct is exact representation versus approximation. The maximum of finitely many affine functions is represented exactly by a ReLU network. If the candidates are nonlinear functions, the maximum identity is still exact as an operation, but the candidate functions may require approximation. In that case, the quality of the final result depends on the component approximation errors, while the maximum operation itself adds no further uniform error.

Key takeaway: ReLU implements pairwise maxima and minima exactly. A balanced tree combines \(m\) candidates with \(O(m)\) units and logarithmic depth, while uniform errors in the candidates pass through the maximum or minimum without amplification.

Check Your Understanding

Use the identities and error bounds developed above.

  1. Write \(\max\{a,b\}\) and \(\min\{a,b\}\) using \(\rho\), and verify each formula in the cases \(a\geq b\) and \(a<b\).
  2. How many pairwise max operations are needed to combine \(m\) candidates in a binary tree, and what depth can a balanced tree achieve?
  3. Why is the maximum of finitely many affine functions piecewise affine? Describe the regions on which one affine function is largest.
  4. If three approximate component functions each have uniform error at most \(0.02\), what uniform error bound follows for their maximum?
  5. In the quadratic example, what error bound results when \(N=20\), and how does it compare with the bound for \(N=10\)?
Clinical Biostats