Chapter 7: Expressivity of Feedforward Networks
Having understood the architecture and the training of feedforward neural networks in the previous chapters, we now ask the questionWhy should neural networks work?
There is abundant empirical evidence that deep learning models work well in a wide range of domains, such as image recognition and natural language processing. However, empirical evidence does not explain why they work. A part of the answer comes from mathematical results on the capacity of neural networks to approximate functions. This capacity is referred to as the expressivity of a network. In this chapter, we review a few of these results.
A neural network is used in two major ways. One is pattern recognition, which corresponds to a classification problem, as illustrated in the previous chapters. The other is function approximation, in particular regression, where the goal is to approximate an underlying functional relationship between inputs and outputs. In fact, classification can also be viewed as a function approximation, where the function maps input vectors to discrete labels.
In recent years, neural networks have also been used to construct approximate solutions of differential equations. The differential equation is incorporated into the cost function through its residual. Such networks are known as physics-informed neural networks (PINNs). PINNs provide a natural bridge from approximation theory to scientific machine learning.
In Section 7.1, we show that a network with a single hidden layer can approximate any continuous function on a compact set to any desired accuracy. This property is known as the universal approximation property. In Section 7.2, we discuss the role of depth and width. We show by an example that deep networks can represent certain functions with exponentially fewer neurons than shallow networks. Finally, in Section «Click Here», we outline the idea of PINNs and apply it to an ordinary differential equation and to simple linear partial differential equations.
7.1 Universal Approximation by Shallow Networks
Approximating a nonlinear function is challenging because different types of nonlinearities require different function classes for effective approximation. A basic requirement in approximation theory is to identify a function class within which any given function can be approximated to a desired accuracy. Such a property is referred to as universal approximation. In this section, we show that shallow neural networks have this property.7.1.1 Function Spaces and Universal Approximators
Let \(\mathcal{D}_x\) denote the input or feature space and \(\mathcal{D}_y\) the target or label space. Define a function classIn what follows, we consider the function class \(\mathbb{F}\) as a linear space equipped with a norm. We call such a normed linear space a function space, especially if it is a Banach space or a Hilbert space.
Continuous Functions:
-
Let \(\mathcal{D}_x\subset \mathbb{R}^{n_0}\) be compact and \(\mathcal{D}_y\subseteq \mathbb{R}^{n_L}\). Then,
\[ \mathbb{F}(\mathcal{D}_x,\mathcal{D}_y):= \big\{ f:\mathcal{D}_x \rightarrow \mathcal{D}_y~\big|~ f ~ \text{is continuous}\big\} \]is a function space with the uniform norm (or supremum norm) defined as\[ \|f\|_{\infty,\mathcal{D}_x} := \sup\{\|f(\boldsymbol{x})\|~|~\boldsymbol{x}\in \mathcal{D}_x \}, \]where \(\|\cdot\|\) on the right hand side denotes a vector norm on \(\mathbb{R}^{n_L}\), which is often taken as the Euclidean norm.
We use the notation \(\mathbb{C}(\mathcal{D}_x, \mathcal{D}_y)\) to denote the space of continuous functions. If \(\mathcal{D}_y=\mathbb{R}\), then we write \(\mathbb{C}(\mathcal{D}_x)\).
Since \(\mathcal{D}_x\) is compact, \((\mathbb{C}(\mathcal{D}_x, \mathcal{D}_y), \|\cdot\|_{\infty,\mathcal{D}_x})\) is a Banach space.
-
Let \(\mathcal{D}_x\subset \mathbb{R}^{n_0}\) be compact, \(\mathcal{D}_y\subseteq \mathbb{R}^{n_L}\), and let \(k\in \mathbb{N}\). Then,
\[ \mathbb{F}(\mathcal{D}_x,\mathcal{D}_y):= \big\{ f:\mathcal{D}_x \rightarrow \mathcal{D}_y~\big|~ f ~ \text{is } k\text{-times continuously differentiable}\big\} \]is a function space with the norm defined as\[ \|f\|_{\infty,k,\mathcal{D}_x} := \max_{|\boldsymbol{\alpha}|\le k}~\sup\{\|\partial^{\boldsymbol{\alpha}} f(\boldsymbol{x})\|~|~\boldsymbol{x}\in \mathcal{D}_x\}, \]where \(\boldsymbol{\alpha}=(\alpha_1,\ldots,\alpha_{n_0})\in \mathbb{N}_0^{n_0}\) is a multi-index, \(|\boldsymbol{\alpha}|=\alpha_1+\ldots+\alpha_{n_0},\) and \(\mathbb{N}_0^{n_0} = (\mathbb{N}\cup \{0\})^{n_0}\).
We use the notation \(\mathbb{C}^k(\mathcal{D}_x, \mathcal{D}_y)\) to denote the space of \(k\)-times continuously differentiable functions. It is a Banach space since \(\mathcal{D}_x\) is compact. If \(\mathcal{D}_y=\mathbb{R}\), then we write \(\mathbb{C}^k(\mathcal{D}_x)\).
Solutions of mathematical problems are often functions, and we look for a solution in an appropriate function space. For many problems, a solution is known to exist, but its explicit form is either unknown or too complicated to obtain. In such situations, we look for an approximation to the solution in a hypothesis set. This hypothesis class can approximate every element to any desired accuracy only if it is dense in the function space.
A subset \(\mathcal{H}\) of a normed linear space \(\mathbb{F}\) is said to be dense in \(\mathbb{F}\) if for every \(f\in \mathbb{F}\), and every \(\varepsilon>0\), there exists \(h\in \mathcal{H}\) such that
We now introduce a notation for families of neural networks.
Given \(L, \hat{n}, n_0, n_L\in \mathbb{N}\), and an activation function \(\mathscr{A}:\mathbb{R}\rightarrow \mathbb{R}\), the set of all multilayer perceptrons of depth \(L\) and width \(\hat{n}\), with activation \(\mathscr{A}\) in all hidden layers and the identity activation in the output layer, is denoted by
for some \(w^{(1)}_{j1}, b^{(1)}_{j}, w^{(2)}_{1j}, b^{(2)}_{1} \in \mathbb{R}\), \(j=1,2,\ldots, \hat{n}\).
We now define the notion of a universal approximator.
A set \(\mathcal{H}\) of functions defined on \(\mathbb{R}^n\) is called a universal approximator of \(\mathbb{C}(\mathbb{R}^n)\) if, for every compact set \(\mathcal{D}_x \subset \mathbb{R}^n\), the set of restrictions \(\mathcal{H}|_{\mathcal{D}_x} = \{h|_{\mathcal{D}_x} : h \in \mathcal{H}\}\) is dense in \(\mathbb{C}(\mathcal{D}_x)\) with respect to the uniform norm. In other words, for every compact set \(\mathcal{D}_x \subset \mathbb{R}^n\), every \(f \in \mathbb{C}(\mathcal{D}_x)\) and every \(\varepsilon > 0\), there exists \(h \in \mathcal{H}\) such that
The following is a classical example of a universal approximator.
Recall that a polynomial function \(p : \mathbb{R}^n \to \mathbb{R}\) is of the form
By the Stone--Weierstrass theorem, the set of all polynomials is dense in \(\mathbb{C}(\mathcal{D}_x)\) for every compact set \(\mathcal{D}_x\subset \mathbb{R}^n\). Hence, the set of all polynomials on \(\mathbb{R}^n\) is a universal approximator of \(\mathbb{C}(\mathbb{R}^n)\).
7.1.2 Shallow ReLU Networks in One Dimension
In this subsection, we prove that shallow \(\texttt{ReLU}\) networks are universal approximators of \(\mathbb{C}(\mathbb{R})\). The proof has two steps. First, we show that continuous piecewise affine functions are dense in \(\mathbb{C}([a,b])\). Second, we show that every continuous piecewise affine function on \([a,b]\) is a shallow \(\texttt{ReLU}\) network.Recall, a function \(\varphi:[a,b]\rightarrow \mathbb{R}\) is called a continuous piecewise affine function with respect to a partition \( a = x_0 < x_1 < \cdots < x_N = b \) if \(\varphi\) is continuous on \([a,b]\) and affine on each subinterval \([x_k, x_{k+1}]\), \(k=0,1,\ldots, N-1\).
Since \(f\) is continuous on the compact interval \([a,b]\), it is uniformly continuous. Hence, there exists \(\delta=\delta(\varepsilon)>0\) such that \(|f(x)-f(y)|<\varepsilon\) whenever \(x,y\in[a,b]\) and \(|x-y|<\delta\). Choose \(N\in \mathbb{N}\) sufficiently large so that \((b-a)/N<\delta\). Then, on the uniform partition
Let \(x\in [a,b]\) be arbitrary. Choose \(k\in \{0,1,\ldots, N-1\}\) such that \(x\in [x_k, x_{k+1}]\). The value \(\varphi_\varepsilon(x)\) lies between \(f(x_k)\) and \(f(x_{k+1})\). Since \(f\) is continuous, by the intermediate value theorem, there exists \(\xi\in [x_k, x_{k+1}]\) such that
For \(x\in [x_0, x_1]\), the condition \({\mathscr{F}_{2,N}}(x) = \varphi(x)\) reads
For any \(k=1,2,\ldots, N-1\), let \(x\in [x_k, x_{k+1}]\). Then we have
Thus, \({\mathscr{F}_{2,N}}\) is affine on \([x_k, x_{k+1}]\). Let us take
Then, its slope on the interval \([x_k, x_{k+1}]\) is
It remains to show that \({\mathscr{F}_{2,N}}(x_k) = \varphi(x_k),~~ k=0,1,2,\ldots, N\). We prove this by induction on \(k\).
For \(k=0\), we have \({\mathscr{F}_{2,N}}(x_0) = \varphi(x_0)\). Assume that \({\mathscr{F}_{2,N}}(x_k) = \varphi(x_k)\). Since \({\mathscr{F}_{2,N}}\) and \(\varphi\) are affine with the same slope in \([x_k, x_{k+1}]\), we have \({\mathscr{F}_{2,N}}(x_{k+1}) = \varphi(x_{k+1})\).
Two affine functions that takes the same value at \(x_k\) and \(x_{k+1}\) coincide on \([x_k,x_{k+1}]\). Hence, \({\mathscr{F}_{2,N}}(x) = \varphi(x)\) for all \(x\in [a,b]\).
We now state and prove the main result of this subsection.
By Lemma 7.1, there exists a continuous piecewise affine function \(\varphi_\varepsilon\) on a partition of \([a,b]\) with \(\hat{n}_\varepsilon\) subintervals such that
Since \(\mathcal{D}_x\) and \(f\) were arbitrary, \(\mathscr{N}_2(\mathscr{R}_0;1,1)\) is a universal approximator of \(\mathbb{C}(\mathbb{R})\).
The following problem shows that shallow networks with the Heaviside activation also approximate continuous functions uniformly on an interval, although the network functions themselves are discontinuous.
- Show that there exists a step function \(s_\varepsilon:[a,b]\rightarrow \mathbb{R}\), constant on each \([x_k,x_{k+1})\) of a uniform partition, such that \(\|f - s_\varepsilon\|_{\infty,[a,b]} < \varepsilon\).
- Show that there exists \({\mathscr{F}_{2,\hat{n}_\varepsilon}} \in \mathscr{N}_{2}(\mathscr{H}; 1, 1)\), for some \(\hat{n}_\varepsilon\in \mathbb{N}\), such that \(\|f - {\mathscr{F}_{2,\hat{n}_\varepsilon}}\|_{\infty,[a,b]} < \varepsilon\).
7.1.3 General Activation Functions
The universal approximation property is not restricted to the \(\texttt{ReLU}\) activation or to one dimension. In this subsection, we state two classical results without proof. The first result is for sigmoidal activation functions.Let \(\mathscr{S}:\mathbb{R}\rightarrow \mathbb{R}\) be a continuous sigmoidal function and let \(I_{n_0}=[0,1]^{n_0}\). Then, the restrictions of the networks in \(\mathscr{N}_{2}(\mathscr{S}; n_0, 1)\) to \(I_{n_0}\) form a dense subset of \(\mathbb{C}(I_{n_0})\).
The next theorem characterizes the continuous activation functions for which shallow networks are universal approximators.
7.2 Role of Depth and Width
The results of the previous section show that depth is not necessary for universal approximation. A single hidden layer is sufficient if the width is allowed to be arbitrarily large. Nevertheless, deep networks are preferred in practice. In this section, we show by an example that depth can reduce the number of neurons needed to represent a function. We also state a result showing that depth can compensate for a bounded width.7.2.1 Depth: The Sawtooth Example
Consider the hat function \(g:[0,1]\rightarrow [0,1]\) defined bySince \(g\) maps \([0,1]\) into \([0,1]\), we can define \(g_k:[0,1]\rightarrow[0,1]\), for \(k\in \mathbb{N}\), recursively by
From the above representation of \(g\), can you observe that \(g\) can be written as a neural network on the interval \([0,1]\)? If so, what are the width and depth of this network? Provide the activation function of each layer and give the number of weights and biases.
The graph of \(g_{k}\) is a sawtooth. The next proposition counts its linear pieces.
Assume that the statement holds for some \(k\in \mathbb{N}\), and write \(g_{k+1} = g\circ g_{k}\). Fix \(j\in\{0,1,\ldots,2^k-1\}\). The two halves of \(I_{j,k}\) are
By the induction hypothesis, \(g_{k}\) is an affine bijection from \(I_{j,k}\) onto \([0,1]\) with slope \((-1)^j 2^k\). Hence, it maps the midpoint of \(I_{j,k}\) to \(\tfrac{1}{2}\), and it maps each half of \(I_{j,k}\) bijectively onto one of the intervals \([0,\tfrac{1}{2}]\) and \([\tfrac{1}{2},1]\).
Case 1: \(j\) even. Then \(g_{k}\) is increasing on \(I_{j,k}\). It maps \(I_{2j,k+1}\) onto \([0,\tfrac{1}{2}]\), where \(g\) has slope \(2\), and it maps \(I_{2j+1,k+1}\) onto \([\tfrac{1}{2},1]\), where \(g\) has slope \(-2\).
Case 2: \(j\) odd. Then \(g_{k}\) is decreasing on \(I_{j,k}\). It maps \(I_{2j,k+1}\) onto \([\tfrac{1}{2},1]\), where \(g\) has slope \(-2\), and it maps \(I_{2j+1,k+1}\) onto \([0,\tfrac{1}{2}]\), where \(g\) has slope \(2\).
In both cases, \(g_{k+1}\) is a composition of two affine bijections on each half of \(I_{j,k}\). Hence, it is an affine bijection from each half onto \([0,1]\). Its slope is the product of the two slopes. In both cases, this gives
Finally, consecutive slopes have opposite signs. Hence, each of the \(2^k-1\) interior nodes is a breakpoint, and \(g_{k}\) has exactly \(2^k\) affine pieces.
For illustration, consider \(k=2\). Since \(g(x)\in[0,1]\) for \(x\in[0,1]\), we can apply the above representation to \(g(x)\) and get
Take
ReLU activation, and an output layer with identity activation. Therefore,
We now prove the proposition for general \(k\) by induction. For \(k\in\mathbb{N}\), define
The case \(k=1\) is proved above. Assume that the statement holds for some \(k\in\mathbb{N}\). Let \(x\in[0,1]\), and let \(\boldsymbol{x}^{(k)}=(x^{(k)}_1,x^{(k)}_2)^\top\) be the activation of the last hidden layer of \({\mathscr{F}_{k+1,2}}(\,\cdot\,;\boldsymbol{\Theta}_k)\) at \(x\). By the induction hypothesis and the form of the output layer,
The two terms
Therefore, a neural network representation of \(g_{k+1}\) is obtained by inserting a hidden layer in the neural network representation of \(g_k\) before the output layer with the augmented weight as given above with activation \(\mathscr{R}_0\) and thus can be written as
Step 1: Each \(\phi_j\) is continuous and has at most one breakpoint. The function \(\phi_j\) is continuous, since it is the composition of the continuous function \(\mathscr{R}_0\) with an affine function. We consider two cases.
- If \(w^{(1)}_{j1}=0\), then \(\phi_j(x)=\mathscr{R}_0\big(b^{(1)}_j\big)\) is constant on \(\mathbb{R}\).
- If \(w^{(1)}_{j1}\neq 0\), define \(\xi_j = -b^{(1)}_j/w^{(1)}_{j1}\). Then \(w^{(1)}_{j1} x + b^{(1)}_j = w^{(1)}_{j1}(x-\xi_j)\). This expression has one sign on \((-\infty,\xi_j]\) and the opposite sign on \([\xi_j,\infty)\). On the side where it is non-negative, \(\phi_j(x) = w^{(1)}_{j1}(x-\xi_j)\). On the other side, \(\phi_j(x)=0\). Hence, \(\phi_j\) is affine on \((-\infty,\xi_j]\) and on \([\xi_j,\infty)\).
Step 2: The network is continuous and has at most \(\hat{n}\) breakpoints. Let \(P\) be the set of points \(\xi_j\) for those \(j\) with \(w^{(1)}_{j1}\neq 0\). Then \(P\) has \(m\le \hat{n}\) elements. Order them as \(p_1 < p_2 < \cdots < p_m\). These points divide \(\mathbb{R}\) into the \(m+1\) intervals
Step 3: Restriction to an interval. Let \(I\subseteq\mathbb{R}\) be an interval. The function \({\mathscr{F}_{2,\hat{n}}}\) is affine on the intersection of \(I\) with each of the \(m+1\) intervals of Step 2. Hence, its restriction to \(I\) has at most \(m+1\le \hat{n}+1\) affine pieces.
By the above Lemma 7.3, \(g_k\) is continuous piecewise affine on \([0,1]\) with respect to the partition \(x_{j,k}=j/2^k\), \(j=0,1,\ldots,2^k\). This partition has \(2^k\) subintervals. Hence, by Lemma 7.2, there exists \({\mathscr{F}_{2,2^k}}\) such that \({\mathscr{F}_{2,2^k}}=g_k\) on \([0,1]\).
Step 2: [Lower bound] Let \({\mathscr{F}_{2,\hat{n}}}=g_k\) on \([0,1]\). By Lemma 7.3, the slope of \(g_k\) changes at each of the \(2^k-1\) points \(x_{j,k}\), \(j=1,2,\ldots,2^k-1\). Each such point is a breakpoint of \({\mathscr{F}_{2,\hat{n}}}\). By Theorem 7.4, \({\mathscr{F}_{2,\hat{n}}}\) has at most \(\hat{n}\) breakpoints. Hence, \(\hat{n}\ge 2^k-1\).
Suppose that \(\hat{n}=2^k-1\). Then every neuron has a breakpoint, and these breakpoints are exactly the points \(x_{j,k}\), \(j=1,2,\ldots,2^k-1\). After relabelling the neurons, the \(j\)-th neuron has \(w^{(1)}_{j1}\neq 0\) and breakpoint \(x_{j,k}\). Let \(s_j\) be the sign of \(w^{(1)}_{j1}\). Since \(\mathscr{R}_0\) is positively homogeneous,
If \(s_j=1\), the \(j\)-th term has slope \(0\) to the left of \(x_{j,k}\) and slope \(a_j\) to the right. If \(s_j=-1\), it has slope \(-a_j\) to the left and slope \(0\) to the right. In both cases, its slope jumps by \(a_j\) at \(x_{j,k}\). The other terms are affine near \(x_{j,k}\). By Lemma 7.3, the slope of \(g_k\) jumps at \(x_{j,k}\) by
Let \(J=\{j : s_j=-1\}\). On \((0,x_{1,k})\), the terms with \(s_j=1\) vanish, and the terms with \(j\in J\) have slope \(-a_j\). The slope of \(g_k\) on this interval is \(2^k\). Hence,
The above comparison concerns exact representation. Telgarsky (2016) proves a stronger result for approximation. Networks with fewer layers need exponentially many neurons even to approximate \(g_{k}\) to a fixed accuracy in the \(L^1\) norm.
Thus, depth does not increase the class of functions that can be approximated. It can reduce the number of neurons needed to approximate a given function.
- Show that the number of hidden neurons is \(N=(L-1)\hat{n}\), and that the number of trainable parameters (weights and biases) is
\[ P = 3\hat{n}+1 + (L-2)\,\hat{n}(\hat{n}+1). \]Deduce that\[ P = (\hat{n}+1)\,N - \hat{n}^2 + 2\hat{n} + 1. \]Hence, for a fixed width \(\hat{n}\), the number of parameters is an affine function of the number of neurons.
- Find the number of trainable parameters of the network of Lemma 7.4.
- Using Corollary 7.1, find a lower bound on the number of trainable parameters of a shallow network that represents \(g_k\) on \([0,1]\).
- Compare the two numbers for \(k=10\).