An Unsupervised Agricultural Machinery Trajectory Classification Method and Device Based on Comparative Learning
An unsupervised agricultural machinery trajectory classification method based on deep contrastive learning utilizes asymmetric data augmentation and a hybrid encoder structure to adaptively sample hard-to-separate negative samples, solving the problem of reliance on manual annotation for agricultural machinery trajectory classification and achieving efficient and stable trajectory feature representation and classification.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- QILU UNIVERSITY OF TECHNOLOGY (SHANDONG ACADEMY OF SCIENCES)
- Filing Date
- 2026-02-24
- Publication Date
- 2026-04-21
AI Technical Summary
Existing agricultural machinery trajectory classification methods rely on manual annotation, which is costly, inefficient, and highly subjective. Furthermore, traditional contrastive learning methods cannot simultaneously extract local and global features of the trajectory, leading to a decrease in classification robustness.
An unsupervised agricultural machinery trajectory classification method based on deep contrastive learning is adopted. It utilizes asymmetric data augmentation, hierarchical temporal decoupling hybrid encoder and adaptive hard-to-separate negative sample sampling to automatically learn trajectory feature representation from unlabeled data. Feature extraction and classification are performed through spectral domain correlation modeling and dynamic memory decoupling hybrid temporal encoder.
It achieves unsupervised trajectory clustering and classification, reduces the cost of manual intervention, and improves the stability and generalization ability of the model, enabling high-precision classification and feature representation of agricultural machinery trajectories in complex operation scenarios.
Smart Images

Figure CN121723271B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of electronic digital data processing technology, specifically relating to an unsupervised agricultural machinery trajectory classification method and device based on contrastive learning. Background Technology
[0002] Agricultural machinery trajectory data is of extremely high value in the agricultural production system. It can accurately reflect the operating patterns, operational behaviors, power responses, and field environmental structure of agricultural machinery, and is an important foundation for building intelligent agricultural machinery scheduling, operation quality assessment, and agricultural machinery energy efficiency modeling. However, at present, trajectory classification still mainly relies on manual annotation, which has the following key problems:
[0003] (1) High labor costs: The amount of agricultural machinery trajectory data is huge, and the collection frequency is high and the time span is long. The cost of manually labeling each data item is extremely high.
[0004] (2) Low efficiency and poor scalability: Agricultural machinery operation scenarios are diverse, including road driving, field cultivation, rice transplanting, spraying, etc., and manual annotation is difficult to adapt to the rapidly growing scale of trajectory data;
[0005] (3) High subjectivity and heavy data noise: Different labelers may have different understandings of the same trajectory, which can easily lead to inconsistent labels and blurred decision boundaries, resulting in "garbage labels" and seriously affecting the stability of model training.
[0006] For example, Chinese patent document CN120105238A discloses a method, apparatus, electronic device, and storage medium for classifying agricultural machinery trajectory data. The method includes: preprocessing and feature transformation operations on raw agricultural machinery GNSS trajectory data to obtain continuous and uniform time-series trajectory data; the raw agricultural machinery GNSS trajectory data contains multiple discrete trajectory points, and the categories of trajectory points include field trajectories and road trajectories; constructing a trajectory classification model including a feature extraction module and a classification head, and training the trajectory classification model using the time-series trajectory data as training samples, wherein the feature extraction module is trained using contrastive learning, and the classification head is trained using cross-entropy loss; deploying the trained trajectory classification model and using it to classify the agricultural machinery trajectory data. However, this method requires manual labeling of the trajectories, which is time-consuming, labor-intensive, increases costs, and has a high error rate.
[0007] To address the aforementioned issues, researchers have conducted studies on agricultural machinery trajectory classification technology based on contrastive learning. For example, Chinese patent document CN119046759A discloses an agricultural machinery trajectory classification method, a computer-readable storage medium, and a computer program product based on trajectory similarity measurement. This method cleans agricultural machinery GNSS trajectory data and then uses the contrastive learning model TrajCL to simultaneously extract structural and spatial features of the trajectory and trajectory points from the original trajectory data, calculates the trajectory embedding vector, and combines this with sliding window technology to achieve accurate field-road classification. However, the extracted spatial features are limited to the length of a single sliding window, resulting in a limited receptive field and an inability to simultaneously extract both local and global trajectory features. This reduces the robustness of classification in complex operational scenarios and is detrimental to classification.
[0008] Based on this, this invention proposes an unsupervised agricultural machinery trajectory classification method and device based on deep contrastive learning. This method eliminates the reliance on manual annotation and utilizes massive amounts of unlabeled trajectory data to automatically mine operational behavior patterns, achieving robust and high-precision agricultural machinery trajectory classification and feature representation learning. Through innovative data augmentation strategies, a hybrid encoder structure, and a difficult-to-distinguish negative sample sampling mechanism, this method significantly improves the stability, interpretability, and generalization ability of the model learning. Summary of the Invention
[0009] This invention proposes an unsupervised agricultural machinery trajectory classification method based on contrastive learning, mainly including core modules such as asymmetric data augmentation of feature dimensions, hierarchical temporal decoupling hybrid encoder, and adaptive hard-to-distinguish negative sample sampling. Through mechanisms such as multi-view augmentation, global and local temporal modeling, and dynamic negative sample optimization, the model can automatically learn discriminative trajectory feature representations from unlabeled data, thereby achieving unsupervised trajectory clustering and classification. This invention has advantages such as requiring no manual intervention, strong feature representation capability, and stable training results, making it highly suitable for large-scale intelligent trajectory analysis scenarios for agricultural machinery.
[0010] The present invention also discloses an apparatus loaded with an unsupervised agricultural machinery trajectory classification method based on contrastive learning.
[0011] The detailed technical solution of this invention is as follows:
[0012] An unsupervised agricultural machinery trajectory classification method based on contrastive learning, the method comprising:
[0013] S1. Preprocess the original agricultural machinery trajectory to obtain the trajectory segment dataset. ;
[0014] S2. Construct a contrastive learning model, which includes a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder:
[0015] S21. The trajectory segment dataset obtained in step S1 Asymmetric data augmentation based on feature dimensions is performed to obtain a weakly augmented sample set. and enhanced sample sets ;
[0016] S22, Weakly enhanced sample set and enhanced sample sets Each sample's temporal features are extracted using a feature encoder, resulting in a sample set containing the temporal features of each individual sample. The Includes weakly augmented sample sets containing temporal features of individual samples. and enhanced sample sets ;
[0017] S23. Construct a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder to process the sample set obtained in step S22, which contains the temporal features of individual samples. Feature extraction is performed to obtain feature samples after feature extraction. ;
[0018] S24. Introduce an adaptive hard-to-separate negative sample sampling strategy to sample the data output in step S23. The negative samples in the sample are divided to construct a set of difficult-to-distinguish negative samples;
[0019] S25. Based on the set of difficult-to-distinguish negative samples constructed in step S24, calculate the weighted contrastive loss and iteratively update the contrastive learning model parameters through backpropagation until the model converges.
[0020] S3. Training the contrastive learning model: Using the trajectory segment dataset preprocessed in step S1. Train the contrastive learning model constructed in step S2 until the model converges and output the trajectory representation model;
[0021] S4. Unsupervised trajectory classification:
[0022] After the data to be classified is preprocessed in step S1, it is input into the trajectory representation model in step S3 to obtain the output features. The output features are then clustered to achieve unsupervised trajectory classification.
[0023] Preferably, the preprocessing in step S1 includes:
[0024] S11. Extract motion features from the original agricultural machinery trajectory to generate trajectory points containing the extracted motion features;
[0025] S12. Use the DBSCAN density clustering algorithm to perform preliminary clustering of trajectory points containing extracted motion features to obtain pseudo-labels;
[0026] S13. Based on the obtained pseudo-labels, a sliding time window is applied to the trajectory points containing extracted motion features to construct trajectory segments, resulting in a trajectory segment dataset. .
[0027] Preferably, step S21 is as follows:
[0028] The trajectory segment dataset X has a shape of (Seq_len, Channels). The Channels are divided into core features and non-core features to obtain a weakly augmented sample set. and enhanced sample sets :
[0029] (1)
[0030] (2)
[0031] in, This refers to the core features. This indicates that slight Gaussian noise was applied to the core features. This refers to non-core features, while This represents structural perturbation operations, including random temporal masking, feature translation, local scaling, etc.; Seq_len refers to the time step size of the current sample, i.e., the sliding window size, and Channels refers to the number of feature channels for each sample.
[0032] Preferably, step S23 includes:
[0033] S231. Construct the spectral domain correlation modeling module, i.e., SRM. The spectral domain correlation modeling module includes a fast Fourier transform and a spectral change encoder, which takes the sample set containing the temporal features of individual samples obtained in step S22. The system maps the data to the spectral domain using Fourier transform, models global dependencies through a frequency-selective attention mechanism in a spectral transformation encoder, and outputs a global representation. With modulation vector ;
[0034] S232. Construct a time-series state evolution modeling module, namely DMEN, wherein the time-series state evolution modeling module introduces a time decay factor. The timing encoder based on SRM modulation and FiLM transformation, through the dynamic gating state update mechanism of DMEN, updates the sample set containing the time features of individual samples obtained in step S22. Local modeling is performed using a dynamic memory-gated temporal network, and local representations are output. ;
[0035] S233. Construct the cross-domain alignment and fusion module, namely CAF, the global representation of SRM. Local characterization of DMEN Feature-level adaptive fusion is performed through the cross-domain attention regulation mechanism of the cross-domain alignment fusion module to obtain the final encoding. .
[0036] More preferably, step S231 involves modeling global dependencies using a frequency-selective attention mechanism of a spectral variation encoder and outputting a global representation. With modulation vector ,include:
[0037] Let the hidden dimension of the contrastive learning model be First, the sample set after Fourier transform... Perform short-time spectral sensing and projection:
[0038] For the sample set after Fourier transform Each feature channel is obtained by performing depthwise convolution. ,Right now
[0039] (3)
[0040] in, This represents the short-time spectral response after independent modeling of each channel. T The total length of the time steps. D Let be the number of feature channels, and t be the t-th time step, with values ranging from 1 to 2. , The set of real numbers is the field of numbers, indicating that the elements belong to this set of real numbers. The length of the temporal convolution kernel. For time offset index, For the first The depthwise convolution kernel parameters corresponding to each feature channel are processed with zero padding at the boundary positions.
[0041] Then, pointwise projection is performed to obtain the spectral domain embedding. :
[0042] (4)
[0043] in, The channel projection weight matrix is... For bias terms, This indicates the hidden dimension of the model. It is a spectral domain embedding sequence.
[0044] right Normalization of layers yields The formula is as follows:
[0045] (5);
[0046] Representation layer normalization, in Implement multi-layer, multi-head self-attention encoding based on this:
[0047] Let the first Layer input is , where the initial value , No. The multi-head self-attention and feedforward calculation of the layer are as follows:
[0048] (6)
[0049] (7)
[0050] (8)
[0051] in, For learnable parameter matrix, Represents a query vector sequence. Represents a sequence of key vectors. Represents a sequence of value vectors. , , .
[0052] Multi-head self-attention is calculated as follows:
[0053] (9)
[0054] in, This represents the attention mechanism. The dimension representing a single attention head is used to scale the inner product result to stabilize the gradient. This represents the softmax function.
[0055] Subsequently, residual connections and a feedforward network are used for feature updates:
[0056] (10)
[0057] (11)
[0058] in, For the first In the layer, the intermediate hidden features obtained after "multi-head self-attention + residual connection + layer normalization" are... Indicates the first A two-layer feedforward network, Indicates the first The final output of the layer. (After...) After layer encoding, the spectral domain context feature matrix is obtained. .
[0059] right Perform time-series pooling to obtain the global representation With modulation vector :
[0060] First, perform adaptive average pooling based on time:
[0061] (12)
[0062] in, Indicates average pooling. t For the current time step, Represents the global spectral domain behavior of the trajectory.
[0063] Then, a modulation vector is generated using a small projection network:
[0064] (13)
[0065] in, Represents the Gaussian error linear unit activation function. To calculate the linear mapping weights of the modulation vector m, This corresponds to the bias term.
[0066] More preferably, in step S232, a basic temporal state evolution model is constructed, and a time decay factor is introduced into it. The FiLM transform based on SRM modulation yields the time-series state evolution module, DMEN, which is then used to generate the sample set containing the time features of individual samples obtained in step S22. After DMEN processing, the following is obtained ,right Perform attention readout based on the final modulation hidden layer, and output local representations through a fusion network. .
[0067] More preferably, the introduction of a time decay factor therein The FiLM transform based on SRM modulation yields the time-series state evolution module, DMEN, which includes:
[0068] Time decay factor Designed as a learnable, exponentially decaying gate or a gate generated from time-varying features, i.e.
[0069] (14)
[0070] in, , It is used to generate the time decay factor. The linear mapping weight matrix, It is the corresponding bias vector. This represents the Sigmoid function. Used for dynamic decay of historical memory.
[0071] Furthermore, decay is introduced into the basic temporal state evolution model—replacing the previous hidden with a decaying hidden:
[0072] (15)
[0073] in, This is the hidden state from the previous time step after being modulated by the time decay factor. This represents the output at time step t-1;
[0074] Simultaneously using the SRM modulation vector Scale and shift for generating FiLM:
[0075] (16)
[0076] (17)
[0077] in, This represents the tanh activation function. and These represent the scaling factor and translation factor by channel, respectively. It is the scaling factor used to generate FiLM. The linear mapping weight matrix, For the corresponding bias vector, It is the translation factor used to generate FiLM. The linear mapping weight matrix, It is the corresponding bias vector.
[0078] The recursive form of DMEN is obtained as follows:
[0079] (18)
[0080] (19)
[0081] (20)
[0082] (twenty one)
[0083] (twenty two)
[0084] in, and These represent the reset gate and update gate after FiLM modulation, respectively. , , , , , , , , For learnable parameters, Indicates the candidate hidden state. These are the candidate hidden states after FiLM modulation. This represents the output at the current time step t after FiLM modulation.
[0085] The sample set obtained in step S22, which contains the time features of a single sample, is then... After DMEN processing, the following is obtained ,right Perform attention readout based on the final modulation hidden layer, and output local representations through a fusion network. :
[0086] The sample set obtained in step S22, which contains the time features of a single sample, After DMEN processing, the hidden sequence at all time points is obtained. The matrix formed ,right Perform attention readout based on the final modulation hidden:
[0087] Set the final time or specified cutoff time as the output ,by Perform a query and calculate the historical weighted context:
[0088] (twenty three)
[0089] (twenty four)
[0090] in, , and For learnable parameters, For exponential mapping, To finally modulate the hidden state, The alignment score represents the correlation between the historical time t and the current local representation. is the attention weight, representing the contribution weight of the t-th time in history to the current local representation.
[0091] This yields the context vector:
[0092] (25)
[0093] And the local final representation is obtained through the fusion network:
[0094] (26)
[0095] in, Represents the local temporal evolution characteristics of the trajectory. It is the linear mapping weight matrix of the fusion network. It is the corresponding bias vector.
[0096] More preferably, step S233 includes:
[0097] First, construct the condition vector of the fusion weights. :
[0098] (27)
[0099] in, Representation of the global spectral domain behavior of the trajectory. This is a local temporal evolution representation, obtained by DMEN + attention readout. This is a vector concatenation operation, representing the joint modeling of global and local features. Linear mapping weights are used to generate the network for conditional vectors, compressing the concatenated features into the hidden dimensions. For the corresponding bias term;
[0100] Then, the fusion weights are generated:
[0101] (28)
[0102] in, For the linear mapping weights of the fusion weight generator, For the corresponding bias term, This is a vector per channel, used to control the fusion ratio of the two types of features.
[0103] The final representation is then obtained by weighting the data by channel or scalar:
[0104] (29)
[0105] in, This indicates element-wise multiplication. This provides a unified trajectory representation for the encoder output.
[0106] Preferably, the adaptive hard-to-separate negative sample sampling strategy described in step S24 specifically involves: within each mini-batch, based on the feature samples output in step S23... Dynamic selection and anchor points Samples with similar feature distances but different pseudo-labels To construct a high-quality negative sample set, the formula is as follows:
[0107] (30)
[0108] in, This represents the variable that minimizes the objective function, not the minimum value itself. Indicates the first i Feature representation of each anchor point sample This represents the feature representation of the j-th sample. , Let represent the pseudo-label of the class of the j-th, i-th sample.
[0109] Preferably, step S25 includes:
[0110] S251. Calculate the weights of each category based on the pseudo-labels obtained in step S12, and calculate the average weight of each category based on the weights. The formula is as follows:
[0111] (31)
[0112] (32)
[0113] in, N Let X be the total number of samples in the trajectory segment dataset. For the first The pseudo-labels of the categories of each sample, For the first Number of class samples As a smoothing factor, For indicator functions, i.e. The value is 1 if it is true, and 0 otherwise. The weight coefficients for category c. For the first Number of class samples .
[0114] In obtaining Then, count the number of each category in each batch. Multiply each category by its respective weight, then sum them and take the average to obtain the average category weight in a batch. ;
[0115] S252, Average category weights obtained in step S251 Calculate the weighted contrast loss:
[0116] The category weights obtained in step S251 By multiplying by a contrastive loss function, the dataset is balanced. The contrastive loss function is as follows:
[0117] (33)
[0118] in, The high-quality negative sample set constructed in Formula 35 , The negative sample weights are adaptively adjusted based on the similarity between the sample and the anchor point, so that hard-to-distinguish samples receive a larger penalty weight. This indicates the calculation of cosine similarity. This is a temperature coefficient used to control the smoothness of similarity. For positive sample feature representation, and Semantic consistency This represents the features of negative samples.
[0119] S253. Iteratively update the parameters of the comparative learning model through backpropagation until the model converges.
[0120] In another aspect of the present invention, an apparatus is provided for implementing an unsupervised agricultural machinery trajectory classification method based on contrastive learning, the apparatus comprising:
[0121] Data acquisition and preprocessing module: Acquires raw agricultural machinery GNSS trajectory data, and performs data cleaning and feature construction processing on the raw agricultural machinery GNSS trajectory data to generate a continuous and uniform trajectory segment dataset. ;
[0122] Feature enhancement module: used for the trajectory segment dataset Perform asymmetric data augmentation based on feature dimensions, where weak augmentation or indifference is applied to key feature dimensions reflecting the physical characteristics of the operation, while strong augmentation is applied to non-key feature dimensions, generating a weakly augmented sample set. and enhanced sample sets This is to improve the robustness of the model while avoiding damage to key discriminative features, and to generate multi-view trajectory samples for comparative learning.
[0123] Feature extraction module: used to extract features from the input weakly augmented sample set. and enhanced sample sets The algorithm learns discriminative trajectory feature representations, and the feature extraction module includes a feature encoder and a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder. The feature encoder is used to process the input weakly enhanced sample set. and enhanced sample sets Preliminary feature encoding is performed to uniformly represent the original or enhanced trajectory sequence, and the output is denoted as... ( include and ); Spectral domain correlation-dynamic memory decoupled hybrid timing encoders are used in In a unified feature space, the multi-level temporal semantics of trajectory sequences are further modeled, which includes a global modeling submodule, a local modeling submodule, and an adaptive feature fusion submodule;
[0124] Contrastive learning training module: used to train trajectory segment datasets under unsupervised conditions. The feature extraction module is pre-trained;
[0125] The difficult-to-distinguish negative sample optimization submodule is used to dynamically identify difficult-to-distinguish negative samples that are close to the feature distribution of the current trajectory sample based on trajectory feature similarity during the contrastive learning training process, and to apply higher weights to the difficult-to-distinguish negative samples to participate in the contrastive loss calculation, so as to enhance the inter-class feature discrimination ability and compress the intra-class feature distribution, thereby improving the discriminativeness and stability of trajectory representation.
[0126] Model application module: Used to deploy the trained trajectory clustering model to perform operation pattern recognition, trajectory classification or statistical analysis on newly collected agricultural machinery trajectory data, so as to support agricultural production management and intelligent decision-making applications.
[0127] Compared with the prior art, the present invention has the following beneficial effects:
[0128] (1) This invention enables the model to automatically learn discriminative trajectory feature representations from unlabeled data through mechanisms such as asymmetric data augmentation, global and local temporal modeling, and dynamic negative sample optimization, thereby achieving unsupervised trajectory clustering and classification. This invention has the advantages of requiring no manual intervention, strong feature representation ability, and stable training effect, and is very suitable for large-scale intelligent trajectory analysis scenarios of agricultural machinery.
[0129] (2) The method of the present invention can completely get rid of the dependence on manual annotation and significantly reduce the application threshold: The present invention constructs an end-to-end unsupervised learning framework, which can automatically discover potential operation patterns and structural differences directly from the massive agricultural machinery trajectory data collected continuously, without any prior category information or manual experience rules, avoiding the problems of strong subjectivity, high cost and difficulty in scaling of manual annotation, and is particularly suitable for the continuous analysis of long-term operation data of multiple regions and multiple machine types.
[0130] (3) Key discriminative features are effectively protected to avoid semantic shifts introduced by augmentation: For the feature dimensions such as speed, working distance, and turning changes in agricultural machinery trajectory that play a decisive role in distinguishing the type of work, this invention designs an asymmetric data augmentation strategy based on feature dimensions. While enhancing the robustness of the model, it effectively suppresses the destruction of core physical meaning features and avoids the problems of blurred inter-class boundaries and semantic confusion caused by traditional random augmentation, thereby ensuring that the learned representation has stronger interpretability and stability.
[0131] (4) Multi-scale temporal semantic collaborative modeling significantly improves the integrity of feature expression: By introducing a dual-branch structure of "spectral domain association modeling + dynamic memory modeling", on the one hand, the periodic patterns and long-range dependencies in the agricultural machinery operation process are captured at the frequency domain level, and on the other hand, local operation behavior and short-term dynamic changes are modeled at the time domain level. Furthermore, through cross-domain modulation mechanism and adaptive feature fusion strategy, the complementarity and synergy of global trend information and local detail features are realized, thereby constructing a trajectory representation with richer layers and more complete semantics.
[0132] (5) Focusing on difficult-to-distinguish negative samples and strengthening inter-class differentiation ability: In view of the problem that there are similar trajectory shapes and blurred boundaries between different operation modes of agricultural machinery, this invention introduces an adaptive difficult-to-distinguish negative sample optimization mechanism. During the comparative learning process, it dynamically identifies and focuses on constraining high similarity negative samples, effectively expanding the feature interval between different operation modes, while compressing the feature distribution range of similar samples, so that the learned representation has stronger discriminative power in clustering and classification tasks.
[0133] (6) It has good generalization ability and engineering robustness, and is suitable for large-scale deployment: The proposed method does not depend on specific machine parameters or fixed operation rules. It can maintain stable performance under different types of agricultural machinery, different operation plots, different operation seasons and different sampling frequencies. It has strong robustness to noise, missing trajectory and uneven sampling, and has the ability to be deployed and promoted on a large scale in real agricultural production environment. Attached Figure Description
[0134] Figure 1 This is the overall model architecture of the present invention;
[0135] Figure 2 This is a schematic diagram of the hybrid timing encoder model constructed in this invention;
[0136] Figure 3 This is a schematic diagram of the prediction results using a trained contrastive learning model in Embodiment 1 of the present invention. Detailed Implementation
[0137] Example 1
[0138] Unsupervised agricultural machinery trajectory classification methods based on contrastive learning, such as Figure 1 As shown, the method includes:
[0139] S1. Preprocess the original agricultural machinery trajectory to obtain the trajectory segment dataset. ;
[0140] S11. Extract motion features from the original agricultural machinery trajectory to generate trajectory points containing the extracted motion features;
[0141] The dataset used in this invention is a wheat GNSS trajectory dataset collected by the Beidou team of China Agricultural University. The original agricultural machinery GNSS trajectory data consists of multiple trajectory points arranged in chronological order. Each trajectory point includes the acquisition time, latitude and longitude, speed, heading angle, and a label. There are two types of labels: "0" represents a road point, and "1" represents a field point. The sampling frequency is 5 seconds. Next, the motion features of the trajectory points are extracted. First, the physical distance between two points must be obtained. Assuming the latitude and longitude of the two points are (…),… )and( The steps are as follows:
[0142] First, convert latitude and longitude to radians:
[0143] (1)
[0144] in, The angle value is expressed in radians. This represents latitude and longitude values expressed in angles. After conversion, the coordinates of the two points are expressed as follows: ,in, and They represent the first The latitude and longitude values in radians for each point.
[0145] Then use the Haversine formula to calculate the distance between the two points:
[0146] (2)
[0147] in, This represents the spherical distance between two geographic coordinate points. The average radius of the Earth is usually taken as... .
[0148] After obtaining the distance between two points, calculate their motion characteristics based on the distance and time, including velocity, acceleration, heading angle, angular velocity, angular acceleration characteristics, and calculate the density of trajectory points within a fixed area based on the distance.
[0149] S12. Use the DBSCAN density clustering algorithm to perform preliminary clustering of trajectory points containing extracted motion features to obtain pseudo-labels;
[0150] When constructing trajectory segments within subsequent sliding time windows, samples within a window are required to belong to the same category. However, since this invention is unsupervised, windows cannot be divided based on labels. A preliminary clustering process is needed to obtain pseudo-labels, preparing for subsequent time window division and also contributing to balancing the dataset. This is explained in detail in section S25. For agricultural machinery trajectory points, the density of field points is high due to the repeated operation of agricultural machinery on the field at a relatively slow speed. Conversely, the density of road points is low because agricultural machinery operates at higher speeds and generally does not repeatedly travel on roads. Based on this density characteristic, the DBSCAN clustering algorithm is used for preliminary clustering of trajectory points, yielding pseudo-labels with an accuracy of approximately 80%.
[0151] S13. Based on the obtained pseudo-labels, a sliding time window is applied to the trajectory points containing extracted motion features to construct trajectory segments, resulting in a trajectory segment dataset. ;
[0152] After the above steps, the conditions for a sliding time window are met. Trajectory segments are then constructed, with a time window size of 40 and a step size of 1. The time window is then slid to sort by time, placing 40 trajectory points with the same pseudo-label into a single window to form a trajectory segment as a new sample. The label of the trajectory point in the middle of the time window is selected as the label for the trajectory segment. If fewer than 40 trajectory points with the same pseudo-label remain, they are discarded. Assume the trajectory point dataset is... The data format of the trajectory segment after the sliding time window is as follows:
[0153] ,
[0154] The trajectory segment dataset is .
[0155] S2. Construct a contrastive learning model, which includes a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder.
[0156] S21. The trajectory segment dataset obtained in step S1 Asymmetric data augmentation based on feature dimensions is performed to obtain a weakly augmented sample set. and enhanced sample sets ;
[0157] In agricultural machinery operation scenarios, trajectory samples are often composed of speed. ,distance Heading angle Time interval Latitude and longitude offset It consists of multiple continuous features. Among them, speed and distance are key discriminative features that determine the job category and road type, but they are often subject to excessive perturbation in traditional contrastive learning. Existing enhancement methods, such as temporal occlusion, noise smoothing, and random jitter, apply perturbation uniformly across all feature dimensions. While this improves sample diversity, it also weakens the numerical continuity of core features and the clarity of class boundaries, thus affecting the contrast target. The similarity of positive samples is incorrectly compressed, and the difference of negative samples is diluted.
[0158] To address this issue, this invention proposes Feature-wise Asymmetric Data Augmentation, a method based on feature dimension. In the augmented view construction stage, a decoupling principle of "Strong Protection vs. Strong Disturbance" is introduced. The trajectory segment dataset, i.e., the input sample X, has a shape of (40, Channels). The Channels are divided into core features and non-core features, resulting in a weakly augmented sample set. and enhanced sample sets :
[0159] (3)
[0160] (4)
[0161] in, This refers to the core features. This indicates that slight Gaussian noise was applied to the core features. This refers to non-core features, while This represents structural perturbation operations, including random temporal masking, feature translation, and local scaling; Channels refers to the number of feature channels per sample. Through this asymmetric design, the weak augmentation view maintains the numerical consistency of core features to preserve compactness within categories; the strong augmentation view, on the other hand, applies significant perturbations to non-core dimensions to force the encoder to learn robustness and invariance to non-critical changes during training.
[0162] In terms of weak enhancement, this invention applies slight Gaussian noise with a variance of 0.001 to the core features. In terms of strong enhancement, it first applies slight Gaussian noise with a variance of 0.001 to the non-core features, and then applies local scaling with an amplitude of 0.01 to increase the complexity of the data, force the model to learn deeper temporal features, and improve the robustness of the model.
[0163] This strategy effectively improves the encoder's feature selectivity and discriminative stability in contrastive learning. The model performs well on samples... When maintaining similarity constraints, what is actually learned is category-invariant semantic features, rather than noise-driven local differences.
[0164] Traditional trajectory data augmentation methods often apply the same augmentation strategy to all input features. However, the speed and distance features between sampling points of agricultural machinery differ significantly between road travel and field operations, and these are key features for distinguishing different operation modes. If the augmentation strategy applies excessive perturbation to the speed and distance features, it will blur the feature boundaries between the two types of operation trajectories, disrupt the positive and negative sample distribution of contrastive learning, and reduce the convergence efficiency of the model.
[0165] In contrastive learning, positive and negative samples are constructed to establish contrast relationships. During subsequent training, the model focuses on learning the similarity between positive samples and the differences between negative samples, ultimately bringing positive samples closer and pushing negative samples further away in the projection space. The overall architecture of this invention is based on the TS-TCC model, and the construction of positive and negative samples is consistent with TS-TCC, that is, for the input dataset... After data augmentation, a weakly augmented sample set is obtained. and strongly enhanced samples Assuming batch_size is 64, then for the samples in a batch Positive samples refer to different augmented views of the same sample, i.e. and Negative samples refer to different trajectories within the same batch, i.e. and .like Figure 1 As shown.
[0166] S22, Weakly enhanced sample set and enhanced sample sets Each sample's temporal features are extracted using a feature encoder, resulting in a sample set containing the temporal features of each individual sample. The Includes weakly augmented sample sets containing temporal features of individual samples. and enhanced sample sets ;
[0167] After passing through S1 and S21, the trajectory segment is still a collection of motion features of each independent point. These features are high-dimensional, noisy, and chaotic. Therefore, the encoder is needed to map the original high-dimensional and noisy temporal signal to the temporal-aware latent representation space, providing stable and more discriminative features for subsequent temporal comparison learning and global modeling.
[0168] The specific configuration of the feature encoder used in this invention is as follows:
[0169] First convolutional layer: kernel size is 9, stride is 1, padding is same, and output channel number is 64;
[0170] The second convolutional layer has a kernel size of 9, a stride of 1, the same padding, and 128 output channels.
[0171] The third convolutional layer has a kernel size of 9, a stride of 1, the same padding, and 128 output channels.
[0172] Meanwhile, these three convolutional layers are not simply arranged sequentially, but interact through residual connections. After the data passes through the first convolutional layer, it is copied into two copies. The first copy passes through the second convolutional layer with an attention mechanism applied, while the second copy passes directly through a simple convolutional layer, increasing the dimension from 64 to 128. The outputs of these two parts are then added together to obtain the final output of the second convolutional layer. The same applies to the third layer. Introducing an attention mechanism and residual connections into the three-layer one-dimensional convolutional encoder can achieve adaptive weighting of key time segments and feature channels while maintaining local temporal modeling capabilities, and significantly alleviate the information degradation problem caused by deep convolutions, thereby improving the stability and discriminativeness of contrastive learning representations. After feature extraction by the feature encoder, a weakly enhanced sample set containing the temporal features of individual samples is obtained. and enhanced sample sets This makes it more suitable for subsequent time series comparison and learning.
[0173] S23. Construct a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder to process the sample set obtained in step S22, which contains the temporal features of individual samples. Feature extraction is performed to obtain the feature-extracted samples. :
[0174] Agricultural machinery trajectory sequences have characteristics such as cross-scale dependence, multi-segment behavior switching, high noise instability, and strong temporal continuity, which makes single coding structures prone to performance bottlenecks such as "insufficient global pattern recognition" or "limited local dynamic modeling ability," such as Transformer or RNN.
[0175] This invention proposes a spectral-temporal decoupling hybrid temporal encoder, which models multi-scale features of trajectory sequences through a parallel structure. The hybrid temporal encoder model is as follows: Figure 2 As shown:
[0176] S231, Spectral Domain Awareness Branch: Construct the Spectral Relational Module (SRM), which includes a Fast Fourier Transform and a spectral change encoder. This module takes the sample set obtained in step S22, containing the temporal features of individual samples, and... The system maps the data to the spectral domain using Fourier transform, models global dependencies through a frequency-selective attention mechanism in a spectral transformation encoder, and outputs a global representation. With modulation vector ;
[0177] Specifically, to address the potential periodicity, behavioral rhythmicity, and cross-regional motion similarity in long sequences, this invention first maps the input sequence to the spectral domain and models global dependencies through a frequency-selective attention mechanism:
[0178] Let the hidden dimension of the contrastive learning model be In this embodiment, it is 64. First, the sample set after Fourier transform... Short-time spectral sensing and projection: For the sample set after Fourier transform... Each feature channel is subjected to a depthwise convolution, with a kernel length of [missing information]. In this embodiment, the value is 9, resulting in... ,Right now
[0179] (5)
[0180] in, T Let t be the total length of the time steps, and t be the t-th time step, with a value of 1. , D The number of feature channels, The set of real numbers is the field of numbers, indicating that the elements belong to this set of real numbers. For time offset index, For the first The depthwise convolution kernel parameters corresponding to each feature channel are handled with zero padding at the boundary positions. This represents the short-time spectral response after each channel is modeled independently.
[0181] Then, pointwise projection and 1×1 convolution are performed to obtain the spectral domain embedding. :
[0182] (6)
[0183] in, The channel projection weight matrix is... For bias terms, This indicates the hidden dimension of the model. It is a spectral domain embedding sequence.
[0184] right Normalization of layers yields The formula is as follows:
[0185] (7)
[0186] Representation layer normalization, in Based on this, implement a multi-layer multi-head self-attention coding module, namely the spectral domain correlation module (SRM).
[0187] Let the first Layer input is , where the initial value , No. The multi-head self-attention and feedforward calculation of the layer are as follows:
[0188] (8)
[0189] (9)
[0190] (10)
[0191] in, For learnable parameter matrix, Represents a query vector sequence. Represents a sequence of key vectors. Represents a sequence of value vectors. , , .
[0192] Multi-head self-attention is calculated as follows:
[0193] (11)
[0194] in, This represents the attention mechanism. The dimension representing a single attention head is used to scale the inner product result to stabilize the gradient. This represents the softmax function.
[0195] Subsequently, residual connections and a feedforward network are used for feature updates:
[0196] (12)
[0197] (13)
[0198] in, For the first In the layer, the intermediate hidden features obtained after "multi-head self-attention + residual connection + layer normalization" are... Indicates the first A two-layer feedforward network, Indicates the first The final output of the layer. (After...) The spectral domain context matrix is obtained after the layer. .
[0199] right Perform time-series pooling to obtain the global representation With modulation vector :
[0200] First, perform adaptive average pooling based on time:
[0201] (14)
[0202] in, Indicates average pooling. t For the current time step, Represents the global spectral domain behavior of the trajectory.
[0203] Then, a modulation vector is generated using a small projection network:
[0204] (15)
[0205] in, Represents the Gaussian error linear unit activation function. , , Used to provide global condition information to subsequent timing branches. To calculate the linear mapping weights of the modulation vector m, This corresponds to the bias term.
[0206] The above process constitutes the "Spectral Domain Correlation Modeling Module (SRM)," whose output is a global representation. With modulation vector .
[0207] SRM can explicitly model the implicit resonance relationships between long-distance behaviors, such as behavioral spectrum changes like "low-speed field operation → accelerated transition → high-speed road driving", enabling the encoder to have cross-scale global perception capabilities.
[0208] S232, Dynamic Scheduling Branch: Construct the temporal state evolution modeling module Dynamic Memory Evolution Network, i.e., DMEN. The temporal state evolution modeling module introduces a time decay factor. The timing encoder based on SRM modulation and FiLM transformation, through the dynamic gating state update mechanism of DMEN, updates the sample set containing the time features of individual samples obtained in step S22. Local modeling is performed using a dynamic memory-gated temporal network, and local representations are output. ;
[0209] To extract local trends, velocity changes, and rapid turning behaviors from the trajectory, this invention designs a dynamic gating state update mechanism, which updates the sample set obtained in step S22, containing the time features of individual samples. Local modeling is performed using the Dynamic Memory Gated Temporal Network (DMEN), which outputs local representations. :
[0210] Constructing a basic temporal state evolution model: This invention uses a unidirectional two-layer GRU with a hidden layer dimension of 128. Let the original recursion of the GRU be:
[0211] (16)
[0212] (17)
[0213] (18)
[0214] (19)
[0215] in , . and These represent resetting the door and updating the door, respectively. , , , , , , , , For learnable parameters, Indicates the candidate hidden state. This represents the output at the current time step t. This represents the output at time step t-1. This indicates element-wise multiplication.
[0216] The original recursion of GRU can also be in a single-level unidirectional form or a multi-level / bidirectional form.
[0217] Introduce a time decay factor into the established basic time-series state evolution model. The FiLM transform based on SRM modulation yields the time-series state evolution module, DMEN:
[0218] Two key enhancements are introduced in DMEN: time decay factor Used for smoothing short-term disturbances and SRM-based FiLM transform. The time decay factor is designed as a learnable exponential decay or a gate generated from time-varying features, i.e.
[0219] (20)
[0220] in, It is used to generate the time decay factor. The linear mapping weight matrix, It is the corresponding bias vector. This represents the Sigmoid function. Used for dynamic decay of historical memory.
[0221] In addition, decay is introduced into the basic temporal state evolution model—replacing the previous hidden with a decaying hidden:
[0222] (twenty one)
[0223] in, This is the hidden state from the previous time step after being modulated by the time decay factor. This represents the output at time step t-1;
[0224] Simultaneously using the SRM modulation vector Scale and shift for generating FiLM:
[0225] (twenty two)
[0226] (twenty three)
[0227] in, This represents the tanh activation function. and These represent the scaling factor and translation factor by channel, respectively; It is the scaling factor used to generate FiLM. The linear mapping weight matrix, For the corresponding bias vector, It is the translation factor used to generate FiLM. The linear mapping weight matrix, It is the corresponding bias vector.
[0228] Embedding the above two items into the GRU update rule yields the recursive form of DMEN:
[0229] (twenty four)
[0230] (25)
[0231] (26)
[0232] (27)
[0233] (28)
[0234] in, and These represent the reset gate and update gate after FiLM modulation, respectively. Indicates the candidate hidden state. These are the candidate hidden states after FiLM modulation. This represents the output at the current time step t after FiLM modulation.
[0235] The sample set obtained in step S22, which contains the time features of a single sample, is then... After DMEN processing, the following is obtained ,right Perform attention readout based on the final modulation hidden layer, and output local representations through a fusion network. :
[0236] Specifically, the sample set obtained in step S22, which contains the temporal features of a single sample, is... After DMEN processing, the hidden sequences at all time points are obtained. The matrix formed To compensate for the truncation / long-term dependency issue, for Perform attention readout based on the final modulation hidden:
[0237] Set the final time or specified cutoff time as the output ,by Perform a query and calculate the historical weighted context:
[0238] (29)
[0239] (30)
[0240] in, , and For learnable parameters, For exponential mapping, To finally modulate the hidden state, The alignment score represents the correlation between the historical time t and the current local representation. is the attention weight, representing the contribution weight of the t-th time in history to the current local representation.
[0241] This yields the context vector:
[0242] (31)
[0243] And obtain the local final representation through the fusion network.
[0244] (32)
[0245] in, , Represents the local temporal evolution characteristics of the trajectory. It is the linear mapping weight matrix of the fusion network. It is the corresponding bias vector.
[0246] this This refers to the output of DMEN.
[0247] This branch introduces a learnable time decay factor and a dynamic memory update strategy, enabling the model to retain historical dependencies, suppress noise, and model local evolution, thus resisting chaotic signals caused by GNSS jitter, short-term drift, and sudden changes in operational behavior.
[0248] S233. Constructing the Cross-domain Alignment Fusion (CAF) module, a global representation of SRM. Local characterization of DMEN Feature-level adaptive fusion is performed through the cross-domain attention regulation mechanism of the cross-domain alignment fusion module to obtain the final encoding. .
[0249] To fully integrate the global pattern in the spectral domain with the local dynamics in the temporal domain, this invention designs a cross-domain attention control mechanism to achieve feature-level adaptive fusion of the global representation of SRM. Local characterization of DMEN The final code is adaptively synthesized using the Cross-Domain Alignment Fusion (CAF) module. Because there are two enhanced views, the final encoding can be displayed as follows: .
[0250] First, construct the condition vector of the fusion weights. It can be obtained by splicing two branches and passing them through a small network:
[0251] (33)
[0252] in, Representation of the global spectral domain behavior of the trajectory. This is a local temporal evolution representation, obtained by DMEN + attention readout. This is a vector concatenation operation, representing the joint modeling of global and local features. Linear mapping weights are used to generate the network for conditional vectors, compressing the concatenated features into the hidden dimensions. For the corresponding bias term;
[0253] (34)
[0254] in, For the linear mapping weights of the fusion weight generator, For the corresponding bias term, This is a vector per channel, used to control the fusion ratio of the two types of features.
[0255] The final representation is then obtained by weighting the data by channel or scalar.
[0256] (35)
[0257] in, This indicates element-wise multiplication. This provides a unified trajectory representation for the encoder output. The projection head is used to obtain the representation for contrastive learning.
[0258] (36)
[0259] in, Indicates batch normalization. The linear mapping weights for the projection head are used to map the representation to the contrastive learning space. For the corresponding bias term, The low-dimensional representation used for contrastive learning is used for future step prediction or InfoNCE loss calculation.
[0260] For contrastive learning scenarios used in future-step prediction, it is available. Through several linear predictors Predicting the future The original feature dimension of each step (or its low-dimensional projection): for each prediction step Calculate the prediction vector The training target is the NCE loss or InfoNCE of negative samples within the batch.
[0261] Through the above process, the model takes into account all features in the local and global, time and frequency domains, and can efficiently and accurately extract the trajectory features of agricultural machinery, and distinguish the two categories of data in the feature space, which facilitates subsequent clustering operations.
[0262] S24. Introduce an adaptive hard-to-separate negative sample sampling strategy for the samples output in step S23. The negative samples in the sample are divided to construct a set of difficult-to-distinguish negative samples;
[0263] In the loss function of contrastive learning, the selection of negative samples directly affects the convergence speed of the model and the quality of the discrimination boundary. Traditional random sampling methods introduce a large number of anchor samples. "Easily separable negative samples" with excessively large feature distances contribute very little to the loss gradient, resulting in low training efficiency.
[0264] To address this, this invention introduces an Adaptive Negative Sampling (ANS) strategy. Its core idea is: within each mini-batch, based on the feature samples output in step S23... Dynamically select those related to the anchor point Samples with similar feature distances but different pseudo-labels This is to construct a high-quality negative sample set. Formalistically:
[0265] (37)
[0266] in, This represents the variable that minimizes the objective function, not the minimum value itself. Indicates the first i Feature representation of each anchor point sample This represents the feature representation of the j-th sample. , Let represent the pseudo-label of the class of the j-th, i-th sample.
[0267] S25. Based on the set of difficult-to-distinguish negative samples constructed in step S24, calculate the weighted contrastive loss and iteratively update the contrastive learning model parameters through backpropagation until the model converges.
[0268] S251. Calculate the weights of each category based on the pseudo-labels obtained in step S12, and calculate the average weight of each category based on the weights. ;
[0269] In the data preprocessing stage, pseudo-labels were generated using DBSCAN. Since the agricultural machinery trajectory data is extremely imbalanced, with a ratio of approximately 1:9 between road points and field points, the ratio of the two categories was calculated based on the pseudo-labels. Weights were then calculated based on these ratios and multiplied by the final loss function to achieve a balanced dataset.
[0270] (38)
[0271] (39)
[0272] in, For the first Number of class samples This is a smoothing factor used to alleviate class imbalance; in this invention, it is 20000. N Let X be the total number of samples in the trajectory segment dataset. For the first The true label of each sample For indicator functions, i.e. The value is 1 if it is true, and 0 otherwise. The weight coefficients for category c. For the first Number of class samples .
[0273] In obtaining Then, count the number of each category in each batch. Multiply each category by its respective weight, then sum them and take the average to obtain the average category weight in a batch. Finally, the loss of that batch is multiplied by this weight to achieve the goal of balancing the dataset.
[0274] S252, Average category weights obtained in step S251 Calculate the weighted contrast loss:
[0275] The category weights obtained in step S251 Multiplying by the contrastive loss function of this batch achieves the goal of balancing the dataset. The contrastive loss function is as follows:
[0276] (40)
[0277] in, The high-quality negative sample set already constructed in Formula 37 , The negative sample weights are adaptively adjusted based on the similarity between the sample and the anchor point, so that hard-to-distinguish samples receive a larger penalty weight. This indicates the calculation of cosine similarity. This is a temperature coefficient used to control the smoothness of similarity. For positive sample feature representation, and Semantic consistency This represents the features of negative samples.
[0278] For the difficult-to-distinguish negative samples proposed in S24, a higher weight is given to them in the contrastive loss;
[0279] in, The model adaptively adjusts the similarity between samples and anchor points, giving greater penalty weights to difficult-to-separate samples. Essentially, this strategy introduces an "adversarially-driven contrastive optimization" into the contrast space, prompting the model to actively expand class boundaries and improve inter-class separability.
[0280] S253. Iteratively update the parameters of the comparative learning model through backpropagation until the model converges.
[0281] S3. Training the contrastive learning model: Using the trajectory segment dataset preprocessed in step S1. Train the contrastive learning model constructed in step S2 until the model converges and output the trajectory representation model;
[0282] The model convergence is specifically defined as follows: the model loss fluctuates by no more than 0.1 within 5 consecutive epochs.
[0283] S4. Unsupervised trajectory classification:
[0284] After the data to be classified is preprocessed in step S1, it is input into the trajectory representation model in step S3 to obtain the output features. The output features are then clustered to achieve unsupervised trajectory classification.
[0285] Application examples
[0286] Clustering experiments were conducted using the method proposed in this invention, and the confusion matrix was calculated.
[0287] After step S3, a trained contrastive learning model, i.e., a trajectory representation model, is obtained. Then, a new dataset, after preprocessing in step S1, is input into this model for feature extraction. Finally, the output features are clustered using k-means. The specific configuration of k-means is as follows:
[0288] The initial cluster centers are 20, the distance is calculated using DTW distance, and the number of clusters is 2.
[0289] After clustering, the two category distributions in the data are obtained. The clustering results are then compared with the true labels to calculate the confusion matrix. The specific calculation method is as follows:
[0290] In binary classification problems, let the common... One sample, true category Recorded as
[0291] (41)
[0292] Where 1 represents the positive class and 0 represents the negative class;
[0293] Model prediction The result is recorded as
[0294] (42)
[0295] Binary confusion matrix Represented as
[0296] (43)
[0297] The rows correspond to the true categories, and the columns correspond to the predicted categories. The formula for calculating each element in the confusion matrix is:
[0298] (44)
[0299] (45)
[0300] (46)
[0301] (47)
[0302] Based on this, the formulas for calculating precision, recall, and F1 score are as follows:
[0303] (48)
[0304] (49)
[0305] (50)
[0306] Based on the above calculation method, the confusion matrix of this experiment is as follows:
[0307] Table 1. Confusion matrix of experimental results of this invention
[0308]
[0309] Prediction was performed using a pre-trained contrastive learning model, i.e., a trajectory representation model. The results are as follows: Figure 3 As shown.
[0310] This invention also conducted comparative verification experiments. Except for the following differences, the experimental conditions, data, and procedures were exactly the same as those in the above application examples:
[0311] Compare with Example 1 and remove the asymmetric data augmentation in step S21;
[0312] Compared to application example 2, step S23 only includes the spectrum correlation modeling module, that is, it only adopts the global modeling method;
[0313] Compared with application example 3, step S23 only includes the temporal state evolution modeling module, that is, only the local modeling method is used;
[0314] Compared to Application Example 4, the adaptive hard-to-separate negative sample sampling strategy without introducing step S24;
[0315] The experimental results for each comparative application example are shown in Tables 2-5:
[0316] Table 2 shows the confusion matrix comparing the experimental results of Application Example 1.
[0317]
[0318] Compared with Table 1, asymmetric data augmentation significantly improved the ability to distinguish road categories, especially playing a key role in precision and F1 score, while having a smaller impact on the relatively stable field category.
[0319] Table 3. Confusion matrix comparing the experimental results of Application Example 2
[0320]
[0321] Compared with Table 1, the accuracy of road category decreased from 87.68% to 49.05%, indicating that it is difficult to accurately depict the local temporal characteristics of road categories by using global modeling alone, resulting in more false detections and significantly increasing the error of misclassifying "fields" as "roads".
[0322] Table 4. Confusion matrix comparing the experimental results of Application Example 3
[0323]
[0324] Compared with Table 1, using only local modeling significantly reduced the precision, recall, and F1 score of road categories, indicating that relying solely on local modeling leads to a large number of missed detections of road categories, demonstrating that global context plays an irreplaceable role in road trajectory recognition.
[0325] Table 5. Confusion matrix comparing the experimental results of Application Example 4
[0326]
[0327] Compared with Table 1, using only local modeling significantly reduced the precision, recall, and F1 score of road categories, indicating that the negative sample optimization mechanism introduced in this invention effectively enhances the model's ability to distinguish between road and field boundary samples, especially improving the precision and stability of road categories.
[0328] Comparative experiments show that asymmetric data augmentation, global-local joint modeling, and the hard-to-distinguish negative sample optimization mechanism all play key roles in road trajectory recognition. Among them, the synergy between global and local modeling is the core factor in improving the recall rate of road categories, while asymmetric augmentation and negative sample optimization mainly improve the discrimination accuracy of road categories. The combined effect of these three mechanisms enables the model to achieve better overall performance in complex agricultural trajectory scenarios.
[0329] Example 2
[0330] This embodiment provides an apparatus loaded with an unsupervised agricultural machinery trajectory classification method based on contrastive learning, the apparatus comprising:
[0331] Data acquisition and preprocessing module: Acquires raw agricultural machinery GNSS trajectory data, and performs data cleaning and feature construction processing on the raw agricultural machinery GNSS trajectory data to generate a continuous and uniform trajectory segment dataset. ;
[0332] Feature enhancement module: used for the trajectory segment dataset Perform asymmetric data augmentation based on feature dimensions, where weak augmentation or indifference is applied to key feature dimensions reflecting the physical characteristics of the operation, while strong augmentation is applied to non-key feature dimensions, generating a weakly augmented sample set. and enhanced sample sets This is to improve the robustness of the model while avoiding damage to key discriminative features, and to generate multi-view trajectory samples for comparative learning.
[0333] Feature extraction module: used to extract features from the input weakly augmented sample set. and enhanced sample sets The algorithm learns discriminative trajectory feature representations, and the feature extraction module includes a feature encoder and a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder. The feature encoder is used to process the input weakly enhanced sample set. and enhanced sample sets Preliminary feature encoding is performed to uniformly represent the original or enhanced trajectory sequence, and the output is denoted as... ( include and ); Spectral domain correlation-dynamic memory decoupled hybrid timing encoders are used in In a unified feature space, the multi-level temporal semantics of trajectory sequences are further modeled, which includes a global modeling submodule, a local modeling submodule, and an adaptive feature fusion submodule;
[0334] Contrastive learning training module: used to train trajectory segment datasets under unsupervised conditions. The feature extraction module is pre-trained;
[0335] The difficult-to-distinguish negative sample optimization submodule is used to dynamically identify difficult-to-distinguish negative samples that are close to the feature distribution of the current trajectory sample based on trajectory feature similarity during the contrastive learning training process, and to apply higher weights to the difficult-to-distinguish negative samples to participate in the contrastive loss calculation, so as to enhance the inter-class feature discrimination ability and compress the intra-class feature distribution, thereby improving the discriminativeness and stability of trajectory representation.
[0336] Model application module: Used to deploy the trained trajectory clustering model to perform operation pattern recognition, trajectory classification or statistical analysis on newly collected agricultural machinery trajectory data, so as to support agricultural production management and intelligent decision-making applications.
Claims
1. An unsupervised agricultural machinery trajectory classification method based on contrastive learning, characterized in that, The method includes: S1. Preprocess the original agricultural machinery trajectory to obtain the trajectory segment dataset. ; S2. Construct a contrastive learning model, which includes a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder: S21. The trajectory segment dataset obtained in step S1 Asymmetric data augmentation based on feature dimensions is performed to obtain a weakly augmented sample set. and enhanced sample sets ; S22, Weakly enhanced sample set and enhanced sample sets Each sample's temporal features are extracted using a feature encoder, resulting in a sample set containing the temporal features of each individual sample. The Includes weakly augmented sample sets containing temporal features of individual samples. and enhanced sample sets ; S23. Construct a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder to process the sample set obtained in step S22, which contains the temporal features of individual samples. Feature extraction is performed to obtain feature samples after feature extraction. ; S24. Introduce an adaptive hard-to-separate negative sample sampling strategy to sample the data output in step S23. The negative samples in the sample are divided to construct a set of difficult-to-distinguish negative samples; S25. Based on the set of difficult-to-distinguish negative samples constructed in step S24, calculate the weighted contrastive loss and iteratively update the contrastive learning model parameters through backpropagation until the model converges. S3. Training the contrastive learning model: Using the trajectory segment dataset preprocessed in step S1. Train the contrastive learning model constructed in step S2 until the model converges and output the trajectory representation model; S4. Unsupervised trajectory classification: After the data to be classified is preprocessed in step S1, it is input into the trajectory representation model in step S3 to obtain the output features. The output features are then clustered to achieve unsupervised trajectory classification.
2. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 1, characterized in that, The preprocessing described in step S1 includes: S11. Extract motion features from the original agricultural machinery trajectory to generate trajectory points containing the extracted motion features; S12. Use the DBSCAN density clustering algorithm to perform preliminary clustering of trajectory points containing extracted motion features to obtain pseudo-labels; S13. Based on the obtained pseudo-labels, a sliding time window is applied to the trajectory points containing extracted motion features to construct trajectory segments, resulting in a trajectory segment dataset. .
3. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 1, characterized in that, Step S21 is as follows: The trajectory segment dataset X has a shape of (Seq_len, Channels). The Channels are divided into core features and non-core features to obtain a weakly augmented sample set. and enhanced sample sets : (1) (2) in, This refers to the core features. This indicates that slight Gaussian noise was applied to the core features. This refers to non-core features, while This represents structural perturbation operations, including feature translation and local scaling; Seq_len refers to the time step of the current sample, i.e., the sliding window size, and Channels refers to the number of feature channels for each sample.
4. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 1, characterized in that, Step S23 includes: S231. Construct the spectral domain correlation modeling module, i.e., SRM. The spectral domain correlation modeling module includes a fast Fourier transform and a spectral change encoder, which takes the sample set containing the temporal features of individual samples obtained in step S22. The system maps the data to the spectral domain using Fourier transform, models global dependencies through a frequency-selective attention mechanism in a spectral transformation encoder, and outputs a global representation. With modulation vector ; S232. Construct a time-series state evolution modeling module, namely DMEN, wherein the time-series state evolution modeling module introduces a time decay factor. The timing encoder based on SRM modulation and FiLM transformation, through the dynamic gating state update mechanism of DMEN, updates the sample set containing the time features of individual samples obtained in step S22. Local modeling is performed using a dynamic memory-gated temporal network, and local representations are output. ; S233. Construct the cross-domain alignment and fusion module, namely CAF, the global representation of SRM. Local characterization of DMEN Feature-level adaptive fusion is performed through the cross-domain attention regulation mechanism of the cross-domain alignment fusion module to obtain the final encoding. .
5. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 4, characterized in that, Step S231 describes modeling global dependencies using a frequency-selective attention mechanism through a spectral variation encoder, and outputting a global representation. With modulation vector ,include: Let the hidden dimension of the contrastive learning model be First, the sample set after Fourier transform... Perform short-time spectral sensing and projection: For the sample set after Fourier transform Each feature channel is obtained by performing depthwise convolution. ,Right now (3) in, This represents the short-time spectral response after independent modeling of each channel. T The total length of the time steps. D Let be the number of feature channels, and t be the t-th time step, with values ranging from 1 to 2. , The set of real numbers is the field of numbers, indicating that the elements belong to this set of real numbers. The length of the temporal convolution kernel. For time offset index, For the first The depth convolution kernel parameters corresponding to each feature channel are processed with zero padding at the boundary positions; Then, pointwise projection is performed to obtain the spectral domain embedding. : (4) in, The channel projection weight matrix is... For bias terms, This indicates the hidden dimension of the model. For spectral domain embedding sequences; right Normalize the layers to obtain The formula is as follows: (5); Representation layer normalization, in Implement multi-layer, multi-head self-attention encoding based on this: Let the first Layer input is , where the initial value , No. The multi-head self-attention and feedforward calculation of the layer are as follows: (6) (7) (8) in, For learnable parameter matrix, Represents a query vector sequence. Represents a sequence of key vectors. Represents a sequence of value vectors. , , ; Multi-head self-attention is calculated as follows: (9) in, This represents the attention mechanism. The dimension representing a single attention head is used to scale the inner product result to stabilize the gradient. This represents the softmax function; Subsequently, residual connections and a feedforward network are used for feature updates: (10) (11) in, For the first In the layer, the intermediate hidden features obtained after "multi-head self-attention + residual connection + layer normalization" are... Indicates the first A two-layer feedforward network, Indicates the first The final output of the layer; after After layer encoding, the spectral domain context feature matrix is obtained. ; right Perform time-series pooling to obtain the global representation With modulation vector : First, perform adaptive average pooling based on time: (12) in, Indicates average pooling. t For the current time step, A global spectral domain representation of the trajectory's behavior; Then, a modulation vector is generated using a small projection network: (13) in, Represents the Gaussian error linear unit activation function. To calculate the linear mapping weights of the modulation vector m, This corresponds to the bias term.
6. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 4, characterized in that, In step S232, a basic temporal state evolution model is constructed, and a time decay factor is introduced into it. The FiLM transform based on SRM modulation yields the time-series state evolution module, DMEN, which is then used to process the sample set obtained in step S22, containing the time features of individual samples. After DMEN processing, the following is obtained ,right Perform attention readout based on the final modulation hidden layer, and output local representations through a fusion network. .
7. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 6, characterized in that, The time decay factor is introduced therein The FiLM transform based on SRM modulation yields the time-series state evolution module, DMEN, which includes: Time decay factor Designed as a learnable, exponentially decaying gate or a gate generated from time-varying features, i.e. (14) in, , It is used to generate the time decay factor. The linear mapping weight matrix, It is the corresponding bias vector. This represents the Sigmoid function. Used for dynamic decay of historical memory; Furthermore, decay is introduced into the basic temporal state evolution model—replacing the previous hidden with a decaying hidden: (15) in, This is the hidden state from the previous time step after being modulated by the time decay factor. This represents the output at time step t-1; Simultaneously using the SRM modulation vector Scale and shift for generating FiLM: (16) (17) in, This represents the tanh activation function. and These represent the scaling factor and translation factor by channel, respectively. It is the scaling factor used to generate FiLM. The linear mapping weight matrix, For the corresponding bias vector, It is the translation factor used to generate FiLM. The linear mapping weight matrix, It is the corresponding bias vector; The recursive form of DMEN is obtained as follows: (18) (19) (20) (21) (22) in, and These represent the reset gate and update gate after FiLM modulation, respectively. , , , , , , , , For learnable parameters, Indicates the candidate hidden state. These are the candidate hidden states after FiLM modulation. This represents the output at the current time step t after FiLM modulation; The sample set obtained in step S22, which contains the time features of a single sample, is then... After DMEN processing, the following is obtained ,right Perform attention readout based on the final modulation hidden layer, and output local representations through a fusion network. : The sample set obtained in step S22, which contains the time features of a single sample, After DMEN processing, the hidden sequence at all time points is obtained. The matrix formed ,right Perform attention readout based on the final modulation hidden: Set the final time or specified cutoff time as the output ,by Perform a query and calculate the historical weighted context: (23) (24) in, , and For learnable parameters, For exponential mapping, To finally modulate the hidden state, The alignment score represents the correlation between the historical time t and the current local representation. For attention weights, we have the weight representing the contribution of the t-th time in history to the current local representation. This yields the context vector: (25) And the local final representation is obtained through the fusion network: (26) in, Represents the local temporal evolution characteristics of the trajectory. It is the linear mapping weight matrix of the fusion network. It is the corresponding bias vector.
8. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 4, characterized in that, Step S233 includes: First, construct the condition vector of the fusion weights. : (27) in, Representation of the global spectral domain behavior of the trajectory. The local temporal evolution representation is obtained by DMEN + attention readout. This is a vector concatenation operation, representing the joint modeling of global and local features. Linear mapping weights are used to generate the network for conditional vectors, compressing the concatenated features into the hidden dimensions. For the corresponding bias term; Then, the fusion weights are generated: (28) in, For the linear mapping weights of the fusion weight generator, For the corresponding bias term, This is a vector per channel, used to control the fusion ratio of the two types of features; The final representation is then obtained by weighting the data by channel or scalar: (29) in, This indicates element-wise multiplication. This provides a unified trajectory representation for the encoder output.
9. The unsupervised agricultural machinery trajectory classification method based on contrastive learning according to claim 1, characterized in that, The adaptive hard-to-separate negative sample sampling strategy described in step S24 specifically involves: within each mini-batch, sampling based on the feature samples output in step S23... Dynamic selection and anchor points Samples with similar feature distances but different pseudo-labels To construct a high-quality negative sample set, the formula is as follows: (30) in, This represents the variable that minimizes the objective function, not the minimum value itself. Indicates the first i Feature representation of each anchor point sample This represents the feature representation of the j-th sample. , Let represent the pseudo-label of the class of the j-th, i-th sample; Step S25 includes: S251. Calculate the weights of each category based on the pseudo-labels obtained in step S12, and calculate the average weight of each category based on the weights. The formula is as follows: (31) (32) in, N Let X be the total number of samples in the trajectory segment dataset. For the first The pseudo-labels of the categories of each sample, For the first Number of class samples As a smoothing factor, For indicator functions, i.e. The value is 1 if it is true, and 0 otherwise. The weight coefficients for category c. For the first Number of class samples ; In obtaining Then, count the number of each category in each batch. Multiply each category by its respective weight, then sum them and take the average to obtain the average category weight in a batch. ; S252, Average category weights obtained in step S251 Calculate the weighted contrast loss: The category weights obtained in step S251 By multiplying by a contrastive loss function, the dataset is balanced. The contrastive loss function is as follows: (33) in, The high-quality negative sample set constructed in Formula 35 , The negative sample weights are adaptively adjusted based on the similarity between the sample and the anchor point, so that hard-to-distinguish samples receive a larger penalty weight. This indicates the calculation of cosine similarity. This is a temperature coefficient used to control the smoothness of similarity. For positive sample feature representation, and Semantic consistency This represents the features of negative samples; S253. Iteratively update the parameters of the comparative learning model through backpropagation until the model converges.
10. An apparatus for implementing the unsupervised agricultural machinery trajectory classification method based on contrastive learning as described in any one of claims 1-9, characterized in that, The device includes: Data acquisition and preprocessing module: Acquires raw agricultural machinery GNSS trajectory data, and performs data cleaning and feature construction processing on the raw agricultural machinery GNSS trajectory data to generate a continuous and uniform trajectory segment dataset. ; Feature enhancement module: used for the trajectory segment dataset Perform asymmetric data augmentation based on feature dimensions, where weak augmentation or indifference is applied to key feature dimensions reflecting the physical characteristics of the operation, while strong augmentation is applied to non-key feature dimensions, generating a weakly augmented sample set. and enhanced sample sets This is to improve the robustness of the model while avoiding damage to key discriminative features, and to generate multi-view trajectory samples for comparative learning. Feature extraction module: used to extract features from the input weakly augmented sample set. and enhanced sample sets The system learns discriminative trajectory feature representations, and the feature extraction module includes a feature encoder and a spectral domain correlation-dynamic memory decoupled hybrid temporal encoder; the feature encoder is used to process the input weakly enhanced sample set. and enhanced sample sets Preliminary feature encoding is performed to uniformly represent the original or enhanced trajectory sequence, and the output is denoted as... ; Spectral domain correlation-dynamic memory decoupled hybrid timing encoder is used in In a unified feature space, the multi-level temporal semantics of trajectory sequences are further modeled, which includes a global modeling submodule, a local modeling submodule, and an adaptive feature fusion submodule; Contrastive learning training module: used to train trajectory segment datasets under unsupervised conditions. The feature extraction module is pre-trained; The difficult-to-distinguish negative sample optimization submodule is used to dynamically identify difficult-to-distinguish negative samples that are close to the current trajectory sample feature distribution based on trajectory feature similarity during the contrastive learning training process, and to apply higher weights to the difficult-to-distinguish negative samples to participate in the contrastive loss calculation, so as to enhance the inter-class feature discrimination ability and compress the intra-class feature distribution, thereby improving the discriminativeness and stability of trajectory representation. Model application module: Used to deploy the trained trajectory clustering model to perform operation pattern recognition, trajectory classification or statistical analysis on newly collected agricultural machinery trajectory data, so as to support agricultural production management and intelligent decision-making applications.
Citation Information
Patent Citations
Agricultural machine trajectory classification method based on trajectory similarity measurement, computer readable storage medium and computer program product
CN119046759A
Agricultural machine track data classification method and device, electronic equipment and storage medium
CN120105238A
Trajectory abnormal route detection method and system based on self-supervised trajectory representation learning
CN120724351A