# Collision Avoidance Behavior Mining Model Considering Encounter Scenarios
## 2 Methodology
### AIS Data Preprocessing  
AIS data provide a substantial amount of both static and dynamic information regarding ship trajectories. However, due to signal distortion in the transmission of AIS data and interference from various external factors, it is necessary to preprocess the data to ensure the accuracy of the model's recognition. Common anomalies in AIS data include data errors and data missing. This study performs preprocessing on the AIS data, addressing both types of anomalies. Data errors are a common issue in AIS data. These errors are typically corrected through data cleaning or anomaly detection methods. Depending on the region of the selected AIS data, the following five types of information need to be filtered. (1) The ship identification code (MMSI): the MMSI is a unique identification code used to identify ships, shipborne mobile stations, and shore stations. It is usually in a 9- or 10-digit numeric format. Any MMSI length less than 9 digits or greater than 10 digits is considered erroneous data. (2) Longitude and latitude errors: data should be filtered based on the boundary longitude  
Figure 2: The framework of collision avoidance behavior mining. and latitude range of the studied water area. Any position data falling outside of this boundary should be discarded. (3) Time errors: data outside of the predefined time range of the study should be excluded. (4) Heading errors: the valid range for ship headings is [0\({}^{\circ}\) to 360\({}^{\circ}\)]. Any data outside of this range should be excluded. (5) Speed errors: the typical speed range for ships is 0 to 40 knots. Data exceeding this range should be discarded, as shown in Equation (1). \[\left\{ \begin{array}{l}lon_{\min}<lon<lon_{\max}\\ lat_{\min}<lat<lat_{\max}\\ 0<sg<40\\ 0^{\circ}<cg<360^{\circ}\\ t_{\min}<t<t_{mat}\end{array} \right. \tag{1}\]  
Regarding the issue of data missing, due to the broadcast frequency of AIS ranging from approximately 3 to 20 s, it is essential to unify the time steps of the ship trajectory data in order to accurately identify the characteristics of collision avoidance behavior and explore the relationships between encountered ship trajectories. Cubic spline interpolation is employed by constructing a cubic polynomial function that passes through all data points while ensuring that the first and second derivatives are continuous between data points. This interpolation method aims to generate a smooth curve transitioning between data points while maintaining certain local approximation properties. Therefore, in this study, 20 s interval cubic spline interpolation is used to address both data missingness and time synchronization issues. First, the date and time of the data points for a specific vessel are converted into timestamps in seconds, and these timestamps are used to identify the exact moment when the ship's position, speed, and heading were recorded. Then, the trajectory is reconstructed by arranging these timestamps in chronological order. The feature set for the same ship (MMSI) is sorted by ascending order of time, thus organizing the ship's trajectory data accordingly. Let the time interval of the selected ship's trajectory be \(\{t_{0},t_{1},\ldots,t_{n}\}\), where the information of the i-th point in the trajectory is represented as \(P_{i_{i}}=(lon_{i_{i}},lat_{i_{i}},sg_{i_{i}},cg_{i_{i}},t_{i})\), with each element corresponding to the longitude, latitude, SOC (speed over ground), COG (course over ground), and timestamp at the i-th moment. After determining the trajectory's time interval, the spline functions \(S(t|lon)\), \(S(t|lat)\), \(S(t|cg)\), and \(S(t|sg_{i})\) are defined for longitude, latitude, COG, and SOC, respectively. Let \(y\) represent the dependent variable of the spline function.