## 3 Methodology
### AIS Data Pre-Processing  
The study primarily focuses on the behavioral patterns of vessels within the channel. Therefore, extracting data specific to the channel and port waters from the vast historical AIS trajectory data helps to effectively narrow down the scope of the problem. The channel and port areas are irregular polygons, and cannot directly compare AIS trajectory points with the latitude and longitude of the channel boundaries to determine whether the trajectory points are within the channel. The Ray-casting algorithm [32] is employed to extract data within these waterway boundaries. The Ray-casting algorithm operates on the principle of determining whether a given point lies inside or outside a polygon by counting the number of intersections between a ray starting from the point and the edges of the polygon. If the number of intersections is odd, the point is considered to be inside the polygon; if even, it is outside. As shown in Figure 3, the shaded area represents the port waters, which form an irregular polygon. Vessels a and c, located within the water area, emit rays in a fixed direction, with the intersection points on the port boundary being 3 and 1, respectively--both odd numbers. Vessels c and d, located outside the water area, emit rays in a fixed direction, with the intersection points on the port boundary being 0 and 2, respectively--both even numbers. Using the Ray-casting algorithm, we can obtain data within the channel boundaries and directly exclude data outside the water area from the study. Algorithm 1 describes how to determine whether an AIS trajectory point is within the Fairway. AIS trajectory data often contains noise, such as erroneous ship information or anomalous positional and speed data. The Maritime Mobile Service Identity (MMSI) is used to identify various stations and groups of calling stations. Each vessel should have a unique MMSI, which can be used as an index in the study to determine if AIS data pertains to the same vessel. However, some small vessels may have incorrectly configured MMSIs, so during data preprocessing, it is crucial to handle these issues to prevent different vessels' AIS data from being mistakenly assigned to the same vessel. The assignment of vessel radio station identifiers follows specific requirements, represented by a 9-digit ship station identifier code in the format of MMSI, Format as MIDXXXXXX. The first three digits represent the Maritime Identification Digits (MID), which can be any number from 0 to 9. The MID denotes the authority responsible for the vessel's radio station. As of 18 July 2023,there are 292 MIDs allocated to responsible authorities out of a possible 474, representing 61.60% of available combinations. A statistical analysis of the used maritime  
Figure 3: Schematic Diagram of the Ray-Casting Algorithm. a, b, c, and d represent four ships at different positions, and the numbers indicating how many times rays emanating from each ship intersect the channel boundaries. identification numbers is shown in Figure 4. Currently, there are no MIDs below 200 or above 800. Therefore, as the first step in data processing, any data that does not comply with the MMSI coding rules based on the MID range is excluded. The removal of other outliers primarily focuses on anomalies in position, speed, and draft information. Errors in position transmission can result in significant discrepancies between the positions of consecutive vessel trajectory points. By calculating the speed of the vessel based on the distance between adjacent points and the time interval, it is possible to identify abnormal position points. Such anomalies typically result in excessively high calculated speeds. The precision of the speed over ground (SOG) field in AIS data is 0.1 knots, with a representable range from 0 to 102.2 knots. When the SOG field value is 1022, it indicates that the vessel speed is 102.2 knots or higher; when the field value is 1023, it signifies that no speed information is available for that trajectory point.