# Classification of Heart Sounds Using Convolutional Neural Network
## 2 Materials and Methods
### Heart Sound Classification Based on the Designed CNN
#### 2.4.2 Global Average Pooling  
Compared with the traditional CNN, in the proposed CNN model, there is a GAP layer, which was first introduced in Reference [41], rather than fully connected layers before the classification layer. The differences between the fully connected layers and the GAP layer are shown in Figure 3.  
As shown in Figure 3a, the feature points of each feature map generated by the last Conv1D layer are first flattened into a vector. Then, the vector is connected to all of the neural nodes of the fully connected layer, which produce various permutations and combinations of the feature nodes. Given \(m\) feature points and n neural nodes, the output of the fully connected layer is calculated as shown in Equation (2). There will be \(mn+n\) parameters to be trained. If we increment the parameters, the model  
Figure 2: Structure of the designed convolutional neural network (CNN) model for normal and abnormal PCG classification. Conv1D denotes a one-dimensional convolution layer. GAP denotes the global average pooling layer.  
will be prone to overfitting. On the other hand, it acts as a black hole from the fully connected layer to the classification layer.  
\[\left[\begin{array}{c}y_{1}\\ y_{2}\\ \ldots\\ y_{n}\end{array}\right]=\left[x_{1}\ x_{2}\ \cdots\ x_{m}\right]\left[\begin{array}{ c c}w_{11}\ w_{12}\ \cdots\ w_{1n}\\ w_{21}\ w_{22}\ \cdots w_{2n}\\ \ldots\\ w_{m1}\ w_{m2}\ \cdots\ w_{mn}\end{array}\right]+\left[\begin{array}{c}b_{1}\\ b_{2}\\ \ldots\\ b_{n}\end{array}\right], \tag{11}\]  
where, \(w_{ij}\) (\(i\) = 1,2,...,\(m\), \(j\) = 1,2,...,\(n\)) and \(b_{n}\) (\(n\) = 1,2,...,\(n\)) are the connected weights and bias, respectively, \(x_{n}\) is the number of feature nodes and \(y_{n}\) is the output.  
The GAP layer carries out average pooling on the global feature map, so it is able to learn global information about each feature map. Each feature map generates a feature node and all of these feature maps are mapped into an eigenvector. As shown in Figure 3b, three feature maps are obtained from the last Conv1D layer. So, we obtain an eigenvector with a size of 3 that is then fed into the classification layer with the sigmoid activation function to calculate the classification probabilities. This procedure can be defined in Equations (12) and (13).  
\[x_{i}=\frac{1}{m}\sum_{j=1}^{m}a_{ij},i=1,2,\ldots,n,\ j=1,2,\ldots,m, \tag{12}\]  
\[\mathbf{x}=[x_{1}\ x_{2}\ \cdots\ x_{n}], \tag{13}\]  
where \(a_{ij}\) is the \(j\)th feature point of the \(i\)th feature map, \(n\) and \(m\) are the number of feature maps and the size of each feature map, respectively, \(x_{i}\) denotes the global average of the \(i\)th feature map and \(\mathbf{x}\) is the eigenvector generated by the GAP layer.  
The GAP layer plays the role of a bridge between the Conv-block and a classification task without requiring extra parameters to be trained. Therefore, it regularizes the network in order to prevent overfitting. Furthermore, one of the authors of the present study has proven that the strategy of replacing the fully connected layer with a GAP layer is efficient [12]. In this study, we introduced a GAP layer into the CNN model to process medical signals.  
Figure 3: Comparison of the working principle between a fully connected layer and the global average pooling layer. “0” and “1” denote abnormal and normal heart sounds, respectively. The feature maps are generated by the convolution layers of the last Conv-block. (**a**) Description of the workflow from feature maps to the classification layer. The feature maps should first be flattened in this process. (**b**) Description of the principle of the global average pooling layer.