## 2 Methods
### Trajectory Clustering  
#### 2.2.1 Similarity Measure  
The determination of the similarity measure is key for the trajectory clustering effect. Two similar trajectories can be understood as the vertical distance from all points on one trajectory to the other trajectory satisfying a certain threshold, and the total length of the two trajectories is approximately equal. Armed with this idea, an improved LCSS was used for the trajectory similarity measure. The LCSS [43] distance was used to obtain the longest common sub-sequence existing in two trajectory sequences. For two point-based trajectories represented by \(A=\{a_{1},\ldots,a_{n}\}\) and \(B=\{b_{1},\ldots,b_{n}\}\), their LCSS distance was calculated as follows:  
\[L(A,B)= \begin{cases}0,&n=m=0\\ 1+L(Head(A),Head(B)),&dist\big{(}a_{i},b_{j}\big{)}\leq\varepsilon\\ max(L(Head(A),B),L(A,Head(B))),&others\end{cases}  \tag{1}\]  
where \(L(A,B)\) is the longest common sub-sequence of two trajectory segments \(A\) and \(B\), the lengths of which are \(n\) and \(m\), respectively. \(Head(A)\) and \(Head(B)\) represent the trajectory segments of \(A\) and \(B\) after removing their first track points. The value \(dist\big{(}a_{i},b_{j}\big{)}\) represents the geographical distance between track points \(a_{i}\) and \(b_{j}\), \(\varepsilon\) is the distance threshold. When the distance difference between two trajectories \(A\) and \(B\) is less than \(\varepsilon\), the pair of trajectory points are considered similar, and the value of \(L\) is increased by 1. If the number of points of trajectory \(A\) and \(B\) are both 0, then \(L(A,B)\) is 0. When the number of trajectory points is not 0, the maximum common sub-sequence can be obtained using Formula (1) recursively. The value \(\varepsilon\) determines the distance range of two trajectories to form a cluster, and its value should not be too large or too small. A large value merges different classes into one class, and a value that is too small splits the trajectories into too many fragmentary classes. Here, the value of \(\varepsilon\) according to the ship's traffic flow width was determined using the traffic flow chart. The traffic flow width was measured on a monthly traffic flow chart between 1 and 3 nm. To improve the clustering resolution, \(\varepsilon\) was set to 1 nm. \(L\) can attain the maximum number of points between two trajectories satisfying \(\varepsilon\), but the direct use of Formula (1) as the trajectory similarity measure leads to two problems (Figure 5). In the first situation, for different reasons, AIS generates a lot of debris trajectories, with differing total lengths of each trajectory. Like \(A\) and \(B\), they are just similar in the middle part. If the short trajectory is similar to many long traject  
Figure 4: GPS records and stay points. A trajectory is composed by some line segments, green arrows represent their direction, the green dots are the sample points of the trajectory. The red dots represent the identified stay points. dissimilar long trajectories gather into a cluster. In another situation, such as \(B\) and \(C\), \(C=\{c_{1},\ldots,c_{n}\}\). Because the trajectories used to cluster are simplified, the distance between two continuous sample points is greater than the original. Intuitively, the two trajectories are similar, but points on one trajectory cannot find points nearby on another trajectory. Consequently, the two trajectories cannot be clustered together. To solve these two problems, the following improved LCSS equation was given:  
\[L^{*}(A,B)=\left\{ \begin{array}{l}0,\;n=m=0\;or\;|len(A)-len(B)|<\eta max(len(A), len(B))\\ 1+L(Head(A),Head(B)),\;dist^{*}(a_{i},b_{j})\leq\varepsilon\\ max(L(Head(A),B),LCSS(A,Head(B))),\;others\end{array} \right. \tag{2}\]  
where \(len(A)\) and \(len(B)\) represent the total distance of \(A\) and \(B\), respectively. The value \(\eta\) is a coefficient between [0, 1], meaning that two similar trajectories should have an approximately equal total length.