# Research on Offshore Vessel Trajectory Prediction Based on PSO-CNN-RGRU-Attention
## 3 Methods  
### Data Selection and Preprocessing  
The experimental data in this paper comes from the Bohai Strait in China, collected on 4 August 2022. The longitude range was from 37\({}^{\circ}\)52\({}^{\prime}\)48\({}^{\prime\prime}\) to 38\({}^{\circ}\)52\({}^{\prime}\)48\({}^{\prime\prime}\), and the latitude range was from 120\({}^{\circ}\)0\({}^{\prime}\)0\({}^{\prime\prime}\) to 122\({}^{\circ}\)0\({}^{\prime}\)0\({}^{\prime\prime}\). This area is a vital shipping region in China, and studying ship trajectories in this region holds significant importance for ensuring navigation safety and related matters. The data parsed from the original AIS messages often contain errors, making it impossible to use the raw AIS data directly. Forcing the use of the original AIS data would result in experimental outcomes that do not align with actual conditions. The AIS data used in this paper includes six pieces of information: the Maritime Mobile Service Identity (MMSI) of the vessel, the time the AIS message was sent, the vessel's longitude information, the vessel's latitude information, the vessel's speed over ground, and the vessel's heading information. Following the IEC61162-1 [24] international standard, the AIS data was processed, and the AIS data preprocessing module consisted of the following four steps:  
Step 1: Anomaly Detection. Data anomalies include the following obvious errors: deletion of data containing empty values, MMSI call signs that are not nine digits long or contain non-numeric information, vessel speed over ground (SOG) set within the range of 0 to 51.2 knots, and course over ground (COG) values ranging from 0 to 360 degrees. Step 2: Docking Point Detection. For ships that remain docked for an extended period, the latitude and longitude information contained in their Automatic Identification System (AIS) data is of no practical significance for trajectory prediction and may interfere with the training of the neural network. Therefore, this paper conducted a detection of the speed  
Figure 5: Model Structure of PSO-CNN-RGRU-Attention. information transmitted by the ships. The judgment criterion in this paper was that if five consecutive speed values were all zero, the ship was considered to be in a docked state at this time, and the data points corresponding to these five speed values were deleted from the dataset. Step 3: Trajectory Segmentation. Over a longer period, the same vessel may travel back and forth between two locations. If the vessel's trajectory is plotted based on time order, a phenomenon known as trajectory drift may occur. To avoid this issue, trajectory segmentation is necessary. This paper determined whether to segment the trajectory by detecting the time interval between two consecutive AIS data points. If the time interval between the two data points exceeded 10 min, this served as a breakpoint for segmentation. Step 4: Missing Data Imputation. The cubic spline interpolation method is not only simple to compute, but also has relatively relaxed constraints and high interpolation accuracy. As elaborated, this paper utilized cubic spline interpolation [25] to fill in the missing trajectory points of the already segmented trajectories. Raw data that has not been processed typically has different magnitudes, and significant differences in magnitude between the data can lead to prediction errors in the network. To address this issue, we normalized the input data to restrict the processed data within the range of 0 to 1. In this paper, we adopted the min-max normalization method for normalizing the training data, defined as follows:  
\[Y=\frac{(X-\text{min})}{(\text{max}-\text{min})} \tag{10}\]  
In Equation (10), max represents the maximum value in the training samples; min represents the minimum value in the training samples; \(X\) denotes the original data; and \(Y\) signifies the normalized data. In this paper, the AIS data extraction interval was set to 1 min, and the continuous trajectory points of vessels with the same MMSI represented the vessel's navigation trajectory.