Track anomaly detection method based on structure enhancement and comparison pre-training
By constructing a structure-semantic contrast pre-training model, GPS trajectories are converted into structured sequences and pre-trained for contrast, which solves the problems of insufficient utilization of structural information and poor cross-regional generalization in existing trajectory anomaly detection methods, and achieves high-precision and interpretable trajectory anomaly detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-09
- Publication Date
- 2026-04-07
AI Technical Summary
Existing trajectory anomaly detection methods suffer from insufficient structural information, weak modal alignment capabilities, poor cross-regional generalization, and insufficient model interpretability, resulting in inadequate detection accuracy and generalization ability.
By converting GPS trajectories into segmented sequences that explicitly contain road structure information, a structure-semantic contrast pre-trained model is constructed. The structure vector is then used to assist the large language model in trajectory anomaly detection, outputting trajectory behavior categories and key evidence fragments.
It significantly improves the model's ability to perceive path structure, achieves structure-semantic alignment, enhances cross-regional adaptability, and provides interpretable anomaly detection results.
Smart Images

Figure CN121808640A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of intelligent transportation systems technology, and in particular relates to a trajectory anomaly detection method based on structural enhancement and contrastive pre-training. Background Technology
[0002] With the rapid development of smart cities and mobility services, massive amounts of mobile trajectory data are continuously being generated. Automatically and accurately identifying behaviors such as detours and abnormal route changes from these trajectory sequences has become a key aspect of urban supervision, platform risk control, and travel quality assessment.
[0003] Existing trajectory anomaly detection methods mainly have the following shortcomings: (1) Insufficient utilization of structural information: Traditional methods rely on shallow statistical features such as speed, distance and direction, and fail to fully integrate explicit structural information such as road topology and road segment geometric attributes, making it difficult for the model to understand the intrinsic relationship between "road structure" and "behavioral semantics", which affects the accuracy of anomaly identification.
[0004] (2) Weak modality alignment capability: Trajectory data is essentially a structured sequence containing hard constraints, while large language models are good at processing natural language. Directly converting the trajectory into a simple text description will lose structural information, and the model will find it difficult to accurately infer implicit constraints such as "whether the path is reasonable" in the semantic space. Existing methods lack effective mechanisms to bridge the semantic gap between structural modalities and text modalities.
[0005] (3) Poor cross-regional generalization: The road network morphology and road grade distribution vary significantly among different cities. When traditional models face areas not covered by training data (i.e., out-of-distribution data), their performance drops sharply, making it difficult to meet the needs of large-scale, cross-scenario trajectory anomaly detection.
[0006] (4) Insufficient model interpretability: Most black box models based on deep learning lack interpretability and cannot provide a basis for anomaly judgment, which is not conducive to decision-making and auditing in actual business.
[0007] Therefore, there is an urgent need for a new trajectory anomaly detection method that can explicitly utilize road structure, achieve structure-semantic alignment, and possess strong generalization and interpretability. Summary of the Invention
[0008] The purpose of this invention is to provide a trajectory anomaly detection method based on structural enhancement and contrastive pre-training, aiming to solve the problems mentioned in the background art.
[0009] The present invention is implemented as follows: a trajectory anomaly detection method based on structural enhancement and contrastive pre-training includes the following steps: Step 1: Constructing structured trajectory input; The GPS trajectory is converted into a segmented sequence representation that explicitly includes road structure information, and a textualized structural description suitable for large language models is constructed. Step 2: Structure-Semantic Contrast Pre-training; Construct a unified representation space between structural and semantic modalities to enable the model to understand the correspondence between structural lexical sequences and their semantic descriptions; Step 3: Structure-aware large language model reasoning; The structure-semantic alignment capability obtained from pre-training is transferred to the trajectory anomaly detection task, and the structure vector is used to assist the model in reasoning. Step 4: Output and Application of Results; Output trajectory behavior categories, key evidence fragments, and structural distribution markers for trajectory anomaly monitoring and early warning.
[0010] A further technical solution, the specific steps of step 1 are as follows: The original trajectory is cleaned to remove duplicate points, invalid points, and points with time discrepancies. The trajectory is divided into continuous road segments and matched to the corresponding road edges in the road network graph to obtain road type, length and geometric shape information; The road length is discretized on a fixed scale, and the road type is mapped to a standardized set of categories to form a sequence of structural lexical units. Transform the structural lexical sequence into a natural language description according to the template, and construct a structured Prompt.
[0011] A further technical solution, the specific steps of step 2 are as follows: Based on the road network structure, a structure vector is generated for each road segment, and a path-level structure vector is obtained by aggregation. Use a text encoder to obtain path-level semantic vectors; By sharing a projection matrix, structural vectors and semantic vectors are mapped to the same contrast space, and cross-modal alignment is performed using InfoNCE contrast loss. During the pre-training phase, the text encoder and structure embedding module are frozen, and only the projection matrix and temperature parameters are trained.
[0012] A further technical solution, the specific steps of step 3 are as follows: Input the structured Prompt into the pre-trained language model encoder to obtain the token-level hidden states; Project the path-level structure vector onto the encoder's hidden dimension to generate a structure guidance vector; Attention weights are calculated for the hidden state based on the structure-guided vector, and then weighted and fused to obtain the fused representation; A classifier is used to predict behavior categories based on the fusion representation and output key evidence fragments.
[0013] In a further technical solution, the key evidence fragments are obtained by selecting the top-k tokens with the highest attention weights and mapping them back to the corresponding structural lexical fragments.
[0014] In a further technical solution, step 4 also includes a structural distribution determination step: Calculate the similarity between the current trajectory structure vector and the nearest neighbor vector in the training set structure vector library; If the similarity is lower than a preset threshold, it is marked as a sample outside the structure distribution.
[0015] In a further technical solution, the behavior category includes at least one of normal, detour, and switching.
[0016] In a further technical solution, in step 4, the result is returned in JSON format, including trajectory ID, behavior category, confidence level, list of evidence fragments, out-of-distribution state, and structural similarity.
[0017] The present invention provides a trajectory anomaly detection method based on structure enhancement and contrastive pre-training, the beneficial effects of which are as follows: (1) Explicit enhancement of structural information: By constructing "structural lexicals", hard constraints such as road topology and geometric attributes are transformed into a form that the model can process, which significantly improves the model's ability to perceive path structure.
[0018] (2) Effective alignment of modal semantics: Through structure-semantic contrast pre-training, large language models can understand the semantics of structured sequences, bridging the gap between trajectory data and natural language, and laying the foundation for accurate reasoning.
[0019] (3) Strong generalization and interpretability: The structurally enhanced representation has cross-regional stability, and combined with the out-of-distribution identification mechanism, it significantly improves the model's adaptability to new cities and new road networks. At the same time, the generative output framework is easy to extend and can provide textual explanations of the causes of anomalies.
[0020] (4) Superior detection performance: Experiments show that the method of the present invention is significantly better than the existing mainstream methods in cross-city trajectory anomaly detection tasks, with ROC-AUC, PR-AUC and other indicators. Attached Figure Description
[0021] Figure 1 A flowchart of a trajectory anomaly detection method based on structural enhancement and contrastive pre-training provided in an embodiment of the present invention; Figure 2This is an overall architecture diagram of a trajectory anomaly detection method based on structural enhancement and contrastive pre-training, provided in an embodiment of the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0023] The specific implementation of the present invention will be described in detail below with reference to specific embodiments.
[0024] like Figure 1 and Figure 2 As shown, this is an embodiment of the present invention providing a trajectory anomaly detection method based on structural enhancement and contrastive pre-training. Step 1: Constructing structured trajectory input; GPS trajectories are converted into segmented sequence representations that explicitly include road structure information, and a textualized structural description suitable for large language models is constructed.
[0025] Step 1.1: Trajectory segmentation and road attribute matching; The system first cleans the original trajectory, removing duplicate points, invalid points, and points with temporal irregularities. The original trajectory is input as a time-ordered sequence of points, denoted as: ; in, It is an ordered sequence of GPS trajectory points. For the first The longitude of each trajectory point For the first The latitude of each trajectory point For the first The timestamps of each trajectory point.
[0026] Then, based on constraints such as the distance between adjacent points and changes in direction, the trajectory is divided into several continuous segments: ; in, This is the sequence of road segments after segmentation. For the first Each section of road, This represents the total number of road segments after segmentation. To improve the accuracy of road structure, a preloaded road network map (such as OpenStreetMap) is used, and KDTree or nearest neighbor matching algorithm is used to match each segment of the trajectory to the corresponding road edge to obtain a stable road type and road length.
[0027] Each section of road The following attribute structure is generated: ; in, This is a road segment index, with a value range of [value range missing]. arrive , For the first The road type labels matched for each road segment For the first Road grade / category code for each road segment For the first The actual length of each road segment For the first A description of the geometric shape of each road segment within the road network.
[0028] This structure transforms the trajectory from a simple sequence of points into a structured sequence with road semantics.
[0029] Step 1.2: Standardization and discretization of road structural attributes; To ensure consistency across regions, road length attributes are processed using fixed-scale processing and integer discretization. For example, road segment lengths are uniformly represented by intervals of 50 meters or 100 meters. ; in, The preset length unit is used. For the first The integer representation of the discretized length of each road segment. For the floor function, For the first The actual length of each road segment.
[0030] Road types are also mapped to a standardized set of categories, such as: highway, primary road, secondary road, and tertiary road. We obtain stable and transferable structural lexical units: ; in, For the first The structural words of each road segment For the first Standardized road type categories for each road segment.
[0031] This forms a structural lexical sequence of the path. : ; Step 1.3: Constructing the structured trajectory text (Prompt); According to a fixed template, the structural lexical sequence The information is sequentially converted into a natural language description and combined with task instructions to form the final input Prompt, for example: Path: highway≈1200m→secondary≈600m→tertiary≈300m→... Task: Determine whether this path is normal, detour or switch. Answer: This structured prompt possesses both explicit structure and parsable language model, providing the necessary input conditions for subsequent inference. It generates corresponding input text for all trajectory samples and aligns the ground truth labels (normal, detour, switch) with the structured word sequence as supervision signals, providing a unified data foundation for subsequent pre-training and fine-tuning stages.
[0032] Step 2: Structure-Semantic Contrast Pre-training; The aim is to construct a unified representation space between structural and semantic modalities, enabling models to understand the correspondence between "structural lexical sequences" and their semantic descriptions. This includes the following steps: Step 2.1: Structural Modal Embedding Construction At the road network level, edge-level or road segment-level structural representation methods are used, such as those based on Node2Vec or related structural embedding algorithms, to generate structural vectors for each road segment: ; in, For road segment vectors, Let be a real vector space. Let be the dimension of the edge-level structure vector; For each trajectory, the corresponding edge vectors are first aggregated (e.g., by average pooling or attention weighting) based on the matched road segment index sequence to obtain the path-level structure vector: ; in, This is the path-level structure vector corresponding to the trajectory. The dimension of the path-level structure vector; This vector serves as a global representation of the structural mode, used to characterize the location and shape of the path in the road topology space.
[0033] Step 2.2: Semantic modality embedding construction; To ensure that the structural modality representation and the textual modality representation reside in comparable representation spaces, this step employs contrastive learning to explicitly align the two representations. For each trajectory... The path-level structure vector is obtained from step 2.1. The path-level semantic vector is obtained by the text encoder. Make both dimensions consistent (e.g., both 768 dimensions) so that they can share projection layer alignment.
[0034] Set up a shared projection matrix Mapping the two modes to the same contrast space ( For comparison of spatial dimensions, optional ), and perform Normalization: ; in, To share the projection matrix; for Normalization operator; These represent the structural modality and the text modality in the contrast space, respectively.
[0035] The number of trajectories within a batch is set to... Construct a similarity matrix: ; in, Indicates the first The structural representation of the trajectory and the first The similarity between the text representations of the trajectories; This is a temperature coefficient used to adjust the smoothness of the similarity distribution.
[0036] Using InfoNCE contrastive loss brings cross-modal representations of the same trajectory closer together and separates representations of different trajectories: ; in, Indicates the first The representation of the trajectory from one perspective and the first The similarity score between the representations of the trajectories from another perspective (usually cosine similarity with a temperature coefficient introduced). (For scaling), it can be written as: ; For fixed anchor points In other words, To form a positive sample pair, corresponding to the molecules in ; The negative sample pairs within a batch correspond to the remaining terms in the denominator. This loss encourages cross-modal representations of the same trajectory to move closer together and widens the distance between representations of different trajectories, thereby achieving structure-semantic alignment.
[0037] Step 2.3: Compare the loss with the pre-training process; Compared to the pre-training phase, the text encoder and structure embedding generation module are frozen, and only the shared projection matrix is trained. (and optional temperature coefficient) This reduces computational overhead and ensures a stable alignment process. After training, [the following steps will be taken]. and It is stored as a runtime adapter parameter.
[0038] In the subsequent fine-tuning and inference phases, the runtime adapter parameters are directly loaded for: (1) Map the structural vector and the text vector to the same comparison space to support structural similarity calculation and out-of-distribution determination; (2) Provide a stable structural representation basis for the fusion module: The structural representation in the comparison space can be denoted as .
[0039] ; in, This represents the aligned path-level structure (comparison space representation).
[0040] Step 3: Structure-aware large language model reasoning; The goal of this step is to transfer the structure-semantic alignment capabilities obtained from pre-training to the trajectory anomaly detection task, enabling large language models to explicitly use structure vectors for reasoning while receiving structured trajectory text.
[0041] Step 3.1: Structural vector injection and joint modeling; To inject path-level structural information without altering the backbone structure of the pre-trained language model, this step employs a structure-guided attention fusion mechanism to weight and aggregate the encoder's hidden representations, resulting in a fused trajectory representation.
[0042] Specifically, the structured Prompt is denoted as Input the pre-trained language model encoder (such as T5 Encoder) to obtain a token-level hidden state sequence. ; in, The number of tokens in the input sequence. To hide the dimension.
[0043] Simultaneously, the path-level structure vector of the trajectory is obtained from step 2.1. To align with the encoder's hidden dimensions, the structure projection layer (which can be cached as a runtime adapter parameter) is set to... Mapped to : ; in, As a projection layer, it is used to project... Mapped to the encoder's hidden dimensions, The output dimension is consistent with the encoder's hidden dimension, and is used for subsequent attention weight calculation and weighted aggregation; For the projection matrix, For bias vectors, This is the structure guiding vector.
[0044] Subsequently, the structure-guided vector Hide the state of each token Calculate the relevance score and obtain the attention weights by Softmax normalization: ; in, For the first Token and Guiding Vector Unnormalized attention score Indicates the first The contribution weight of each token to trajectory discrimination; The hidden states are weighted and summed using attention weights to obtain the fused context representation vector: ; in, This is the semantic-structural representation of the fused trajectory.
[0045] Step 3.2: Anomaly Category Prediction and Evidence Output; Using a lightweight classifier Output trajectory behavior categories, category set Recorded as: ; Will The input to a multilayer perceptron classifier (MLP) yields logits for each category, which are then processed by Softmax to obtain the category probabilities. ; in, The unnormalized score output by the classifier. This represents the class probability distribution after Softmax normalization. The final output behavior category is: ; in, Indicates belonging to a category The predicted probability, This refers to the category of the output trajectory behavior.
[0046] Furthermore, to provide interpretable evidence, the contribution weights obtained in step 3.1 are used. Select the top-k tokens with the highest weights from the token sequence as key evidence fragments: ; in, For the collection of evidence, This represents the number of tokens after the structured Prompt has been segmented. The number of evidence is preset; the evidence tokens can be further mapped back to the corresponding structure tokens (e.g., fragments of "road type ≈ discrete length"), thereby outputting "key road segments / fragments that lead to the judgment result".
[0047] During the training phase, cross-entropy loss is used to supervise the classifier: ; in, For real labels, For classification cross-entropy loss, For the true category in this distribution The corresponding probability.
[0048] Step 4: Output and Application of Results; After completing structure enhancement, contrastive pre-training, and structure-aware fine-tuning recognition, two core results are output for each trajectory: trajectory behavior category and key evidence fragment. The behavior category is calculated by the classifier based on the fusion representation, and the key evidence fragment is selected by structure-guided attention weights. These results can be deployed in urban mobility service platforms or traffic monitoring systems for automated review and online anomaly monitoring of large-scale trajectories.
[0049] Step 4.1: Output the behavior category; Output trajectory behavior category prediction results: ; Furthermore, it can simultaneously output class probability vectors. and with As a confidence index, it is used for business-side threshold alarms or manual review triggers.
[0050] As an optional engineering implementation strategy, when the model prediction uncertainty is high, an "uncertainty" return mechanism can be triggered, for example: if the maximum class probability... Below the preset threshold Or the difference between the probabilities of the first two categories is less than the threshold. If so, the trajectory will be marked as "uncertain" and added to the manual review queue.
[0051] Step 4.2: Output of Evidence Fragments; To provide an interpretable basis, the contribution weights obtained in step 3.1 are used. Select the top-k tokens with the highest weights from the token sequence as key evidence fragments: ; The evidence token can be further mapped back to the corresponding structure token to indicate the range of road segments / fragments that contribute the most to the current judgment.
[0052] Step 4.3: Output of Out-of-Depth (OOD) tags; To identify out-of-structure samples, the similarity between the current trajectory structure representation and the training structure is calculated based on the training set structure vector library. If the following conditions are met, the trajectory is marked as "out of structure distribution": ; in, The threshold for determining the external structure distribution; The structure vectors in the training set structure vector library (preferably those related to the current structure vectors) The nearest neighbor vector). Let be the cosine similarity. The quantiles can be set based on the similarity distribution of the training set, for example, the values corresponding to the 10th or 5th percentile. The system can also output structural similarity values as a deviation indicator for risk assessment and monitoring alerts.
[0053] Step 4.4: Result encapsulation and interface return; The system will return information such as predicted category, confidence level, and evidence fragments in JSON or business log format, as shown in the following example: {
[0054] "trajectory_id": "T12345", "behavior": "detour", "behavior_conf": 0.92, "evidence": [ {"token": "primary≈600m", "weight": 0.21}, {"token": "secondary≈450m", "weight": 0.18} ], "ood_status": "in_domain", "struct_similarity": 0.23 } The results can be used in scenarios such as ride-hailing risk control, road analysis by urban management departments, travel quality assessment systems, and trajectory anomaly early warning systems.
[0055] In a preferred embodiment of the present invention, model training and inference are performed on a personal workstation equipped with one GPU (NVIDIA RTX4070S) and an 8-core CPU (Intel i7-6850K). The specific hardware configuration is shown in Table 1.
[0056] Table 1 Server Configuration
[0057] The system's software environment is based on the Windows 11 operating system, uses Python as the primary programming language, and employs PyCharm as the development environment. This invention utilizes the PyTorch and Transformers frameworks to implement structure enhancement, contrastive pre-training, and structure-aware T5 fine-tuning. The specific software environment is shown in Table 2.
[0058] Table 2 Software Environment
[0059] Under the aforementioned hardware and software environment, the structural reinforcement trajectory anomaly detection method provided by this invention is executed according to the following steps: 1. Initialization and Preparation: The system sets basic variables such as training parameters (batch size, epoch, learning rate, etc.), model and weight paths, and structure vector library paths, and loads the structured Prompt template.
[0060] Simultaneously load the road network graph (GraphML) and its pre-computed structural embeddings (Node2Vec / Edge2Vec), and load the alignment adapter parameters (shared projection matrix) fixed during the pre-training phase. and optional temperature coefficient ).
[0061] 2. Data Processing and Loading: The system reads the structured, enhanced trajectory JSONL file, where each trajectory contains at least: (1) Structured text Prompt (e.g., a sequence of tokens with road_type ≈ length); (2) Track category labels (normal, detour, switch); (3) Structure vector index (vec_id), used to retrieve the corresponding path-level structure representation from the structure vector library.
[0062] After loading, the following operations are performed on the data: text segmentation and tokenization, structured vector retrieval, training / validation set partitioning, and batch processing encapsulation (DataLoader) to ensure that each batch contains both text modal input and structured modal vector input.
[0063] 3. Model and training settings: The system initializes a structure-aware T5 model, including: a pre-trained language model encoder (e.g., T5 Encoder) and a structure-guided fusion module (structure projection). The aligned structural representation is mapped to the encoder's hidden dimension, and the classification head (MLP+Softmax).
[0064] The loss function is defined as the classification cross-entropy loss. It is used to supervise the three-class classification outputs of normal / detour / switch; if a joint training strategy is enabled, a contrastive loss can be added. (InfoNCE) is used to further solidify the structure – semantic alignment. The optimizer preferably uses AdamW (e.g., learning rate 1e-4).
[0065] 4. Start the training cycle (Epochs): Training iterates according to a set number of epochs. Each training round includes: structure vector retrieval and alignment, prompt encoding, structure-guided fusion, classification output, and loss calculation.
[0066] 5. Training phase (fine-tuning of structure-aware classification): After entering training mode, the model executes: (1) Structure representation alignment: The retrieved structure vectors are mapped to the contrast space through an alignment adapter to obtain the aligned structure representation. ; (2) Structure-guided fusion: through Mapping to hidden dimensions to form guiding vectors And calculate attention weights for the encoder hidden state. , to obtain fusion representation ; (3) Classification output: Input the classification header to get the class probability ; (4) Loss calculation and update: Calculate the classification cross-entropy loss. (and optional) Backpropagation updates trainable parameters (preferably only the fusion projection and classification head are updated; the encoder can be frozen or fine-tuned).
[0067] The system records the training loss for each batch and calculates the average training loss at the end of the epoch.
[0068] 6. Verification Phase (Structural + Semantic Joint Reasoning): The model is switched to eval mode, and forward propagation is performed using the validation set to obtain the trajectory category prediction results. Validation set classification loss (Cross-Entropy Loss) and structural attention weights The corresponding Top-k key tokens (optional) are used to evaluate the model's convergence and the quality of its interpretable output.
[0069] 7. Update and save: The system compares the validation metrics (e.g., validation loss or AUC) of the current epoch with the historical best values. If they are better, it saves the optimal fine-tuned model parameters (e.g., finetune_cls_best.pt) and simultaneously saves the key parameters of the fusion module (structure projection layer and classifier head weights). The system can update the learning rate according to a preset strategy (e.g., cosine or step decay).
[0070] 8. Epoch Iteration and Continued Training: If the maximum number of training epochs has not been reached, return to step 4; otherwise, end the training process and enter the inference phase.
[0071] 9. Training Completion and Experiment Comparison: After training is completed, the training log is output, and the optimal fine-tuned model, loss curve, structural representation visualization results (e.g., UMAP, optional), and a comparison report of the pre-training stage are generated (optional). To verify the effectiveness of this method, common trajectory anomaly detection models are selected as baseline methods for comparison, including IBOAT, DeepTEA, CausalTAD, and FOTraj; all baseline methods are trained and tested under the same dataset partitioning and evaluation protocol. The experimental data scale and parameter settings are shown in Table 3.
[0072] Table 3 Experimental Parameter Settings
[0073] The specific experimental results are shown in Tables 4 and 5.
[0074] Table 4 Experimental results on the Xi'an dataset
[0075] Table 5 Experimental results on the Chengdu dataset
[0076] As shown in Tables 4 and 5, under the same-city OOD setting, TAD-LLM achieved the best or tied-best detection performance on both the Xi'an and Chengdu datasets, and its performance was stable in both Detour and Switch anomaly categories. Taking ROC-AUC as an example, the ROC-AUC for Xi'an OOD & Detour improved from 0.8232 on FOTraj to 0.8479, and for Xi'an OOD & Switch from 0.8073 to 0.8550; for Chengdu OOD & Detour, it improved from 0.8214 on CausalTAD to 0.8595, and for Chengdu OOD & Switch from 0.8363 to 0.8527. A consistent trend was observed in PR-AUC: Xi'an reached 0.8397 and 0.8748 respectively, and Chengdu reached 0.8437 and 0.8661 respectively, indicating that this method maintains strong anomaly detection capabilities even under conditions of fluctuating positive and negative sample ratios and distribution shifts.
[0077] Further comparison with different baselines reveals that traditional sequence / reconstruction methods are more susceptible to sampling density, traffic fluctuations, and local noise in OOD scenarios, resulting in significant fluctuations in PR-AUC. TAD-LLM's advantages stem primarily from two aspects: First, structural channels provide relatively stable road network topology and road hierarchy cues, enabling the model to obtain transferable structural anchors even under "changes in intra-city distribution." Second, compared to pre-training, it explicitly aligns structural representations with textual representations, reducing cross-modal bias in the downstream fusion stage. This allows structure-guided attention to more reliably focus on key road segments, thereby simultaneously improving performance on both Detour and Switch anomalies.
[0078] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A trajectory anomaly detection method based on structure enhancement and contrastive pre-training, characterized in that, Includes the following steps: Step 1: Constructing structured trajectory input; The GPS trajectory is converted into a segmented sequence representation that explicitly includes road structure information, and a textualized structural description suitable for large language models is constructed. Step 2: Structure-Semantic Contrast Pre-training; Construct a unified representation space between structural and semantic modalities to enable the model to understand the correspondence between structural lexical sequences and their semantic descriptions; Step 3: Structure-aware large language model reasoning; The structure-semantic alignment capability obtained from pre-training is transferred to the trajectory anomaly detection task, and the structure vector is used to assist the model in reasoning. Step 4: Output and Application of Results; Output trajectory behavior categories, key evidence fragments, and structural distribution markers for trajectory anomaly monitoring and early warning.
2. The trajectory anomaly detection method based on structure enhancement and contrast pre-training according to claim 1, characterized in that, The specific steps of step 1 are as follows: The original trajectory is cleaned to remove duplicate points, invalid points, and points with time discrepancies. The trajectory is divided into continuous road segments and matched to the corresponding road edges in the road network graph to obtain road type, length and geometric shape information; The road length is discretized on a fixed scale, and the road type is mapped to a standardized set of categories to form a sequence of structural lexical units. Transform the structural lexical sequence into a natural language description according to the template, and construct a structured Prompt.
3. The trajectory anomaly detection method based on structure enhancement and contrastive pre-training according to claim 2, characterized in that, The specific steps of step 2 are as follows: Based on the road network structure, a structure vector is generated for each road segment, and a path-level structure vector is obtained by aggregation. Use a text encoder to obtain path-level semantic vectors; By sharing a projection matrix, structural vectors and semantic vectors are mapped to the same contrast space, and cross-modal alignment is performed using InfoNCE contrast loss. During the pre-training phase, the text encoder and structure embedding module are frozen, and only the projection matrix and temperature parameters are trained.
4. The trajectory anomaly detection method based on structure enhancement and contrastive pre-training according to claim 3, characterized in that, The specific steps of step 3 are as follows: Input the structured Prompt into the pre-trained language model encoder to obtain the token-level hidden states; Project the path-level structure vector onto the encoder's hidden dimension to generate a structure guidance vector; Attention weights are calculated for the hidden state based on the structure-guided vector, and then weighted and fused to obtain the fused representation; A classifier is used to predict behavior categories based on the fusion representation and output key evidence fragments.
5. The trajectory anomaly detection method based on structure enhancement and contrast pre-training according to claim 4, characterized in that, The key evidence fragments are obtained by selecting the top-k tokens with the highest attention weights and mapping them back to the corresponding structural lexical fragments.
6. The trajectory anomaly detection method based on structure enhancement and contrastive pre-training according to claim 1, characterized in that, Step 4 also includes a structural distribution external determination step: Calculate the similarity between the current trajectory structure vector and the nearest neighbor vector in the training set structure vector library; If the similarity is lower than a preset threshold, it is marked as a sample outside the structure distribution.
7. The trajectory anomaly detection method based on structure enhancement and contrast pre-training according to claim 1, characterized in that, The behavior categories include at least one of normal, detour, and switching.
8. The trajectory anomaly detection method based on structure enhancement and contrastive pre-training according to claim 1, characterized in that, In step 4, the results are returned in JSON format, including trajectory ID, behavior category, confidence level, list of evidence fragments, out-of-distribution state, and structural similarity.
Citation Information
Cited By
A task-adaptive trajectory representation learning method
CN122241265A