## 3 The Proposed SP-IoUAV Model
### Intrusion Detection System (IDS)
#### 3.3.2 Intrusion Detection Engine
t-SNE can be represented as follows:  
\[P_{ij}=\frac{\exp(-\frac{|x_{i}-x_{j}|^{2}}{2\sigma_{i}^{2}})}{\sum_{k\
eq i} \exp(-\frac{|x_{i}-x_{jk}|^{2}}{2\sigma_{i}^{2}})} \tag{14}\]  
\[Q_{ij}=\frac{(1+|y_{i}-y_{j}|^{2})^{-1}}{\sum_{k\
eq i}(1+|y_{i}-y_{k  
\(P_{ij}\) is the conditional probability that \(x_{i}\) would pick \(x_{j}\) as its neighbor, \(Q_{ij}\) is the conditional probability that \(y_{i}\) would pick \(y_{j}\) as its neighbor, and \(\text{KL}(P_{i}|Q_{i})\) is the Kullback-Leibler divergence between \(P_{i}\) and \(Q_{i}\).  
These data preprocessing steps, including normalization, feature extraction with PCA, and data transformation using t-SNE, are essential for improving the data representation and facilitating more effective anomaly detection and classification in the intrusion detection engine.  
Algorithm 5 summarizes the data preprocessing stage.  
```
Data: Collected data \(X_{\text{collected}}\) Result: Preprocessed data \(X_{\text{preprocessed}}\)
1 Data Normalization:
2 for each feature \(x\) in \(X_{\text{collected}}\)do
3 Normalize the data using Equation (9);
4
5 end for
6 END Data Normalization
7 Feature Extraction using PCA:
8 Compute the covariance matrix \(C\) of \(X_{\text{normalized}}\) using Equation (10);
9 Compute the eigenvectors and eigenvalues of Cusing Equation (11);
10 Select the top \(k\) eigenvectors with the highest eigenvalues;
11 Construct the transformation matrix \(V\) from the selected eigenvectors;
12\(X_{\text{transformed}}\gets X_{\text{normalized}}\cdot V\) ;
13 Compute the transformed data using Equation (12);
14 END Feature Extraction
15 Data Transformation using t-SNE:
16 Compute the pairwise distances between data points in \(X_{\text{transformed}}\) using Equation (13);
17 Compute the conditional probabilities \(P_{ij}\) and \(Q_{ij}\) based on the pairwise distances using Equations (14) and (15);
18 Compute the Kullback-Leibler divergence \(C\) between \(P\) and \(Q\) using Equation (16);
19 Use gradient descent to minimize \(C\) and obtain the lower-dimensional data \(X_{\text{preprocessed}}\);
20 END Data Transformation
21 Output: Preprocessed data \(X_{\text{preprocessed}}\);
```  
**Algorithm 5** Data Preprocessing Algorithm  
**Anomaly Detection and Classification:** In this stage, the preprocessed data are fed into advanced machine learning algorithms, such as the convolutional neural network-long short-term memory (CNN-LSTM) network, for anomaly detection and classification. The combination of CNN and LSTM allows the system to perform comprehensive anomaly detection and classification, enhancing the intrusion detection system's ability to effectively identify and respond to security threats in the UAV network.  
**Convolutional Neural Network (CNN):** CNN is a powerful deep learning model commonly used for image and spatial data analysis. The CNN plays a critical role in anomaly detection in the proposed intrusion detection system for UAVs by learning spatial patterns and features from preprocessed data. The CNN architecture is made up of several layers, such as convolutional layers, pooling layers, and fully connected layers.  
The convolution operation is the essential building component of a CNN. It entails applying filters (kernels) to input data in order to derive feature maps. In the output feature map, the convolution process for a specific pixel can be expressed as:  
\[y_{ij}=\sum_{m}\sum_{n}w_{mn}\cdot x_{(i+m)(j+n)} \tag{17}\]  
where \(y_{ij}\) i represents the output feature map, \(w_{mn}\) is the filter (kernel) value at position \((m,n)\), and \(x_{(i+m)(j+n)}\) represents the input data at position \((i+m,j+n)\). The activation function adds nonlinearity to the CNN, allowing it to simulate complicated data relationships. ReLU (rectified linear unit) and sigmoid are two common activation functions. The ReLU activation function is defined as follows:  
\[f(x)=\max(0,x) \tag{18}\]  
Pooling layers reduce the spatial dimensions of the feature maps, lowering computational cost and preventing overfitting.