## 3 Methodology
### Data Processing
#### 3.2.5 Dataset Construction  
After the above data processing, the time intervals between each trajectory point are equal. When constructing the dataset, it is necessary to compute the relative values \(\{lon_{i},lat_{i}\}\) of the longitude and latitude of each trajectory point with respect to the previous trajectory point \(\{\Delta lon_{i},\Delta lat_{i}\}\). The differential values of longitude and latitude, along with the current true heading and ground speed, constitute the features of the current trajectory point. In the trajectory prediction model of this paper, since the time intervals between the points in the trajectory sequence are equal, the input sequence omits the time dimension. The input data have 4 dimensions, namely the true heading angle, ground speed, relative longitude, and relative latitude. The output sequence data have 2 dimensions, namely relative longitude and relative latitude. There is the input sequence point \(x_{i}^{j}\in\mathbb{R}^{N_{\text{D4}}}\), as shown in mathematical expression (17). \[x_{i}^{j}=\left\{cg_{i^{\prime}}^{j},sog_{i^{\prime}}^{j},\Delta ion_{i^{ \prime}}^{j},\Delta lat_{i}^{j}\right\} \tag{17}\]  
The predicted trajectory sequence consists of differential values of longitude and latitude, with the output sequence point \(y_{i}^{j}\in\mathbb{R}^{N_{\text{D2}}}\), as shown in mathematical expression (18). \[y_{i}^{j}=\left\{\Delta ion_{i^{\prime}}^{j},\Delta lat_{i}^{j}\right\} \tag{18}\]  
At the same time, it is necessary to record the reference point used for absolute value calculation, which is the longitude and latitude coordinates of the last point in the input sequence, as shown in Formula (19), and \(n\) presents the final position of history trajectory. \[Z^{j}=\left\{lon_{n}^{j},lat_{n}^{j}\right\} \tag{19}\]  
Combining \(X^{j}\), \(Y^{j}\), and \(Z^{j}\) forms one input-output sequence pair \(D^{j}\), as shown in Formulas (20)-(22). \[X^{j} =\left\{x_{1}^{j},x_{2}^{j},x_{3}^{j}\ldots x_{n}^{j}\right\} \tag{20}\] \[Y^{j} =\left\{y_{1}^{j},y_{2}^{j},y_{3}^{j}\ldots y_{m}^{j}\right\}\] (21) \[D^{j} =\left\{X^{j},Y^{j},Z^{j}\right\} \tag{22}\]  
The above is the specific method for processing ship trajectories, which includes the data processing flow and algorithm pseudo-code as shown in Algorithm 1. The purpose of this trajectory prediction data processing algorithm is to preprocess the original AIS ship data and construct a dataset, as well as to form an input structure suitable for ship trajectory prediction models. ```
1:Input:\(init\_ais\): represents the original input AIS data. \(l_{min}\): Represents the min length of trajectory. \(T_{interp}\): Represents the interpolation time interval. \(T_{samp}\): Represents the resample time interval. \(H\): Represents the input sequence length. \(P\): Represents the output sequence length. Output: Trajectory prediction dataset \(TD\). Initialization:\(MMSI\_Traj\): Used to store the trajectory of each unique MMSI. \(All\_Traj\): Used to store ship trajectories during the processing. Function:\(Repair(\cdot)\): Used to store ship trajectories during the processing. Process: //Step 1 Trajectory segmentation, removal of outliers and redundant points, patching of missing points, and equidistant time interval resampling.