# CAA-RF: An Anomaly Detection Algorithm for Computing Power Blockchain Networks
## 3 Network Anomaly Detection Strategy for Computing Power Blockchain Networks
The Algorithm 2 workflow is as follows:  
Input: Network Traffic Data \(D=\{X_{1}\), \(X_{2}\), \(X_{3}\), \(X_{4}\), \(\ldots\), \(X_{14}\), \(Y\}\)  
Output: Random Forest Classification Accuracy \(A_{2}\)  
Standardize features \(D\)  
Apply ADASYN oversampling to the dataset \(D\)  
**for**\(i=1\) to \(n\)**do**  
\(O\gets CAA\) (\(X_{i}\))  
\(Loss\leftarrow\) LF(\(O\), \(Y\))  
Backward  
Update \(W\)  
\(A_{1}\leftarrow\) Predict \(O\)  
\(F\gets CAA\)(\(X_{i}\))  
\(RF\) Fit(\(F\), \(Y\))  
\(A_{2}\leftarrow\) RF(\(F\))  
**End For**  
Where \(D\) denotes the input dataset, which will be specifically introduced in the experimental section; \(LF\) represents the loss function; CAA refers to the Convolutional Adaptive Attention neural network model; O indicates the prediction results of the CAA; \(X\) represents the data features; Y denotes the dataset labels; F represents the features extracted at the output of the CAA network. RF stands for random forest. \(W\) denotes the weight parameters of the CAA, and Fit represents the process of training the random forest model. \(A_{1}\) represents the accuracy of the CAA model, and \(A_{2}\) represents the accuracy of the CAA-RF model. In the first part of the model, as shown in Figure 3, we used [34] convolutional operations to extract features, setting the size of each convolutional kernel to 3, denoted as M. To prevent information loss due to multiple convolutions, we applied a padding of 1 on the edges during each convolution. The filters in the convolutional layer slide over the input data with a stride of 1, performing a dot product between the local region and the filter to perceive local features in the data, thus detecting specific patterns in the input. The number of convolutional kernels affects the result of the features captured. In the first convolution, 32 convolutional kernels were configured to enhance the model's expressive ability. After the convolution operation, the data pass through a \(ReLU\) activation function, denoted as \(\sigma\). The function of ReLU is to set all negative values to zero while retaining and amplifying positive values. This nonlinear transformation helps the model learn more complex patterns, increases network sparsity, and reduces the vanishing gradient problem, making the training process more efficient. By randomly deactivating some neurons and their connections through Dropout, the model avoids over-reliance on certain nodes, thereby enhancing robustness and generalization, and reducing the risk of overfitting. Next, the filters perform the feature extraction task again, but this time, both the second and third convolutional operations use 64 convolutional kernels to extract features, further abstracting the data into the K + 1 layer based on the previously extracted Kth-layer features. The \(ReLU\) activation function is applied again to ensure that the model can capture higher-level feature representations while maintaining its nonlinearity. Finally, another convolution operation is performed on the obtained features. This series of operations allows the model to extract multi-level information from the raw input, which is crucial for understanding complex datasets. The formula is as follows:  
\[H_{s,c,t}^{(l)}=\sigma\left(\sum\limits_{c=1}^{C_{l-1}}\sum\limits_{k=1}^{K} \left(W_{c,c,k}^{(l)}\cdot H_{i,c,t+k-[K/2]}^{(l-1)}\right)+b_{c}^{(l)}\right) \tag{1}\]  
\[H_{s,c,t}^{(l)}=\sum\limits_{k=1}^{K}\left(W_{c,c,k}^{(l)}\cdot H_{i,c,t+k-[K/2 ]}^{(l-1)}\right)+b_{c}^{(l)} \tag{2}\]  
where \(H^{(l)}\) denotes the output of the \(l\)-th convolutional layer, \(C_{l}\) represents the number of output channels in the \(l\)-th convolutional layer, \(K\) refers to the kernel size, \(W^{(l)}\) denotes the weights of the convolutional kernels in the \(l\)-th layer, \(b^{(l)}\) indicates the bias term, \(\sigma(\ \cdot\ )\) denotes the activation function, \(i\) is the sample index, \(c\) is the channel index, and \(t\) indicates the position within the feature sequence.