Adaptive Neural Networks Using Residual Fitting
Current methods for estimating the required neural-network size for a given
problem class have focused on methods that can be computationally intensive,
such as neural-architecture search and pruning. In contrast, methods that add
capacity to neural networks as needed may provide similar results to
architecture search and pruning, but do not require as much computation to find
an appropriate network size. Here, we present a network-growth method that
searches for explainable error in the network's residuals and grows the network
if sufficient error is detected. We demonstrate this method using examples from
classification, imitation learning, and reinforcement learning. Within these
tasks, the growing network can often achieve better performance than small
networks that do not grow, and similar performance to networks that begin much
larger.
Noah Ford, John Winder, Josh McClellan
# Adaptive Neural Networks using Residual Fitting

## 1 Abstract

Current methods for estimating the required neural-network size for a given problem class have focused on methods that can be computationally intensive, such as neural-architecture search and pruning. In contrast, methods that add capacity to neural networks as needed may provide similar results to architecture search and pruning, but do not require as much computation to find an appropriate network size. Here, we present a network-growth method that searches for explainable error in the network's residuals and grows the network if sufficient error is detected. We demonstrate this method using examples from classification, imitation learning, and reinforcement learning. Within these tasks, the growing network can often achieve better performance than small networks that do not grow, and similar performance to networks that begin much larger.

## 2 Introduction

Prior to training a neural network on a set of data, it is difficult to estimate the size or shape of the network required to fit the complexity of the data. The network's ability to fit a data set is also dependent on the network's initialization, which further complicates the search for the "right" network size. For most problems, a smaller network than typically used would suffice if we only knew how to initialize the weights [1]. Since we have little a priori knowledge of the structure of the best-performing networks, we can either train a network that is much larger than needed, or we can search for an appropriate smaller network using techniques such as neural architecture search [2], network pruning [3], and network growing. In this paper, we present and test a new technique for networking growing that trains a small, neural network on the residuals of a larger network. This method can be used in addition to, and as a replacement for, neural architecture search, network pruning, and other growth methods.

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"
General architecture searches can find network sizes and shapes that are appropriate for a set of problems with a given complexity [4]. These methods train many neural networks, either simultaneously or in sequence, to discover the right architecture for a given problem. For example, [5] uses neural architecture search to find a more efficient and performant transformer-like network for translation tasks. While neural-architecture search can produce more efficient networks, the search itself is computationally intensive, as it necessitates the training of many networks.

Network pruning is another method to find suitable network structures, but often requires less computational cost than architecture searches. Pruning is particularly popular for finding small, performant networks for fast inference. Several criteria have been proposed for choosing which nodes and at what time to prune ([6], [3]). These methods can help find performant, smaller networks, but they often require training much larger networks to find the most performant subnetwork ([1]). Furthermore, pruning methods may produce small, neural networks that perform well on a particular problem, but do not adapt well to changes in data.

There has been less research into network growth methods than into architecture search or pruning, but network growth has benefits such as allowing for smaller initial networks and fitting distribution shifts in the data with additional growth during training. To grow a neural network, we must decide: 1. when to grow and 2. how to grow. To help determine when to grow a neural network, the method presented in [7] grows a neural network when the loss function is experiencing a plateau to help escape gradient-descent slow-downs. To determine how to grow, the method in [8] presents Gradient Maximizing Growth to maximize the gradients of new weights to accelerate training. Focusing on non-stochastic problems, the method presented in [9] and [10] solves for when and how to grow neural networks based on the network error, but it is not easily extensible to problems in which loss cannot be driven to zero. Most similar to the work presented here, AdaNet [11] approach iteratively grows a neural network before training. It uses the Rademacher complexity to approximate the generalization error of neural network and trains the network predicted to give the least generalization error.

The method presented has similar growth mechanisms to AdaNet, but the method here increases the network size during training by focusing on the network's Mean Squared Error (MSE). Instead of approximating the generalization error as in AdaNet, we train a residual network to approximate the loss of the base neural network. If the residual network can predict structure in the loss of the base network, the algorithm infers that some amount of network complexity is missing from the base neural network, and we combine the two networks into one and continue training. The algorithm then initializes a new residual network and fits the error of the base network again.

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"
## 3 Method

When training a fully connected, multi-layer perceptron with \(n\) hidden layers, we initialize a narrower neural network that also has \(n\) hidden layers. We call this network the residual neural network. After each training epoch, we train the residual network to fit the current residuals of the larger network (Fig 1).

If adding in the predicted residuals to the larger network's predictions improves the MSE above a certain user-defined threshold, we increase the latent size of the neural networks by fusing the residual network to the base neural network together. The two, joined networks create a new, fully connected neural network with hidden-layer widths equal to the number of nodes in the base network's hidden layer plus the number of nodes in the residual network's hidden layer.

The weights of the first layer and the output layer are completely defined by the base neural network and the residual network. However, the internal, hidden layers have new connections between the base nodes and the residual network's nodes. These weights need to be initialized. Initializing these weights to zero leads to the smallest MSE after growth, but the backpropagation algorithm will cause these weights to remain equal to each other. Here, we initialize the new weights randomly to have a one tenth the magnitude to the existing weights in the residual network.

After fusing the networks together, we continue to train the larger network. Additionally, we reset the weights of the residual neural network and continue to fit the residual network to the larger network's residuals. This algorithm is detailed in Algorithm 1.

Since this technique focuses on fitting predictable error in the residuals of the network, it is prone to overfitting. One technique to reduce overfitting and the subsequent growth of the neural networks is to use dropout layers during training in both the base neural network and the residual network. In some experiments, networks with dropout perform worse than networks without. So we don't need to rely on dropout to stop excessive network growth, we include a growth criterion that the current mean squared error must be over the growth threshold from the last time the network grew. So if the network last grew at

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"

Figure 1: Base Network and Residual Network Diagram
a MSE of 10, and the growth threshold is 10%, the base network must achieve an MSE of 9 before it can grow again.

```
Training data: \(\{X_{i}\}\), \(\{Y_{i}\}\), adaptation threshold \(\gamma\)\(f(x)\) Neural Network \(g(x)\) Residual Network \(\alpha_{prev}\gets 1\times 10^{6}\)\(\triangleright\) set \(\alpha_{prev}\) to some large number for\(i\) in number of epochs do  Fit \(f(x)\) to training data \(\{X_{i}\}\), \(\{Y_{i}\}\). Collect residuals \(\{r_{i}\}\)  Fit \(g(x)\) to \(\{X_{i}\}\), \(\{r_{i}\}\) \(\alpha\leftarrow\text{MSE}(f(x))\) \(\beta\leftarrow\text{MSE}(f(x)+g(x))\) if\(\beta/\alpha<1-\gamma\) and \(\alpha/\alpha_{prev}<1-\gamma\)then  Grow network by combining weights of \(f(x)\) and \(g(x)\)  Reset weights of \(g(x)\) \(\alpha_{prev}=\alpha\) endif endfor
```

**Algorithm 1** SANN Algorithm

## 4 Results

### Cifar

Following AdaNet [11], we compare the performance of these networks on CIFAR-10 classification using histogram data from the CIFAR images. The state-of-the art method for image classification typically include convolutional neural networks, but following [11], we use histograms of the image data to test the viability of this method. In these CIFAR-10 experiments, we only use histograms of each color distribution, with 40 bins per color, 120 bins total. We evaluate this method on a hold-out set. We test the performance of small fixed networks, small growing networks, large fixed networks, and large growing networks. We test the performance of the large growing networks to ensure that growth does not always occur at all network sizes. We run 10 training runs for each pairwise classification experiment for each network type.

For the classification of deer vs truck, the growing network performs better than the small, fixed network and similarly to the large networks (Figure 2). The large, growing network grows in size a small amount, but maintains a similar mean squared error to the large, fixed network.

In testing the networks' performance on the bird vs frog classification problem, we see that the training does not induce as much growth as that seen in the deer vs truck problem (Figure 3). The growing network, again, performs better than the small, fixed network and similarly to the larger networks.

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"
For the cat vs dog classification problem, neither the small nor large networks typically grow (Figure 4). This lack of growth means that the residual network typically does not find large error in the loss that the base network is not fitting. The smaller network performs worse than the larger network, but this difference is relatively small (less than 0.01 in mean loss). It is possible that the color histograms for cat vs dog classification do not contain enough information for the neural network to make complex classification decisions. In this case, the neural network for both the small and large networks do not grow.
### Imitation Learning

We use imitation learning as another testing task for the adaptive neural network method. We compare performance of networks of varying sizes within the DAgger algorithm [12]. DAgger is a popular method of imitation learning when one has access to the environment and to the expert itself during training. We run the DAgger algorithm to imitate an expert within the PyUXV environment, also used in [13]. In this environment, the agent must navigate around obstacles to reach a goal. Here, we imitate the commands needed to avoid the obstacles.

With 10 runs in each condition, we find that the growing network trains faster than the large and small fixed networks Figure 5. Also, the growing network achieves a similar score to the large network, which is above the score of the small network.

We use Mujoco as a baseline for testing the adaptive networks performance in behavior cloning. We consider two environments: Ant and Half Cheetah, and perform 10 iterations for each conditions in the two environments. We train on 10 expert trajectories and then validate against 10 unseen trajectories. The expert trajectories were generated using [14]. We do not use dropout in these experiments as we found that dropout reduced the performance of the networks. Instead, we prevent runaway growth by preventing a network from growing again until it achieves its MSE improvement threshold.

In both Ant and Half Cheetah, the MSE of the growing network jumps at certain moments during training. These jumps occur right after the network grows as the evaluation occurs before the network's new, randomly initialized weights have been trained.

For the Ant environment, the growing network provides gains in MSE to the small, fixed network and a similar MSE to the large, growing network (Figure 6). The three networks attain a similar score in the environment, but the large-growing error has less variance in the score.

In the Half Cheetah environment, the network on average grows to be larger than the large, fixed network. However, before reaching the larger size, the growing network achieves a similar MSE to the larger network (ignoring the steps in which one of the network grows and spikes the MSE). The imitators with growing network appears to achieve an improved MSE to the large, fixed

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"

Figure 5: PyUXV with DAgger
network (Figure 7). Also, imitators with small, growing network achieve the highest average environmental rewards.

## 5 Adaptive Networks in Reinforcement Learning

We apply the same adaptive-network technique to the value function within the reinforcement-learning algorithm PPO ([15]). We grow the size of the value-function network if its fit can be improved by the addition of the residual network. In all the experimental conditions, the policy network is fixed to have two hidden layers that are each 64 nodes in width while the value function has two hidden layers with varying widths. We do not use dropout in these experiments, and without dropout, the networks can experience continuing growth, even for large networks.

We train using PPO for the varying value networks in both the Mujoco Ant and Half Cheetah Environment. We trained five runs for each condition in each environment. In the Ant environment, we see that the growing network performs similarly to the large network (Fig 8). However, the PPO runs with a smaller value network outperforms the runs with both the larger and growing value networks. In the Half Cheetah environment, the PPO runs with the growing network begin by performing similarly to the small network, but as the value

Figure 6: Behavior Cloning on Ant

Figure 7: Behavior Cloning on Half Cheetah
network grows, the score for these runs begin to approach the score of the PPO runs with the large value network (Fig 9).

It appears that the PPO runs with growing value networks can perform similarly to the PPO runs with larger networks, but may take more time reach a similar proficiency. More work is required to further explore the effectiveness of these growing value networks and to reduce the unnecessary growing of these networks.

## 6 Conclusion

Here we studied the technique of fitting a small neural network to the residuals of another neural network and combining those networks if the residual network finds significant, predictable error in the base network's fit. Using test cases from classification, imitation learning, and reinforcement learning, we find that this technique can produce effective networks without having preexisting knowledge of the problem's complexity.

In many cases this method of fitting residuals can achieve evaluation losses

NAVAIR Public Release 2022-360. Distribution Statement A - "Approved for public release; distribution is unlimited"

Figure 8: Reinforcement Learning on Ant

Figure 9: Reinforcement Learning on Cheetah
that are similar to much larger multi-layer perceptrons for several types of problems. In fitting CIFAR data, we find that the networks would grow to different sizes for different problems, which may reflect the available information in the histogram data. In imitation learning, we find that the adaptive networks used for behavioral cloning and within the DAgger algorithm can achieve similar effectiveness to networks of fixed size that began with much wider hidden layers. The reinforcement-learning runs using an adaptive value networks appear to train more slowly that the larger, fixed networks, but can also achieve similar results.

Future work will focus on improving the initialization of new weights during the network combination process using methods like [8]. We would also like to implement growth with varying network depth like in AdaNet ([11]).

## Acknowledgement

This research is in part funded by the Test Resource Management Center (TRMC) and Test Evaluation/Science & Technology (T&E/S&T) Program under contract W900KK-19-C-004.

Any opinions, findings and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the Test Resource Management Center (TRMC) and Test Evaluation/Science & Technology (T&E/S&T) Program.

Distribution Statement A - Approved for public release.
