ResNet with one-neuron hidden layers is a Universal Approximator
Hongzhou Lin, Stefanie Jegelka
Introduction
Deep neural networks are central to many recent successes of machine learning, including applications such as computer vision, natural language processing, or reinforcement learning. A common trend in deep learning has been to construct larger and deeper networks, starting from the pioneer convolutional network LeNet , to networks with tens of layers such as AlexNet or VGG-Net , or recent architectures like GoogLeNet/Inception or ResNet , which may contain hundreds or thousands of layers. A typical observation is that deeper networks offer better performance. This phenomenon, at least on the training set, supports the intuition that a deeper network should have more capacity to approximate the target function, and leads to a question that has received increasing interest in the theory of deep learning: can all functions that we may care about be approximated well by a sufficiently large and deep network? In this work, we address this important question for the popular ResNet architecture.
The question of representational power of neural networks has been answered in different forms. Results in the late eighties showed that a network with a single hidden layer can approximate any continuous function with compact support to arbitrary accuracy, when the width goes to infinity . This result is referred to as the universal approximation theorem. Analogous to the classical Stone-Weierstrass theorem on polynomials or the convergence theorem on Fourier series, this theorem implies that the family of neural networks are universal approximators: we can apply neural networks to approximate any continuous function and the accuracy improves as we add more neurons in the width. More importantly, the coefficients in the network can be efficiently learned via back-propagation, providing an explicit representation of the approximation.
This classical universal approximation theorem completely relies on the power of the width increasing to infinity, i.e., “fat” networks. Current “tall” deep learning models, however, are not captured by this setting. Consequently, theoretically analyzing the benefit of depth has gained much attention in the recent literature . The main focus of these papers is to provide examples of functions that can be efficiently represented by a deep network but are hard to represent by shallow networks. These examples require exponentially many neurons in a shallow network to achieve the same approximation accuracy as a deep network with only a polynomial or linear number of neurons. Yet, these specific examples do not imply that all shallow networks can be represented by deep networks, leading to an important question:
If the number of neurons in each layer is bounded, does universal approximation hold when the depth goes to infinity?
This question has recently been studied by for fully connected networks with ReLU activation functions: if each hidden layer has at least neurons, where is the dimension of the input space, the universal approximation theorem holds as the depth goes to infinity. If, however, at most neurons can be used in each hidden layer, then universal approximation is impossible even with infinite depth.
In practice, other architectures have been developed to improve empirical results. A popular example is ResNet , which includes an identity mapping in addition to each layer. A first step towards a better theoretical understanding of those empirically successful models is to ask how the above question extends to them. Do the architecture variations make a difference theoretically? Due to the identity mapping, for ResNet, the width of the network remains the same as the input dimension. For a formal analysis, we stack modules of the form shown in Figure 1, and analyze how small the hidden green layers can be. The resulting width of (blue) or even less (green) stands in sharp contrast with the negative result for width for fully connected networks in ; their constructions do not transfer. Indeed, our empirical illustrations in Section 2 demonstrate that, empirically, significant differences in the representational power of narrow ResNets versus narrow fully connected networks can be observed. Our theoretical results confirm those observations.
show that ResNet enjoys universal finite-sample expressive power, i.e., ResNet can represent any classifier on any finite sample perfectly. This positive result in the discrete setting motivates our work. Their proof, however, relies on the fact that samples are “far” from each other and hence cannot be used in the setting of full functions in continuous space.
This result implies that, compared to fully connected networks, the identity mapping of ResNet indeed adds representational power for tall networks.
After performing the nonlinear transformation, we add the identity to form the input of the next layer. The resulting ResNet is a combination of several basic residual blocks and a final linear output layer:
Unlike the original architecture , we do not include any convolutional layers, max pooling or batch normalization; the above simplified architecture turns out to be sufficient for universal approximation.
A motivating example
We begin by empirically exploring the difference between narrow fully connected networks, with neurons per hidden layer, and ResNet via a simple example: classifying the unit ball in the plane.
We artificially create a margin between positive and negative samples to make the classification task easier. We use logistic loss as the loss , where is the output of the network on the -th sample. After training, we illustrate the learned decision boundaries of the networks for various depths. Ideally, we would expect the decision boundaries of our models to be close to the true distribution, i.e., the unit ball.
Figure 2 shows the results. For the fully connected networks (top row), the learned decision boundaries have roughly the same shape for different depths: the approximation quality seems to not improve with increasing depth. While one may be inclined to argue that this is due to local optimality, our observation agrees with the results in :
In other words, the level set of a narrow fully connected network is either unbounded or has measure zero.
The proof is a direct application of Theorem 2 of , see Appendix E. Thus, even when the depth goes to infinity, a narrow fully connected network can never approximate a bounded region. Here we only show the case because we can easily visualize the data; the same observation will still hold in higher dimensions. A even stronger result has been developed very recently showing that any connected component of the decision boundaries obtained by a narrow fully connected network is unbounded .
The decision boundaries for ResNet appear strikingly different: despite the even narrower width of one, from 2 hidden layers onwards, the ResNet represents the indicator of a bounded region. With increasing depth, the decision boundary seems to converge to the unit ball, implying that Proposition 2.1 cannot hold for ResNet. These observations motivate the universal approximation theorem that we will show in the next section.
Universal approximation theorem
In this section, we present the universal approximation theorem for ResNet with one-neuron hidden layers. We sketch the proof in the one-dimensional case; the induction for higher dimensions relies on similar ideas and builds on it.
Sketch of the proof when 𝒅=𝟏𝒅1\bm{d=1}.
We start with the one-dimensional case, which is central to our construction. As mentioned above, it is sufficient to approximate piecewise constant functions. Given a piecewise constant function , there is a subdivision such that
where is the constant value on the -th subdivision . We will approximate via trapezoid functions of the following form, shown in Figure 3.
A trapezoid function is a simple continuous approximation of the indicator function. It is constant on the segment and linear in the -tolerant region . As goes to zero, the trapezoid function tends point-wisely to the indicator function.
A natural idea to approximate is to construct a trapezoid function on each subdivision and to then sum them up. This is the main strategy used in to show a universal approximation theorem for fully connected networks with width at least . However, this strategy is not applicable for the ResNet structure because the summation requires memory of past components, and hence requires additional units in every layer. The width constraint of ResNet due to the identity mapping makes the difference here.
In contrast, we construct our approximation in a sequential way: we build the components of the trapezoid function one after another. Due to the sequential construction, we can only build increasing trapezoid functions as shown in Figure 4. Such functions are trapezoidal on each subdivision and the constant value on increases when grows. The construction relies on the following basic operations:
The following operations are realizable by a single basic residual block of ResNet with one neuron:
where represents the input layer in the basic residual block and the output layer.
Geometrically, operation (a) allows us to shift the function by a constant; operation (b) allows us to remove the level set or and operation (c) can be used to adjust the slope. With these basic operations at hand, we construct the increasing trapezoid function by induction on the subdivisions. For any , we construct a function satisfying
is a trapezoid function on each , for any .
on for any .
is bounded on by .
if ,
where is the infinity norm and measures the quality of the approximation. A geometric illustration of is shown in Figure 5. On the first subdivisions, is the restriction of the desired increasing trapezoid function. On , the function is a very steep linear function with negative slope that enables the construction of next subdivision.
Given , we sequentially stack three residual blocks to build :
;
;
.
Figure 5 illustrates the effect of these blocks: the first operation flips the linear part on by adjusting the slope, the second operation folds the linear function in the middle of , and finally we cut off the peak at the appropriate level .
An important consideration is that we need to keep the function on previous subdivisions unchanged while building the next trapezoid function. We achieve this by increasing the function values. The different values will be the basis for adjusting the function value in each subdivision to the final value of the target function we want to approximate. Before proceeding with the adjustment, we remark that goes to as . This negative “tail” is easily removed by performing a cut-off operation via the max operator. This gives us the desired increasing trapezoid function .
To adjust the function values on the intervals , we identify the via the level sets of . This works because, by construction, on . More precisely, we define the level sets (for ) and adjust them one by one from highest to lowest value: for any , we sequentially build
Figure 6 shows an illustration. In particular, the first step only scales the top level set because the ReLU activation is active if and only if . The coefficients are appropriately selected such that after the scaling, the constant in matches . Hence, we have
Next, we set the second largest level set to , and so on. As a result, the function , obtained after rescaling all the level sets is the desired approximation of the piecewise constant function . Concretely, we show that satisfies
on and .
on for any .
is bounded with .
The detailed proof is deferred to the appendix. Importantly, our construction is valid for any small enough satisfying . Hence, the approximation error, which is bounded by
can be made arbitrarily small by taking to . This completes the proof.
Extension to higher dimensions.
The last step of the one-dimensional construction is performed by sliding through all the grid cells and adjusting the function value sequentially. This procedure can be done regardless of the dimension. Therefore, it suffices to build a -dimensional grid indicator function, which is a generalization of the increasing trapezoid function in high dimension space, see Definition B.4.
We perform an induction over dimensions and the main idea is to sum up an appropriate one-dimensional grid indicator function and an appropriate dimensional grid indicator function, as illustrated in Figure 7.
The summation gives the desired shape inside each grid cell. However, it also makes some regions positive that were previously zero. We address this issue via another separate level set property: there is a threshold such that a) the function value inside each is larger than ; b) the function values outside the grid cells are smaller than . Therefore, the desired grid indicator function can be obtained by performing a max operator with the threshold , i.e., cutting off the smaller values and setting them to zero (see Appendix C).
Number of neurons/layers.
A straightforward consequence of our construction is that we can approximate any piecewise constant function to arbitrary accuracy with a ResNet of hidden units/layers. The most space-consuming procedure is the function adjusting procedure which requires going through each of the grid cells one by one. Nevertheless, it is worth remarking that this procedure can be parallelized if we allow more hidden units per layer.
Deriving an exact relationship between the original target function and the required number of grid cells is nontrivial and is highly dependent on characteristics of . In particular, when the function is continuous, this number is related to the modulus of continuity of defined by
where is any compact set and represents the radius of the discretization. Given a desired approximation accuracy , we need to
second, determine such that .
Then, the number of grid cells is . This dependence is suboptimal in the exponent, and it may be possible to improve it using a similar strategy as . Also, by imposing stronger smoothness assumptions, this number may be reducible dramatically . These improvements are not the main focus of this paper, and we leave them for future work.
Discussion and concluding remarks
In this paper, we have shown the universal approximation theorem of the ResNet structure with one unit per hidden layer. This result stands in contrast to recent results on fully connected networks, for which universal approximation fails with width or less. To conclude, we add some final remarks and implications.
While we achieve universal approximation with only one hidden neuron in each basic residual block, one may argue that the structure of ResNet still passes the identity to the next layer. This identity map could be counted as hidden units, resulting in a total of hidden unites per residual block, and could be viewed as making the network a width () fully connected network. But, even from this angle, ResNet corresponds to a compressed or sparse version of a fully connected network. In particular, a width () fully connected network has connections per layer, whereas only connections are present in ResNet thanks to the identity map. This “overparametrization” of fully connected networks may be a patrial explanation why dropout has been observed to be beneficial for such networks. By the same argument, our result implies that width () fully connected networks are universal approximators, which is the minimum width needed .
Why does universal approximation matter?
As shown in Section 2, a width fully connected network can never approximate a compact decision boundary even if we allow infinite depth. However, in high dimensional space, it is very hard to visualize and check the obtained decision boundary. The universal approximation theorem then provides a sanity check, and ensures that, in principle, we are able to capture any desired decision boundary.
Training efficiency.
The universal approximation theorem only guarantees the possibility of approximating any desired function, but it does not guarantee that we will actually find it in practice by running SGD or any other optimization algorithm. Understanding the efficiency of training may require a better understanding of the optimization landscape, a topic of recent attention .
Here, we try to provide a slightly different angle. By our theory, ResNet with one-neuron hidden layers is already a universal approximator. In other words, a ResNet with multiple units per layer is in some sense an over-parametrization of the model, and over-parametrization has been observed to benefit optimization . This might be one reason why training a very deep ResNet is “easier” than training a fully connected network. A more rigorous analysis is an interesting direction for future work.
Generalization.
Since a universal approximator is able to fit any function, one might expect it to overfit very easily. Yet, it is commonly observed that deep networks generalize surprisingly well on the test set. The explanation of this phenomenon is orthogonal to our paper, however, knowing the universal approximation capability is an important building block of such a theory. Moreover, the above-mentioned “over-parametrization” implied by our results may play a role too.
To conclude, we have shown a universal approximation theorem for ResNet with one-neuron hidden layers. This theoretically distinguishes them from fully connected networks. To some extent, our construction also theoretically motivates the current practice of going deeper and deeper in the ResNet architecture.
References
Appendix A Notations and preliminary
In this section, we set up the notations and prepare some tools towards the universal approximation theorem. We first define the class of piecewise constant functions with compact support and finite many discontinuities.
outside .
is constant on each small cube .
Theorem A.2 is a well known result directly derived from the definition of Lebesgue measure. As a result, it is sufficient to prove that ResNet can approximate any piecewise constant function arbitrarily well, which is the main objective of the following proof. We start by showing some basic operations allowed by ResNet with one unit per hidden layer.
The following operations are realizable by a single basic residual block of ResNet with one neuron:
where represents the input layer in the basic residual block and the output layer.
It is easy to see that (c) implies (a) and (b). We now prove (c). Indeed, the following coefficient do the job: given ,
These basic operations are extensively used in the following construction. Intuitively, operation (a) allows us to shift the function; operation (b) allows us to cut off the level set or and operation (c) is more complex, which can be used to adjust the slope.
Appendix B Warm Up: One Dimension case
We start with the one dimension case. As we mentioned, it is sufficient to approximate piecewise constant functions. Given a piecewise constant function , there is a subdivision such that
where is the constant value on the -th subdivision . We are going to approximate using trapezoid function.
Given a piecewise constant function , for any satisfying , there exists a ResNet such that
for and .
for , for .
is bounded with .
We first construct the increasing trapezoid function , as shown in Figure 9. It is a trapezoid function on each with “increasing” value.
We construct the increasing trapezoid function by induction on the subdivisions. For any , we construct a ResNet such that
is a trapezoid function on each , for any .
on for any .
is bounded on by .
if .
When , we start with the identity function and sequentially build
. (Cut off )
.
We provide a geometric interpretation in Figure 10 and it is easy to see that C1-C5 holds.
Now we proceed by induction. Assume that is constructed, we will stack more modules of one-neuron residual blocks on top of to build . More precisely, we use as input and sequentially perform
.
.
.
A geometric interpretation of the construction is shown in Figure 11.
The first operation flips the linear part on by adjusting the slope. By induction, is positive on and it is a negative linear function on . Thus,
The second operation folds the linear function in the middle of . We show that the ReLU function is active if and only if .
When , , then by C4
Thus the in the update (b) of is not active on , meaning when .
When , is a linear function with positive slope, which is increasing. Therefore, the in the update (b) is active only when .
Finally, we cut off the peak of at the appropriate level which yields . We deduce the following expression of :
It is then easy to check conditions C1-C5 holds, which enrolls the induction.
Before moving on, we remark that goes to as . This negative “tail” is easily removed by performing a cut-off operation via the max operator:
which sets all the negative values to zero. This gives us the desired increasing trapezoid function . One of the main properties of the increasing trapezoid function is that takes different value on different . This allows us to adjust the function value of different level sets separately. More concretely, we define level sets by
It is easy to see that for any . The main idea is to sequentially adjust the function value on different level sets . We start adjusting the top level set by performing
The ReLU activation is active if and only if , which means the function values on other level sets are unchanged. Moreover, when , which immediately implies . As a result, we have
Then we adjust the next level set, and so on.
More formally, for any , we sequentially construct
The -th subdivision is set to value by moving from to . We show by induction that satisfies
on and .
on for any .
on for any .
is bounded with .
It is clear that satisfies these properties. Assume that they are valid for , then from (5),
In particular, remarking that and for any . We have
This implies satisfies (a) and (c). To show (b), it remains to show on , which is a direct consequence of (5). Finally, (d) holds by remarking that
This completes the induction. Therefore the last function is the desired approximation of . More precisely, we have shown that
on and .
on for any .
is bounded with .
which can be made arbitrarily small by choosing an appropriate . This completes the proof. ∎
The only property of the increasing trapezoid function that we have used in the proof is the property of separate level sets. The increasing function value is an artifact that facilitates the sequential construction.
However, the concept of monotonicity does not generalize in high dimensions. Instead, we are going to introduce a notion called grid indicator function.
In dimension space, a hypercube is the Cartesian product of bounded intervals, i.e.
For small enough , we denote as the -interior of , namely
if .
if , for any .
In other words, can be viewed as an approximation of the indicator function, which in addition takes different function value on different hypercubes. For instance, the increasing trapezoid function is a grid indicator function when .
Appendix C Extension to high dimension
We extend our proof to high dimensions by following the same path as our one dimensional construction. We first construct a high dimensional grid indicator function and then adjust the function value on each grid cell one after another. It is worth remarking that this last step of function adjustment is performed by sliding through all the grid cells and adjusting the function value sequentially, which can be done regardless of the dimension. Therefore, the main effort is to build the high dimensional grid indicator function, which enjoys the separate level set property.
where denotes the total number of hypercubes and each is a -dimensional hypercube of the form
for some , , , . Moreover, we denote
for , which is the -interior of the -th grid cell .
is bounded with .
We are going to perform an induction on the dimension . The case is true by the analysis in Section B. Now assume that it is true for , which means we are able to approximate any dimensional piecewise constant function. The key idea is to view a -dimensional hypercube as the product of a one dimensional interval and a -dimensional hypercube. More precisely, we denote
Therefore each can be represented by , for some and . We are going to construct a dimensional grid indicator function and a one dimensional network grid indicator function independently.
By induction, there exists a dimensional ResNet such that
if
for .
is bounded with .
We have abused the notation to use to denote a -dimensional vector. Even though is dimensional, we can extend it to a dimensional network by setting the weight of the first coordinate to zero, see Figure 13.
Next, we construct an increasing trapezoid function on the first coordinate such that
is a trapezoid function on each , for .
for .
is bounded with .
We concatenate with in a dimensional network. This is possible since only operates on the first coordinate while operates on the last coordinates, see Figure 14.
Thanks to the identity mapping, we can pass the information forward even though the weights are set to zero. Thus, in the last layer of the above network, we get in the first neuron and in one of the last neurons. Now we are going to couple these two neurons by summing them up. For technical reasons, we need to ensure the positiveness of , which can be easily obtained by performing a max operator
Then we sum up and by performing
We show that a separation level set property holds respect to the -dimensional grid cell . More precisely,
When , one of the function , vanishes, thus
When , then
As a result, by performing a “cut and shift” operation:
on .
is bounded with .
In particular, different pairs gives different value of . Therefore is a -dimensional grid indicator function of the desired hypercube . Then it suffices to perform the function adjustment procedure on each individual grid cell to obtain the final approximation, as in the one dimensional case. This completes the proof. ∎
Appendix D Experimental settings
In this section, we provide more details of the experimental setting in the unit ball classification problem.
The training/testing samples are -dimensional vectors. We say is a positive sample if and is a negative sample sample if . The training set consists of positive samples and negative samples, being randomly generated.
About the training algorithm.
We train the network with logistic loss using SGD with momentum. We run the algorithm for 10 epochs and we observe that after 5-8 epochs the loss on the training set saturates.
Visualizing the decision boundaries.
After training, we learn a function based on the neural network. To visualize the decision boundary, we randomly sampled points in the ball and use red point to represent positive predictions and blue points to represent negative predictions .
Appendix E Proof of Proposition 2.1
We recall Proposition 2.1 in the main paper and prove it based on the result developed in .
In other words, the level set of a “narrow” fully connected network is either unbounded or has measure null.
When , one hidden unit fully connected network is always monotone. Thus the statement holds.
When . We apply Lemma 1 of : if a fully connected network with ReLU activation has at most neurons per hidden layer, then
We are going to stack one more layer on top of to build a new network which thresholds its negative part.
More precisely, we take the exact same coefficients as and duplicate the last linear transformation into two ReLU activation functions such that
Since is also a fully connected network with at most neurons per hidden layer, the lemma 1 of also applies to . Therefore,
Again the case when it is zero directly implies . Moreover, is upper bounded by one, which yields