# An Interpretable Deep Learning Method for Identifying Extreme Events under Faulty Data Interference
## 2 Methods
### Grad-CAM  
Gradient-weighted Class Activation Mapping (Grad-CAM) is a CNN-based technique that generates visual explanations for decisions [24]. It reflects the deep model's interest region using back propagation gradient information from the neural network's feature maps, and the interest region is represented by a heat map.  
Note that Grad-CAM is a modified form of the Class Activation Mapping (CAM) algorithm. The CAM algorithm replaces the fully connected layer in CNNs with the global average pooling layer (GAP) to generate interpretable output [41]. The GAP computes the average value of each feature map in the last convolutional layer of the CNN, with each value representing the importance of the corresponding feature map to the predicted class, denoted by \(\omega_{k}^{c}\), where \(k\) is the feature map number for a target class \(c\). Next, the feature layers are weighted by their corresponding importance weight \(\omega_{k}^{c}\), and then stacked altogether to form a matrix. This matrix is then up-sampled to the size of the input image to generate the class activation map. The mathematical representation of CAM is as follows:  
\[S_{c}=\sum_{x,y}\sum_{k}\omega_{k}^{c}f_{k}(x,y) \tag{1}\]  
where, \(f_{k}(x,y)\) denotes the activation of feature layer \(k\) in a certain layer of the CNN at a spatial location \((x,y)\), and \(\omega_{k}^{c}\) denotes the weight related to the class \(c\) for the feature map \(k\).  
Although the CAM algorithm can demonstrate the interest region of the deep model's decision, it has to replace the fully connected layer with a GAP layer, which alters the network's structure and may decrease its performance. Furthermore, it is necessary to retrain the network, which is time-consuming. In this regard, [PERSON] et al. [24] proposed the Grad-CAM method. Grad-CAM directly uses the gradient information as important weights to generate the activation map without any change or modification for the network structure. Therefore, Grad-CAM achieves better universality and convenience compared with CAM. The workflow of the Grad-CAM algorithm is shown in Figure 4.  
It is suggested that feature maps maintain the class-specific information in the image, and the feature maps of deeper convolutional layers preserve richer semantic information but a lower degree of granularity [24]. Figure 4 illustrates that the \(k\)th feature map, denoted as \(A^{k}\), of a convolutional layer contains semantic information relevant to the object of interest. This information is propagated to the Softmax layer to predict the object category. Then, the gradient of the probability for class c is computed, denoted as \(A^{\prime k}\), and the element \(\alpha_{ij}\) in row \(i\) and column \(j\) of the matrix \(A^{\prime k}\) can be computed as follows:  
\[\alpha_{ij}=\frac{\partial y\zeta}{\partial A_{ij}^{k}} \tag{2}\]  
Figure 4: Flowchart of Gradient-weighted Class Activation Mapping.  
where, \(A^{\prime}{}^{k}\) represents the contribution of each element in \(A^{k}\) to the category \(y^{\prime}\), so its mean value \(\alpha_{k}^{c}\) for the elements of \(A^{\prime}{}^{k}\) can reflect the importance of \(k\)th feature map \(A^{k}\), as shown in Equation (3). Grad-CAM is subsequently obtained by summing the weighted feature layers, and then passing through the ReLU layer. The mathematical representation is in Equation (4).  
\[\alpha_{k}^{c}=\frac{1}{Z}\sum_{i}^{I}\sum_{j}^{J}\alpha_{ij} \tag{3}\]  
\[L_{Grad-CAM}^{c}=\text{ReLU}\left(\sum_{k}\alpha_{k}^{c}A^{k}\right) \tag{4}\]  
where, \(Z\) denotes the total number of elements in a feature map, i.e., \(Z=I\times J\). In this paper, the Grad-CAM algorithm is embedded into the ResNet34 for interpretable event and anomaly detection. The interest regions extracted by convolutional layers from shallow to deep can be used to investigate the inner mechanisms of deep models.