# Knowledge Distillation-Based GPS Spoofing Detection for Small UAV
## 5 Methodology
### KD-Enabled Lightweight Detection  
Due to the requirements of flexibility, UAVs usually have limited power and computation resources, which restricts them to being equipped with complex and computationally intensive algorithms. The LSTM trained for GPS spoofing detection is hard to deploy on a UAV platform. We need to tailor some features to make the LSTM compact so that the UAV can use LSTM-based detection onboard. The conventional approaches make adjustments to the architectures of the LSTM to reduce the consumption of computation and storage, which is a good method for deployment. However, the conventional approaches also lose accuracy control, which means that the performance of the algorithms will drop dramatically and cannot be controlled. This section uses knowledge distillation methods to obtain compact LSTM-based detection. We transfer performance from a teacher model (the trained LSTM), \(T(PA_{t})\), to a student model (a small NN model), \(S(PA_{t})\), with knowledge distillation.  
For the teacher model, \(T(PA_{t})\) is a complex LSTM model, as described in Section 5.1. Trained with datasets, \(T(PA_{t})\) can achieve competitive performance on position predictions. However, \(S(PA_{t})\) is lightweight, which is different from \(T(PA_{t})\). \(S(PA_{t}\) is combined with multiple 1D neural network (NN) layers, one fully connected layer, and one softmax layer. We leveraged the mean squared error (MSE) to calculate the loss of training \(S(PA_{t})\). The loss function is described as follows:  
\[\mathbb{L}=\parallel T(PA_{t})-S(PA_{t})\parallel \tag{10}\]With the configuration of the student model and teacher model, the loss paradigm of knowledge distillation can be  
\[L=\mathbb{L}_{1}(S(PA_{t}),T(PA_{t}))+\alpha\mathbb{L}_{2}(S(PA_{t}),P_{t^{\prime}}) \tag{11}\]  
Here, \(L_{1}()\) and \(L_{2}()\) are the loss functions of the student model vs. the teacher model and the student model vs. the real positions. \(\mathbb{L}_{1}=\parallel T(PA_{t})-S(PA_{t})\parallel\) and \(\mathbb{L}_{2}=\parallel P_{t}-S(PA_{t})\parallel\). \(\alpha\) are the balance factors for the loss between \(L_{1}()\) and \(L_{2}()\).  
The trained student model, \(S^{\prime}(PA_{t})\), was deployed on a compact platform to test its performance and resource consumption; then, \(S^{\prime}(PA_{t})\) was deployed in the UAV controller to detect GPS spoofing. As Algorithm 1 shows, we replaced the trained LSTM model with the student model, \(S^{\prime}(PA_{t})\). At the initial phase, we loaded the original positions, \(PA_{t0}\), and the trained weights of LSTM. When the power of the UAV was on, the algorithm ran without stopping. In the while loop, the algorithm acquired GPS data, \(P_{t}\), and acceleration data, \(A_{t}\), from the GPS module and IMU module, respectively. As the data went through the LSTM model, we could obtain \(P_{t}\). We compared the \(P_{t}\) with the updated data, \(P_{t+1}\), from the GPS module. If the difference was over the threshold, the spoofing attack was detected. As the data go in as input, the storage size and time consumption do not change, so the complexity is O(1).