Topological Understanding of Neural Networks, a survey
We look at the internal structure of neural networks which is usually treated
as a black box. The easiest and the most comprehensible thing to do is to look
at a binary classification and try to understand the approach a neural network
takes. We review the significance of different activation functions, types of
network architectures associated to them, and some empirical data. We find some
interesting observations and a possibility to build upon the ideas to verify
the process for real datasets. We suggest some possible experiments to look
forward to in three different directions.
Tushar Pandey
# Topological understanding of Neural Networks

###### Abstract

In this review paper, we look at the internal structure of neural networks which is usually treated as a black box. The easiest and most comprehensible thing to do is to look at a binary classification and try to understand the approach a neural network takes. We review the significance of different activation functions, types of network architectures associated to them, and some empirical data. At the end, we conclude with describing some possible choices of activation functions for different problems and techniques.

## I Introduction

One of the prominent questions in deep learning is understanding what happens inside the black box, i.e. the hidden layers. The theme of the paper is to understand what happens to the data when it goes through different layer. There are some other approaches taken, one where each data point is looked at after every layer, usually images. The second one is to understand the boundary manifold and how that changes in the hidden layer. Even though these methods are important, we believe it's more important to look at the transformation of the entire data set as it goes through the hidden layers, and see the representation of the data space in the final layer.

We begin the paper by looking at some smooth activation functions, where width plays an important role. We provide some intuition behind selecting neural networks with different architectures. We point out some possible errors in considering such methods and the time complexity that comes with it.

In the third section, we look at a comparison between smooth and non-smooth activation functions, along with changing width and depth of the network. We try to answer a widely asked question, what makes ReLU better than other activation functions in practice? [1], [2], [3] We begin with a simulated dataset, where the topology is known, in order to understand the changes that could take place in an actual manifold. Under different conditions, these changes are measured. Once there is an idea of the change, it is verified on real world data in high dimensions. Due to computational power constraints, some parameters of the architecture are not adjusted from the simulated data to real world data with a large difference in dimensions.

After reviewing these methods, we draw some conclusions from both the approaches and provide with experiments to extend the results to different architectures in order to improve the understanding of the black box.

For most of the paper, we will consider the case where the data has two classes. All the definitions are provided at the end of the paper in Appendix.

## II Smooth activation functions and change in topology

In this section, we look at the change in topology when the activation function is smooth. This section is based on the work of [4]

Consider an architecture where there is no hidden layer. Let's assume the data forms two lines as described in fig 1.

Figure 1: No hidden Layer
Since there is no hidden layer, the output layer is a linear function, therefore the neural network tries to classify the data by separating it through a straight line (or a hyperplane in case of higher dimensions). In this example, it can not properly classify the data set as no straight line can possibly distinguish the two classes completely. Note that there is no activation function involved so far.

Now consider the case with one hidden layer. We look at the \(tanh\) function and see the boundary line between the two classes of data in fig 2.

This separation is seen in the actual data space, by which we mean the original way the data is represented. However, internally, the network doesn't try to change the boundary shape from a line to a curve, rather, it changes the shape of the data and then fits a linear separating boundary. More precisely, the ambient space of the data changes after applying the activation functions and therefore it's easier for the neural network to construct a linear boundary. An example of the same is demonstrated in fig 3.

For a smooth activation functions, this change in the data space is a homeomorphism. A natural question that arises: _"Is one hidden layer enough to change the data space (manifold) in order to separate two classes via a linear boundary for smooth activation functions?"_

Answer: No. In fact, depth is not sufficient to decide whether or not two data sets are separable. The depth of the network corresponds to the number of transformations. Since the functions are homeomorphisms, they can't change some topological properties of the space. One such property of a space is the homology (or the Betti numbers). Back to neural networks; if one has an annulus as one class of data points and in the hole, there is a cluster corresponding to a different class, no homoemorphism in \(\mathbb{R}^{2}\) can distinguish between these classes for a smooth activation neural network. Since it's a homeomorphism, \(\beta_{1}\) will remain 1, which means, no linear boundary can separate the two classes completely.

Question: _How about changing the width?_

Answer: yes! It will work. Width corresponds to an embedding in a higher dimensional space, where one can lift up the class inside the hole and by a hyperplane, separate them. This means, if we know the minimum dimension of the ambient space where the data can be embedded properly, we can use a neural network to completely classify the dataset.

**Theorem II.1**.: _For the data space described above, any neural network with a smooth activation function, width 1 or 2 is not enough to completely classify the two data classes regardless of the depth._

Proof.: For a smooth activation function, hidden layer corresponds to a homeomorphism, which means \(\beta_{1}=1\) after all the hidden layers. The last layer is a linear transformation, therefore conserves \(\beta_{1}\) as well. In order to divide the space by a linear boundary, \(\beta_{1}\) needs to be 0. Therefore, a contradiction. 

Note that this was true only because of the smoothness of the activation function. Which means, if the activation function is not smooth (e.g. ReLU), the Neural network can form a linear boundary to distinguish the two classes.

Figure 3: The data space is transformed and the final boundary (in green) is linear.

Figure 2: ”tanh” activation function with one hidden layer. The green line is the boundary
For a dataset with n dimensional points, they can be embedded in ambient space of dimension 2n+2, such that a linear (hyperplane) boundary can separate them. Therefore, if the hidden layer has width \(\geq 2n+2\), then the data can be separated.

**Theorem II.2**.: _[_4_]_ _There is an ambient isotopy between the input and a network layer's representation if: a) W isn't singular, b) we are willing to permute the neurons in the hidden layer, and c) there is more than 1 hidden unit._

So far, we have a way to find a nice boundary to potentially get 100% accuracy on the training data. This however, does not mean it's the actual separation. The author [4] also suggests that based on some empirical results, changing the last layer from softmax to KNN, the accuracy increases. This approach concludes that for smooth activation, the width needs to be wide enough and there is a need of sufficient (but small) depth in order to not force the network to get stuck at a local minima.

## III Smooth vs non-smooth activation functions

We follow [5] for most of the section. Once again, the data is divided into two classes \(M=M_{a}\cup M_{b}\). The first conclusion of this section describes ReLU outperforming smooth activation function, namely tanh, and the second one is describing the depth instead of the fact that shallow networks can approximate most functions pretty well. [5] have performed the analysis on real and simulated data to conclude such observations. The topological work is done through TDA, based on the idea of persistent homology originally inspired by [6; 7; 8]

The interesting aspect of this study is that instead of looking at the change in each data point, the overall change in the data shape is observed, which provides a better insight. The focus of the study is to look at the change in Betti numbers and how it is affected in the training.

In fig 4, the actual network changes the shape of the data like demonstrated. In order to unlink the components, it has to break the topology, and change the betti numbers. Generally speaking, for binary classification problems, the idea is to decrease the betti numbers, s.t. \(\beta_{1}(M_{a})=0=\beta_{1}(M_{b})\) and \(\beta_{2}(M_{a})=0=\beta_{2}(M_{b})\), whereas \(\beta_{0}(M_{a})=1=\beta_{0}(M_{b})\). Note that the last condition is not very strict. Even if \(\beta_{0}(M_{a})>1\) while other \(\beta_{j}(M_{a})=0\) for \(j\geq 1\), it's still a good enough classification. In fact, if \(\beta_{0}>1\), the suggests possibility of another class (or subclass), providing more insights about the data.

Out of some of the obstructions this hypothesis possesses, one of them is that the data usually doesn't come in such nice form. The data will more likely be in a point cloud form with some noise. But, that's where persistent homology comes into picture. Presence of small noise does not change the effective \(\beta_{j}\) for the point cloud data. If the data does come from some sampling of a manifold structure, then persistent homology recovers the \(\beta_{j}\) almost precisely. The authors of the paper have not only looked at the topological changes for simulated data, but also for real world data including images.

Some important questions which will be answered here are:

1) Why does ReLU perform better than others empirically?

2) Are these topological changes observed through this method robust?

3) Why do deep neural network work better than shallow ones even after the approximation theorems?
### Topology

We try to look into topological complexity of the manifold and the generalization gap of the dataset which measures the difference in test and training accuracy of the model. The Generalization gap is defined as

\[GG(X_{train},X_{test},m)=Acc(X_{train},m)-Acc(X_{test},m)\]

where m is the model.

For piece wise linear function the upper bound for topological complexity is given in terms of linear regions. However, the number of linear regions determined through the training set is not stable under small perturbations [9]. Instead of looking at the decision boundary at different stages, the data space transformations are the object of interest here. In order to understand the transformations, one can look at the change in Betti numbers. Furthermore, instead of looking at the Betti number of the entire Manifold, it's sufficient to look at the Betti number progression of each component. In practice, it's usually difficult to compute the homology for a point cloud.

The standard practices in Topological Data Analysis (TDA) is i) Discard outliers, noise ii) Construct \(\epsilon-\)Vietoris-Rips complex iii) Simplify VR Complex without changing the topology. The topological structure can be altered by i) and ii) based on choices of noise reduction/smoothing and \(\epsilon\) value in VR complex.

### Setup

1. The problem assumed is a binary classification problem, \(M=M_{a}\cup M_{b}\) with an additional assumption, \(\inf\{||x-y||:x\in M_{a},y\in M_{b}\}>0\).
2. For the simulated dataset, we know the manifold, so to generate the point cloud a large sample is selected uniformly and densely. The neural network chosen in feed forward, with depth l.
3. The network function is \(v:s\circ f_{l}\circ\cdots\circ f_{1}:\mathbb{R}\rightarrow[0,1]\).s is the score function, \(s:\mathbb{R}^{n_{l+1}}\rightarrow[0,1]\).
4. Let \(n_{j}\) denote the width of the layer j. We let \(n_{1}=d,n_{l+1}=p\) and \(v_{j}:f_{j}\circ\cdots\circ f_{1}\).
5. The simulated data is non-realistic with complicated topology in low-dimension. Real world data is in high dimensions but most likely simpler in terms of entangled classes. For the simulated data we look at large \(\beta_{0}\), non-zero \(\beta_{j}\) for \(j\geq 1\) and large Topological complexity.
6. The model is trained to near-zero generalization error.

Spoiler alert: with sufficient depth, the last layer maps \(v(T_{a}),v(T_{b})\) on the opposite ends of \([0,1]\). There are some challenges moving from simulated to real data. The topology is not known so the persistent homology is harder to compute at each layer.

The work is done on three different dataset which can be seen in the following figure [5]. The red part of the data is \(M_{b}\) and the green part is \(M_{a}\).
### Training

1. Different activation functions: tanh, ReLU, leaky ReLU
2. Different depth from 4-10
3. Different width between 6-50
4. Criss entropy categorical loss
5. ADAM with 18000 epoch
6. \(\eta=0.02-0.04\) with exponential decay \(\eta^{t/d}\), \(d=2500\) and t is the epoch.
7. For bottleneck architecture (narrow width in middle), d = 4000, \(\eta=0.5\)
8. Score = softmax function
9. Metric \(\delta_{k}\) for \(VR_{\epsilon}\) Complex is the graph geodesic distance on K-nearest neighbours. \(\delta_{k}(x_{i},x_{j})=\) minimum no. of edges between them in knn graph. It preserves connectivity and normalizes distance.
10. Two hyperparameters, \(k\) and \(\epsilon\). The persistant homology is used through filtered complex w.r.t. \(\delta_{k}\) at \(\epsilon\). Find \(k^{*}\) with \(\epsilon=1\) first by \(\beta_{0}(VR_{k^{*}})=\beta_{0}(M)\). Then find \(\epsilon^{*}\) by equating \(\beta_{1}\) and \(\beta_{2}\).

### Results

1. Clear decay in \(\beta_{0}\) across all possible neural network architectures. It's slower in tanh, faster in Leaky ReLU and fastest in ReLU.
2. Width: * Narrow: 6 neurons each layer, changes topology faster * Bottleneck: one of the middle layer has 3 neurons while other have 15, sudden change in topology at bottleneck. * Wider: 50 neurons each, smoother reduction in topological complexity.
3. depth: * For highly entangled classes, more depth required for 100% accuracy. Low depth makes it difficult to get the accuracy we want * Faster reduction in Topological complexity in the final layers. * Sometimes, there's non-required simplification for deeper neural networks.
4. For wide enough layers, \(\beta_{1}(M)=0\) and \(\beta_{2}(M)=0\) is not required. Shallow networks sometimes forces this but deeper ones don't, therefore preserving more structure.

### Graphical Results

### Real Dataset

These properties were verified for MNIST, HTRU2, UCI Banknotes and UCI sensorless drive datasets. Since the dimension of these datasets are high, the persistent homology can not be performed as efficiently and needs to be performed on every layer. The generalization gap is relaxed, from \(2-5\%\). The width and depth of the networks are fixed.

MNIST: \(\mathbb{R}^{784}\), for this dataset, the topological observations are made on top 50 principal components, HTRU2 Dataset: \(\mathbb{R}^{8}\), UCI Banknotes: \(\mathbb{R}^{4}\), UCI drive: \(\mathbb{R}^{49}\)

The table of results are available in the appendix. The observation as expected were:

1. The topological complexity is reduced overall. The network tries to reduce \(\beta_{0}\) to 1 and other \(\beta_{j}\) to 0.
2. Smooth activation function reduces the topological complexity slower than non-smooth ones with ReLU performing the most simplification.
3. ReLU adds a folding to the data space but not entirely. This is immediate from the definition of ReLU or the absolute value function.
4. More layers makes it easier to train the model by "taking it's time simplifying the space step by step".

## IV Future work

While the possibility of research in this direction is never ending, some possible options for near term research experiments are:

### Different activation functions in different layers

For training a model on multiple data sets or for training a dataset with composite architectures, setting the activation function for the initial layers as a smooth one, and applying ReLU or Leaky ReLU at the end could better transform the data. The idea behind this is that smooth activation function preserves the structure in the same dimension, but embedding it in higher dimension would reduce some complexity with some structures still being preserved.

Figure 6: [5] Average change in \(\beta_{0}\) for different activation functions for Dataset I. The dark line is the average whereas the shaded regions are results of multiple simulations.

Figure 7: [5] Change in \(\beta_{0}\) and \(\beta_{1}\) for Dataset II for different activation functions.
### Relationship between time complexity and robustness against noise

There are some results about different linear folding because of ReLU which are not stable under noise. There seems to be a trade-off between oversimplification and time. It'll be interesting to relate the stability of folding under a network architecture with non-ReLU activation functions in some layers as well.

Figure 8: [5] Change in \(\beta_{0}\) and \(\beta_{2}\) for Dataset III for different activation functions.

Figure 9: [5] Topological complexity for varying network depth for all three datasets.
### Different neural network architectures

Different architectures for the same dataset, e.g. CNN, simple feed forward network and ResNet should be compared in terms of changes in topological complexity.
