# A Method for Processing Static Analysis Alarms Based on Deep Learning
## 3 Methodology
### Classification Algorithms
#### 3.2.3 Bidirectional Recurrent Neural Networks  
BiRNNs consist of two separate RNNs: one processes the input sequence in forward order while the other processes it in reverse order. At each time step, the outputs of the forward and backward RNNs are concatenated, resulting in a final output that represents the combined information from both directions. By processing the sequence in both directions, the model is able to capture dependencies between input features that may be missed by a unidirectional RNNs. In this study, we implemented a customized class _BiRNN_ that is the classifier inherited from _nn.Module_, and it comprises a bidirectional GRU layer and a fully connected layer for predicting alert categories. The bidirectional GRU layer contains two directions of GRU layers that process the input sequence in both forward and backward directions simultaneously, enabling the model to consider contextual information. The GRU layer utilizes gating mechanisms to regulate the flow of information within the neural network, enabling selective updates and disregarding of specific aspects of the hidden state depending on the input at each time step. Mathematically, for a given time step \(t\), suppose that the input is a minibatch \(\mathbf{X}_{t}\in\mathbb{R}^{n\times d}\) (number of examples: \(n\); number of inputs: \(d\)) and the hidden state of the previous time step is \(\mathbf{H}_{t-1}\in\mathbb{R}^{n\times h}\) (number of hidden units: \(h\)). As illustrated in Figure 5, GRU has only two gates: the reset gate \(\mathbf{R}_{t}\in\mathbb{R}^{n\times h}\), which controls whether to update using the previous hidden state \(H_{t-1}\) or the current input \(X_{t}\), and the update gate \(\mathbf{Z}_{t}\in\mathbb{R}^{n\times h}\), which determines whether to update the hidden state \(H_{t}\) (set to 1) or not (set to 0). These calculations can be represented by the following formula:  
\[\mathbf{R}_{t}=\sigma(\mathbf{X}_{t}\mathbf{W}_{xt}+\mathbf{H}_{t-1} \mathbf{W}_{hr}+\mathbf{b}_{r}),\] \[\mathbf{Z}_{t}=\sigma(\mathbf{X}_{t}\mathbf{W}_{xz}+\mathbf{H}_{t- 1}\mathbf{W}_{hz}+\mathbf{b}_{z}),\]  
where \(\mathbf{W}_{xt},\mathbf{W}_{xz}\in\mathbb{R}^{d\times h}\) and \(\mathbf{W}_{hr},\mathbf{W}_{hz}\in\mathbb{R}^{h\times h}\) are weight parameters, \(\mathbf{b}_{r},\mathbf{b}_{z}\in\mathbb{R}^{1\times h}\) are biases, and \(\sigma\) is the fully connected layer with activation function. The reset gate \(\mathbf{R}_{t}\) leads to the following _candidate hidden state_\(\mathbf{\hat{H}}_{t}\in\mathbb{R}^{n\times h}\) at time step \(t\):  
\[\mathbf{\hat{H}}_{t}=\tanh(\mathbf{X}_{t}\mathbf{W}_{xh}+(\mathbf{R}_{t}\odot \mathbf{H}_{t-1})\mathbf{W}_{hh}+\mathbf{b}_{h}),\]  
where \(\mathbf{W}_{xh}\in\mathbb{R}^{d\times h}\) and \(\mathbf{W}_{hh}\in\mathbb{R}^{h\times h}\) are weight parameters, \(\mathbf{b}_{h}\in\mathbb{R}^{1\times h}\) is the bias, and the symbol \(\odot\) is the Hadamard product operator. The update grate \(\mathbf{Z}_{t}\) determines the extent to which the new hidden state \(\mathbf{H}_{t}\in\mathbb{R}^{n\times h}\) is just the old state \(\mathbf{H}_{t-1}\) and by how much the new candidate state \(\tilde{\mathbf{H}}_{t}\) is used. This leads to the final update equation for the GRU:  
\[\mathbf{H}_{t}=\mathbf{Z}_{t}\odot\mathbf{H}_{t-1}+(1-\mathbf{Z}_{t})\odot \tilde{\mathbf{H}}_{t}.\]  
Whenever the update gate \(\mathbf{Z}_{t}\) is close to 1, we simply retain the old state. In this case, the information from \(\mathbf{X}_{t}\) is essentially ignored, effectively skipping time step \(t\) in the dependency chain. In contrast, whenever \(\mathbf{Z}_{t}\) is close to 0, the new latent state \(\mathbf{H}_{t}\) approaches the candidate latent state \(\tilde{\mathbf{H}}_{t}\). In summary, the BiRNN model receives sequences of context embeddings as input and forwards them through the bidirectional GRU layer.