# LSTM-DQN-APF Path Planning Algorithm Empowered by Twins in Complex Scenarios
## 4 Twin System Modeling and LSTM-DQN-APF Algorithm
### Algorithm Validation Test and Analysis
#### 4.3.3 Experiment 2: Verify the Accuracy of LSTM-DQN-APF Prediction  
(1) LSTM-DQN-APF  
The configuration of parameters in the LSTM-DQN-APF network has a significant impact on both prediction accuracy and speed. To optimize these parameters, this paper employs an LSTM architecture with two hidden layers, each containing 50 neurons. Additionally, the DQN component includes three fully connected hidden layers, each containing 128 neurons, which enhances the decision-making and prediction capabilities. During the training process, the learning rate is dynamically adjusted to ensure effective convergence at different stages, and a batch size of 40 is used for each training iteration. The model selects five main features: latitude, longitude, altitude, horizontal velocity, and vertical velocity, and generates time-series data for each variable. Therefore, the actual input data for each batch are represented as a three-dimensional tensor with a shape of B \(\times\) 40 \(\times\) N, where B represents the time steps and N = 5 denotes the number of features. To improve prediction accuracy, we perform a comparative analysis of the prediction errors across time steps from 5 to 50, thereby determining the optimal time step for the LSTM-DQN-APF network in quadrotor UAV trajectory prediction. To evaluate the performance of the LSTM-DQN-APF model, we use mean absolute error (MAE) as the evaluation metric. MAE quantifies the closeness between the predicted UAV trajectory points and their actual values; a lower MAE indicates that the LSTM-DQN-APF-based quadrotor UAV trajectory prediction model has higher accuracy. As can be seen from Table 2, when the step size is set to 40, the prediction errors for both flight altitude and latitude are minimized. The optimal step size for predicting longitude is 45, which yields the smallest measurement error. Therefore, the optimal step sizes for predicting the flight height of a quadrotor UAV, latitude, and longitude are 40, 40, and 45, respectively. Table 1 also indicates that as the time step length increases, the prediction accuracy improves, suggesting that LSTM-DQN-APF networks perform better with longer time-series data. However, beyond a certain step size, increasing the step size further leads to a decrease in prediction accuracy. As shown in Table 3, under the given network structure and time step conditions for the LSTM-DQN-APF model, the multi-step prediction results for the quadrotor UAV trajectory demonstrate that one-step and two-step predictions fall within an acceptable error range, while the error for three-step predictions increases significantly. \begin{table}
\begin{tabular}{c c c c} \hline
**Step Length** & **Height/m** & **Latitude/\({}^{\circ}\)** & **Longitude/\({}^{\circ}\)** \\ \hline
5 & 2.72 & 8.73 & 7.99 \\
10 & 2.90 & 9.04 & 8.52 \\
15 & 2.79 & 7.98 & 9.59 \\
20 & 2.67 & 7.28 & 7.37 \\
25 & 2.99 & 6.60 & 6.91 \\
30 & 2.88 & 6.83 & 7.01 \\
35 & 2.49 & 8.62 & 6.82 \\
40 & 2.33 & 6.45 & 7.00 \\
45 & 2.66 & 8.42 & 6.04 \\
50 & 2.50 & 7.58 & 6.61 \\ \hline \end{tabular}
\end{table} 
Table 2: Comparison of prediction errors MAE (m) of different steps. 2. verifies the prediction errors of the LSTM-DQN-APF, LSTM, BP, and CNN models along the x, y, and z axes As illustrated in Figure 7, the predictions of the four models for the three coordinate axes (x, y, z) generally follow the trend of the actual trajectory. However, the prediction curves of the BP (backpropagation algorithm) and CNN (convolutional neural network) models exhibit significant deviations from the actual trajectory. In contrast, the LSTM and LSTM-DQN-APF models demonstrate smaller prediction errors. Notably, the prediction error for the \(z\)-axis is marginally higher compared to the x and y axes across all models, with the BP and CNN models showing considerable fluctuations at various positions. Although the LSTM model's prediction error for the \(z\)-axis height remains within an acceptable range, it is still greater than that of the LSTM-DQN-APF model.