Shaplet-based time sequence contrast learning method
By employing the PIP method and multi-level contrastive learning, the problems of low feature extraction efficiency and insufficient robustness of the shapelet method in existing technologies are solved, achieving high accuracy and stability in time series classification and improving the model's classification accuracy and feature recognition capabilities.
Patent Information
- Application Number
- CN202511609449.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-05
- Publication Date
- 2026-01-09
AI Technical Summary
Existing shapelet methods suffer from low feature extraction efficiency, high computational complexity, and insufficient robustness. They struggle to effectively distinguish between different categories of time series samples and neglect the importance of local patterns, leading to a decline in classification performance.
The Perceptual Significance Point (PIP) method is used to extract key point sequences. Noise is filtered out through two-stage clustering. Mix-shapelet and sample-shapelet contrast loss functions are designed between samples and within classes. End-to-end training is performed in combination with encoder and mapping head to optimize the feature space.
It improves the accuracy and feature robustness of time series classification, effectively captures global and local patterns, and enhances the model's discriminative and generalization performance.
Smart Images

Figure CN121301978A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of time series data analysis technology, specifically a time series contrastive learning method based on shapelets. Background Technology
[0002] Time series data is widely used in fields such as industrial monitoring, medical signals, and financial forecasting. Its complexity and diversity pose significant challenges to classification and pattern recognition. In recent years, shapelet techniques have been proposed to extract key local segments from time series data. Comparing shapelet features from different categories can improve classification accuracy. However, existing shapelet methods typically suffer from the following problems:
[0003] 1) The feature extraction efficiency is low, the number of candidate shapelets is huge, the search and filtering costs are high, and it is difficult to apply it to large-scale datasets.
[0004] 2) The ability to distinguish between categories is limited. Traditional methods mainly rely on similarity measures and do not make full use of the joint representation of global and local features.
[0005] 3) The model lacks robustness. In time series with a lot of noise or outliers, the shapelet representation is easily disturbed, resulting in a decrease in classification performance.
[0006] In summary, existing technologies typically rely on global features or manually designed statistical features, which have limited ability to capture local patterns and are difficult to effectively distinguish between different categories of time series samples, resulting in the following problems:
[0007] 1) Traditional shapelet mining methods rely on exhaustive or heuristic rules, which are computationally complex and susceptible to noise, resulting in redundant or discriminative extracted shapelets; 2) Existing time series contrastive learning methods only utilize the global features of the entire sequence, ignoring local patterns with class discriminative power in the sequence, making it difficult for the model to capture key time segment features; 3) Traditional shapelet-based classification frameworks use fixed feature distance or linear discriminative methods, which cannot achieve the synergistic optimization of global semantic information and local temporal patterns through end-to-end training mechanisms.
[0008] Therefore, there is an urgent need for a time series classification method that can efficiently extract representative shapelets, fuse global and local features, and enhance representation capabilities through contrastive learning, so as to improve classification accuracy, feature robustness, and algorithm scalability. Summary of the Invention
[0009] The purpose of this invention is to address the shortcomings of existing technologies by providing a shapelet-based time series contrastive learning method. This method employs Perceptual Important Points (PIP) extraction to obtain keypoint sequences, extracts segments between adjacent keypoints to generate a candidate shapelet set, and uses two-stage clustering to filter out noise and select representative shapelets. During the training phase, three contrastive loss functions are designed: inter-sample contrast, intra-class mix-shapelet contrast, and sample-shapelet contrast, guiding the model to learn representations with stronger discriminative power and local sensitivity. Finally, fine-tuning and prediction are performed using labeled samples to achieve high-precision time series classification. This method effectively enhances the model's ability to recognize local patterns in time series, improves classification accuracy and feature robustness, and can be widely applied in scenarios such as industrial equipment condition monitoring, medical physiological signal classification, financial transaction behavior modeling, speech emotion recognition, and other time series classification, showing promising application prospects.
[0010] The technical solution to achieve the objective of this invention is: a time series contrastive learning classification method based on shapelets, characterized by the following steps:
[0011] S100: Apply the Perceived Significance Point (PIP) method to the time series to identify key turning points, and extract sequence segments between adjacent key points to obtain a set of candidate shapelets. By calculating the vertical distance from each point in the original sequence to the current multi-segment polyline, iteratively select the point with the largest distance as the key point until the distance is less than a set threshold or the maximum number is reached, forming a set of key points that retains the local shape.
[0012] S200. Perform two-stage clustering on the candidate shapelets, removing noisy segments and retaining each cluster center as a representative shapelet of the class, which includes:
[0013] S210. In the first stage of clustering, similar segments are initially aggregated based on the shape similarity of candidate shapelets measured by Euclidean distance. The Euclidean distance is calculated by the following formula:
[0014] .
[0015] in, Indicates the first The candidate shapelet and the first Euclidean distance between candidate shapelets express The Feature components at each time point express The The feature components at each time point, where L represents the length of the shapelet.
[0016] S220. In the second stage of clustering, the cluster structure is further refined using the Dynamic Time Warping (DTW) distance to remove isolated noise shapelets, and the cluster centers are selected as the final representative shapelets. The Dynamic Time Warping distance is calculated by the following formula:
[0017] .
[0018] in, Indicates the first The candidate shapelet and the first Dynamic time-warped distance between candidate shapelets express The Feature components at each time point express The Each time point feature component Represents a set of dynamically time-warped paths. Indicates a sample in a regular path The Time points and samples The Alignment of time points.
[0019] S300. Input the original sequence and representative shapelet into the time series encoder and mapping module respectively, and map them to the contrastive learning feature space, which includes:
[0020] S310. Input the original sequence and representative shapelet into the encoder to extract the temporal and local feature information of the time series. The extracted features are calculated using the following formula:
[0021] , .
[0022] in, It is the first Input time series data, Indicates parameters For the weight encoder, Indicates input The feature vector obtained after encoder processing; No. One input shapelet, express The feature vector obtained after processing by the encoder.
[0023] S320. Perform max pooling on the temporal features output by the encoder to compress the temporal dimension and retain the most representative feature information, forming a fixed-length vector representation. The max pooling is calculated by the following formula:
[0024] , .
[0025] in, and Representing input features or In the Feature components at each time step and It is the output feature obtained after max pooling operation.
[0026] S330. The pooled feature input projection head is mapped to the contrastive learning feature space through a nonlinear transformation to form a normalized feature vector; the feature input projection head output by the encoder is subjected to feature dimension mapping and nonlinear transformation to obtain a representation for contrastive learning. Calculated by the following formula:
[0027] , .
[0028] in, Indicates parameters For the weight mapping header, and It is the output feature representation obtained after processing by the mapping head.
[0029] S400. Based on time series and shapelet representations, three contrastive loss functions are designed to optimize model parameters. The design of the three losses includes:
[0030] S410. In inter-sample contrast loss, different data augmentation operations (such as random cropping) are performed on the same original sample, resulting in augmented samples. Compared with the original sample In a batch of model training, all samples except the target sample and its positive samples are treated as negative samples. This is referred to as the instance loss. Calculated by the following formula:
[0031] .
[0032] in, Represents cosine similarity. For temperature parameters, It is an enhanced sample The feature vector obtained after feature extraction Indicates sample Features Its positive sample features The similarity between them (usually calculated using cosine similarity, etc.). Indicates sample Features Its negative sample features Similarity between them It is an exponential function used to convert similarity into a probabilistic form. It is a logarithmic function that converts probability into loss value, making the model focus more on sample pairs with high discriminative power.
[0033] S420, For categories Representative shapelet Positive samples are mix-shapelet features within the same category, meaning they belong to the same category. The features of multiple shapelets are fused to generate a mix-shapelet feature. , with the original shapelet features This constitutes a positive sample pair. (The pair does not belong to the category.) Other categories (such as) , Each shapelet is then merged within its class to generate a corresponding mix-shapelet feature. ( These features are similar to the original shapelet features. The mix-shapelet features, which constitute negative sample pairs, are calculated by the following formula:
[0034] .
[0035] in, Indicates belonging to a category The total number of representative shapelets.
[0036] Intraclass mix-shapelet contrast loss Calculated by the following formula:
[0037] .
[0038] in, Indicates belonging to a category Representative shapelet eigenvectors, It is a category The mix-shapelet feature is used to enhance aggregation between shapelets of the same type. Indicates belonging to the rest Mix-shapelet features of the class. This loss function maximizes the similarity between shapelets and mix-shapelets of the same class, and minimizes the similarity between shapelets and mix-shapelets of different classes, allowing the model to learn shapelet feature representations with intra-class consistency and inter-class discriminativeness, thereby improving the model's ability to recognize local feature patterns;
[0039] S430. In the sample-shapelet contrastive loss (Ins-Shapelet Loss), for samples belonging to the category... samples Positive samples are mix-shapelet features within their respective categories. Negative samples are other categories mix-shapelet features .
[0040] The sample-shapelet contrast loss Calculated by the following formula:
[0041] .
[0042] in, It is a sample Feature representation, It is a category The mix-shapelet feature, It is a category The mixed-shapelet feature is used. This loss function associates samples with shapelets within their class and distinguishes samples from shapelets of other classes, allowing the model to learn discriminative features at both the sample level and the local shapelet level, thereby improving the model's ability to jointly recognize overall and local patterns of samples.
[0043] The total loss of the three types of losses is calculated by the following formula:
[0044] ,
[0045] in, , , These are the parameters of the three loss functions. and These represent the original time series and the number of representative shapelets, respectively. By jointly optimizing the above loss function, the parameters of the encoder and the mapping head are updated, enabling the feature space to simultaneously represent global trends and local patterns.
[0046] S500: Fine-tuning is performed using labeled samples. The classifier parameters are optimized through the cross-entropy loss function. After fine-tuning, the samples are sequentially input into the encoder and classifier to obtain the final predicted category. Specifically, this includes:
[0047] S510. Fine-tune the trained model using labeled samples, optimize the classifier parameters through the cross-entropy loss function, and improve the model's adaptability to limited labeled data through the encoder. and classifier h Predicted Samples The category is calculated by the following formula:
[0048]
[0049] in, Indicates sample The predicted category probability distribution.
[0050] The cross-entropy loss is calculated by the following formula:
[0051] .
[0052] in, It is the total number of categories, that is, the number of categories in the classification task; This refers to the number of input time series samples; It is a sample The one-hot encoding of the true label represents that if the sample belongs to the first... The value is 1 if the condition is met, and 0 otherwise. Model on samples Belongs to the The predicted probability of a class.
[0053] S520. Input the test samples into the encoder and classifier sequentially, and output the predicted category of the time series to verify the model's classification performance. The predicted category is calculated by the following formula:
[0054]
[0055] in, This represents the input test sample. This represents the predicted category after passing through the encoder and classifier.
[0056] Compared with the prior art, the present invention has the following beneficial technical effects and significant technical progress:
[0057] 1) Two-stage clustering improves shapelet quality: Combining Euclidean distance and DTW distance as dual metrics, noise and redundant subsequences are filtered out to ensure that the final representative shapelet has good distinguishability and stability;
[0058] 2) Multi-level contrastive learning enhances discriminative power: By jointly optimizing the inter-sample, intra-class shapelet, and sample-shapelet contrastive losses, the model can simultaneously capture global temporal features and local pattern features.
[0059] 3) End-to-end training and fine-tuning mechanism: Global optimization of the feature space is achieved through a unified encoder and mapping head structure, and the classification boundary is further strengthened in the fine-tuning stage to improve the generalization performance of the model;
[0060] 4) High interpretability: The introduction of shapelets enables the model to explain the classification criteria at the feature level, which meets the needs of industrial and medical fields for model transparency. Attached Figure Description
[0061] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0062] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be described below in conjunction with the accompanying drawings.
[0063] The specific implementation methods will be described in further detail. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Other embodiments obtained by those skilled in the art based on the embodiments of the present invention without creative effort are all within the scope of protection of the present invention.
[0064] Example 1
[0065] See Figure 1 This embodiment provides a time series classification method based on shapelets, the overall process of which includes the following steps: S100: Key point extraction and candidate shapelet generation
[0066] This step aims to identify representative local structures from the original time series, providing a foundation for subsequent feature clustering and learning. Specifically, the time series is represented by the following formula:
[0067] .
[0068] in, The sequence length is given.
[0069] The PIP (Piecewise Importance Points) method is used to extract the key point set. The PIP algorithm selects key points step by step by calculating the importance of each time point in fitting the overall trend. The algorithm steps are as follows:
[0070] 1) Initialize the set of key points containing the start and end points of the time series. ;
[0071] 2) Among all non-key points, calculate the perpendicular distance from each point to the line connecting it to the current key point; select the point with the largest distance as the new key point and add it to the set. ;
[0072] 3) Repeat steps (2)–(3) until the set number of key points or error threshold is reached, and finally obtain the key point set shown in the following formula. :
[0073] .
[0074] Among them, the time segments between three adjacent key points It is considered a candidate shapelet.
[0075] Each candidate shapelet The local morphological features of the sequence in that interval were preserved.
[0076] S200: Two-stage clustering screening shapelet
[0077] To reduce redundancy and noise in candidate shapelets, this step employs a two-stage clustering strategy to obtain representative shapelets, specifically including:
[0078] S210: First-stage clustering (Euclidean distance)
[0079] First, candidate shapelets are quickly clustered using Euclidean distance to initially merge segments with similar shapes. The Euclidean distance is defined by the following formula:
[0080] .
[0081] in, The length of the shapelet is given. Density clustering algorithms (such as DBSCAN) are used to cluster the distance matrix, resulting in several initial clusters.
[0082] For the initial clusters generated after clustering, further screening is required to retain highly representative shapelets: calculate the density of each initial cluster (measured by the ratio of the number of shapelets within the cluster to the spatial range of the cluster). If the cluster density is lower than the preset threshold, or if the shapelet distribution is too sparse and no effective cluster is formed (such as noise points in DBSCAN), then the shapelets corresponding to these clusters are directly discarded, and only the initial clusters with the required density and complete structure and their contained shapelets are retained.
[0083] S220: Second-stage clustering (DTW distance)
[0084] For each sample within an initial cluster, further fine-grained clustering is performed using the DTW (Dynamic Time Warping) distance, as shown in the following formula:
[0085] .
[0086] in, Indicates the time alignment path.
[0087] DTW clustering can further merge similar local patterns and calculate the center shapelet of each cluster, obtaining each cluster center as a representative shapelet.
[0088] S300. Map the original time series and representative shapelets to a unified feature space to obtain fixed-dimensional feature vectors; this includes:
[0089] S310. Input the original sequence and representative shapelet into the encoder to extract the temporal and local feature information of the time series. The extracted features are calculated using the following formula:
[0090] , .
[0091] in, It is the first Input time series data, Indicates parameters For the weight encoder, Indicates input The feature vector obtained after encoder processing; No. One input shapelet, express The feature vector obtained after processing by the encoder.
[0092] S320. Perform max pooling on the temporal features output by the encoder to compress the temporal dimension and retain the most representative feature information, forming a fixed-length vector representation. The max pooling is calculated by the following formula:
[0093] , .
[0094] in, and Representing input features or In the Feature components at each time step and It is the output feature obtained after max pooling operation.
[0095] S330. The pooled feature input projection head is mapped to the contrastive learning feature space through a nonlinear transformation to form a normalized feature vector. The feature input projection head output by the encoder is then subjected to feature dimension mapping and nonlinear transformation to obtain a representation for contrastive learning. Calculated by the following formula:
[0096] , .
[0097] in, Indicates parameters For the weight mapping header, and It is the output feature representation obtained after processing by the mapping head. S400. Based on time series and shapelet representations, three contrastive loss functions are designed to optimize model parameters. The designs of the three losses are as follows:
[0098] S410. In inter-sample contrast loss, different data augmentation operations (such as random cropping) are performed on the same original sample, resulting in augmented samples. Compared with the original sample In a batch of model training, all samples except the target sample and its positive samples are treated as negative samples. This is referred to as the instance loss. Calculated by the following formula:
[0099] .
[0100] in, Represents cosine similarity. For temperature parameters, It is an enhanced sample The feature vector obtained after feature extraction Indicates sample Features Its positive sample features The similarity between them (usually calculated using cosine similarity, etc.). Indicates sample Features Its negative sample features Similarity between them It is an exponential function used to convert similarity into a probabilistic form. It is a logarithmic function that converts probability into loss value, making the model focus more on sample pairs with high discriminative power.
[0101] S420, For categories Representative shapelet Positive samples are mix-shapelet features within the same category, meaning they belong to the same category. The features of multiple shapelets are fused to generate a mix-shapelet feature. , with the original shapelet features This constitutes a positive sample pair. (The pair does not belong to the category.) Other categories (such as) , Each shapelet is then merged within its class to generate a corresponding mix-shapelet feature. ( These features are similar to the original shapelet features. The mix-shapelet features, which constitute negative sample pairs, are calculated by the following formula:
[0102] .
[0103] in, Indicates belonging to a category The total number of representative shapelets.
[0104] Intraclass mix-shapelet contrast loss Calculated by the following formula:
[0105] ,
[0106] in, Indicates belonging to a category Representative shapelet eigenvectors, It is a category The mix-shapelet feature is used to enhance aggregation between shapelets of the same type. Indicates belonging to the rest Mix-shapelet features of the class. This loss function maximizes the similarity between shapelets and mix-shapelets of the same class, and minimizes the similarity between shapelets and mix-shapelets of different classes, allowing the model to learn shapelet feature representations with intra-class consistency and inter-class discriminativeness, thereby improving the model's ability to recognize local feature patterns.
[0107] S430. In the sample-shapelet contrastive loss (Ins-Shapelet Loss), for samples belonging to the category... samples Positive samples are mix-shapelet features within their respective categories. Negative samples are all samples that do not belong to the category. Other categories mix-shapelet features The sample-shapelet contrastive loss Calculated by the following formula:
[0108] .
[0109] in, It is a sample Feature representation, It is a category The mix-shapelet feature, It is a category The mixed-shapelet feature is used. This loss function associates samples with shapelets within their class and distinguishes samples from shapelets of other classes, allowing the model to learn discriminative features at both the sample level and the local shapelet level, thereby improving the model's ability to jointly recognize overall and local patterns of samples.
[0110] The total loss of the three types of losses is calculated by the following formula:
[0111] .
[0112] in, , , These are the parameters of the three loss functions. and These represent the original time series and the number of representative shapelets, respectively. By jointly optimizing the above loss function, the parameters of the encoder and the mapping head are updated, enabling the feature space to simultaneously represent global trends and local patterns.
[0113] S500: Fine-tuning is performed using labeled samples. The classifier parameters are optimized using the cross-entropy loss function. After fine-tuning, the samples are sequentially input into the encoder and classifier to obtain the final predicted category. This includes:
[0114] S510. Fine-tune the trained model using labeled samples, optimize the classifier parameters through the cross-entropy loss function, and improve the model's adaptability to limited labeled data through the encoder. and classifier h Predicted Samples The category is calculated by the following formula:
[0115] .
[0116] Indicates sample The predicted category probability distribution.
[0117] The cross-entropy loss function is calculated by the following formula:
[0118] .
[0119] in, It is the total number of categories, that is, the number of categories in the classification task; This refers to the number of input time series samples; It is a sample The one-hot encoding of the true label represents that if the sample belongs to the first... The value is 1 if the condition is met, and 0 otherwise. Model on samples Belongs to the The predicted probability of a class.
[0120] S520. Input the test samples into the encoder and classifier sequentially, and output the predicted category of the time series to verify the model's classification performance. The predicted category is calculated by the following formula:
[0121] .
[0122] in, This represents the input test sample. This represents the predicted category after passing through the encoder and classifier.
[0123] Through the above steps, this invention can stably extract representative local morphological features in small sample scenarios, realize structured time series comparative learning, and effectively improve the classification accuracy and interpretability of the model.
[0124] The above is merely a further description of the present invention and is not intended to limit the scope of this patent. Any equivalent implementation of the present invention should be included within the scope of the claims of this patent.
Claims
1. A time series comparison learning method based on shapelets, characterized in that, The method specifically includes the following steps: S100. Extract key points from segments of the original time series sample, obtain the key turning points of the time series, and generate multiple candidate shapelet segments using these as boundaries. S200. Perform two-stage clustering on each candidate shapelet fragment, remove noisy fragments, and retain each cluster center as a representative shapelet set of the class. S300. Map the original time series and the representative shapelet set to a unified feature space to obtain a fixed-dimensional feature vector. S400. Based on the representation of time series and shapelet sets, design an inter-sample contrast loss function, an intra-class mix-shapelet contrast loss function, and a sample-shapelet contrast loss function to optimize model parameters. The inter-sample contrast loss... Calculated by the following formula: ; in, Cosine similarity; For temperature parameters; To enhance the sample The feature vector obtained through feature extraction; For the sample Features Its positive sample features The similarity between them; For the sample Features Its negative sample features The similarity between them; This is an exponential function used to convert similarity into a probabilistic form; Using a logarithmic function, the probability is converted into a loss value, making the model focus more on sample pairs with high discriminative power; The intra-class mix-shapelet contrast loss Calculated by the following formula: ; in, To belong to category Representative shapelet eigenvectors; For category The feature representation of a shapelet is the average feature obtained after a mixture transformation, i.e., the category. The mix-shapelet feature is used to enhance the aggregation between shapelets of the same type; For belonging to the rest The mix-shapelet feature of the class; The sample-shapelet contrast loss Calculated by the following formula: ; in, For the sample Feature representation; For category The mix-shapelet feature; For category The mix-shapelet feature; S500: Fine-tune using labeled samples, optimize the MLP classifier parameters using the cross-entropy loss function, and then input the samples into the encoder and MLP classifier in sequence to obtain the predicted class.
2. The time series comparison learning method based on shapelets according to claim 1, characterized in that, The two-stage clustering in step S200 uses the DBSCAN algorithm based on Euclidean distance in the first stage, with 0.25 times the average distance as the neighborhood radius and 0.25 times the number of candidate shapelets as the minimum number of neighbors to initially eliminate noisy shapelets. The second-stage clustering refines the results of the first-stage clustering based on the DTW distance. It re-aggregates similar shapelets and calculates the representative shapelet of the cluster center. The specific operation is as follows: S210. Group the candidate shapelet fragments by length, calculate the similarity between shapelets based on Euclidean distance, and perform preliminary clustering of the candidate shapelets to obtain several initial clusters. The Euclidean distance is calculated by the following formula: ; in, Indicates the first The candidate shapelet and the first Euclidean distance between candidate shapelets; express The Feature components at each time point; express The The feature components at each time point; L represents the length of the shapelet; S220. Perform fine-grained clustering on the cluster centers of all initial clusters based on the dynamic time-warped distance, remove noisy shapelets, and retain the cluster centers of each cluster to form a representative shapelet set for each class. The dynamic time-warped distance is calculated by the following formula: ; in, Indicates the first The candidate shapelet and the first Dynamic time-warped distance between candidate shapelets; express The Feature components at each time point; express The Each time point feature component; Represents a set of dynamically time-warped paths; Samples in the regularized path The Time points and samples The Alignment of time points.
3. The time series comparison learning method based on shapelets according to claim 1, characterized in that, The specific operation of step 300 is as follows: S310. Input the original sequence and a representative shapelet set into the encoder to extract the temporal and local feature information of the time series. The encoder uses parameters... Encoder for weights Features are extracted using the following formula: , ; in, For the first One input time series data; Indicates parameters An encoder for weights; enter The feature vector obtained after encoder processing; For the first One input shapelet; for The feature vector obtained after encoder processing; S320. Perform max pooling on the temporal features output by the encoder to compress the temporal dimension and retain the most representative feature information, forming a fixed-length vector representation. The max pooling is calculated by the following formula: , ; in, and Input features or In the Feature components at each time step; and The output features are obtained after max pooling. S330. The pooled feature input mapping head is mapped to the contrastive learning feature space through a nonlinear transformation to form a normalized feature vector. The feature input mapping head output by the encoder is then subjected to feature dimension mapping and a nonlinear transformation to obtain a representation for contrastive learning. The mapping head uses parameters... Mapping header for weights Its calculation is expressed by the following formula: , ;in, Indicates parameters The mapping header for weights; and It is the output feature representation obtained after processing by the mapping head.
4. The time series comparison learning method based on shapelets according to claim 1, characterized in that, The specific operation of step 400 is as follows: S410, Inter-sample contrast loss Performing different data augmentation operations on the same original sample generates augmented samples. Compared with the original sample In a batch of model training, all samples except the target sample and its positive samples are considered negative samples. The inter-sample contrast loss is... Calculated by the following formula: ; in, Cosine similarity; For temperature parameters; To enhance the sample The feature vector obtained through feature extraction; For the sample Features Its positive sample features The similarity between them; For the sample Features Its negative sample features The similarity between them; This is an exponential function used to convert similarity into a probabilistic form; Using a logarithmic function, the probability is converted into a loss value, making the model focus more on sample pairs with high discriminative power; S420, intra-class mix-shapelet contrast loss For belonging to category Representative shapelet Positive samples are mix-shapelet features within the same category, meaning they belong to the same category. The features of multiple shapelets are fused to generate a mix-shapelet feature. and the original shapelet features Constitutes positive sample pairs, and pairs that do not belong to the category. Other categories of shapelets are fused within their respective categories to generate corresponding mix-shapelet features. ( These features are different from the original shapelet features. The mix-shapelet features, which constitute negative sample pairs, are calculated by the following formula: ; in, To belong to category The total number of representative shapelets; The intra-class mix-shapelet contrast loss Calculated by the following formula: ; in, To belong to category Representative shapelet eigenvectors; For category The mix-shapelet feature; For belonging to the rest The mix-shapelet feature of the class; The intra-class mix-shapelet contrast loss By maximizing the similarity between shapelets and similar mix-shapelets, and minimizing the similarity between shapelets and dissimilar mix-shapelets, the model learns shapelet feature representations with intra-class consistency and inter-class discriminativeness, thereby improving the model's ability to recognize local feature patterns. S430, Sample-shapelet contrastive loss For belonging to category samples Positive samples are those belonging to the category. mix-shapelet features Negative samples are other categories mix-shapelet features The sample-shapelet contrastive loss It can be expressed as follows: ; in, For the sample Feature representation; For category The mix-shapelet feature; For category The mix-shapelet feature; The sample-shapelet contrast loss By associating samples with shapelets within a class and distinguishing samples from shapelets of other classes, the model learns discriminative features at both the sample level and the local shapelet level, thereby improving the model's ability to jointly recognize overall and local patterns of samples. The total loss of the above three losses : ; in, , , These are the parameters of the three loss functions; and These represent the number of the original time series and the number of representative shapelets, respectively. By jointly optimizing the above loss function, the parameters of the encoder and the mapping head are updated, enabling the feature space to simultaneously represent global trends and local patterns.
5. The time series comparison learning method based on shapelets according to claim 1, characterized in that, The specific operation of step 500 is as follows: S510. Fine-tune the trained model using labeled samples, optimize the MLP classifier parameters using the cross-entropy loss function, and then use the encoder... and MLP classifier h Predicted Samples The category is calculated as follows: ; For the sample The predicted category probability distribution; The cross-entropy loss is calculated by the following formula: ; in, This represents the total number of categories, i.e., the number of categories in the classification task. The number of time series samples to input; For the sample The one-hot encoding of the true label represents that if the sample belongs to the first... The value is 1 if the condition is met, and 0 otherwise. For the model to sample Belongs to the The predicted probability of a class; S520. Input the test samples into the encoder and MLP classifier sequentially. The output is the predicted category of the time series, thus verifying the model's classification performance. The predicted category is calculated using the following formula: ; For the input test sample; The predicted categories for the encoder and classifier.
6. The time series contrastive learning method based on shapelets according to claims 1 and 4, characterized in that, The encoder is a dilated causal convolutional neural network used to capture local and global features of a time series; the mapping head includes two fully connected layers and one normalization layer, and its input dimension is equal to the encoder output dimension.
7. The time series contrastive learning method based on shapelets according to claims 1 and 5, characterized in that, The MLP classifier includes at least one hidden layer and a non-linear activation function. The output layer is connected to Softmax to generate class probabilities. The number of nodes and depth of the hidden layer are adjusted according to the data scale to increase the number of labeled samples used in the Finetune stage.