Adaptive time series analysis method based on dynamic prompting mechanism and related device
Through the dynamic prompt mechanism and adaptive window optimization, the adaptability and efficiency problems of traditional time series analysis methods in complex data are solved, and efficient and explainable time series prediction is achieved.
Patent Information
- Application Number
- CN202510093014.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-21
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2045-01-21
AI Technical Summary
Existing time series analysis methods have difficulty adapting flexibly to different time scales and patterns when processing complex time series data that are non-stationary, nonlinear, and high-dimensional. They also lack computational efficiency and model interpretability. Directly applying large language models faces the challenges of large computational resource requirements and adapting to specific domain knowledge.
An adaptive time series analysis method based on a dynamic prompt mechanism is adopted. Time series subsequences are constructed through sliding windows, dynamic prompts are generated using a dynamic prompt pool, and a large language model is combined for analysis. An adaptive window length optimization mechanism is set up, and reinforcement learning and interpretability modules are introduced to optimize the prediction strategy.
It enables flexible adaptation to analyses of different time scales and patterns in complex time series data, improving forecast accuracy and the robustness and generalization capabilities of the model while maintaining computational efficiency and interpretability.
Smart Images

Figure CN120011423B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the technical field of time series data analysis, and particularly relates to a self-adaptive time series analysis method based on a dynamic prompting mechanism and related devices. BACKGROUND
[0002] In the field of modern data science and artificial intelligence, time series analysis plays a crucial role and is widely used in meteorological forecasting, intelligent question answering, industrial production monitoring, and other fields. With the advent of the big data era and the popularization of Internet of Things technology, the scale, complexity, and diversity of time series data are increasing dramatically, posing a huge challenge to existing traditional time series analysis methods.
[0003] Currently, traditional time series analysis methods, such as the Autoregressive Integrated Moving Average (ARIMA) model, perform well for simple, stationary time series data. However, these methods often struggle with complex, nonstationary, nonlinear, and high-dimensional time series data. In recent years, deep learning methods, particularly recurrent neural networks (RNNs) and long short-term memory (LSTM) networks, have made significant progress in time series analysis. While capable of capturing complex temporal dependencies, deep learning methods still face challenges in processing long and multivariate time series, particularly in terms of computational efficiency and model interpretability. Recently, methods based on the Transformer architecture have been proposed that achieve efficient processing of long-range time series data through a self-attention mechanism. While these methods excel at capturing long-term dependencies, they still rely on fixed-length input windows and lack the flexibility to adapt to temporal patterns of varying scales. In addition, graph neural networks (GNNs) have shown potential in processing data with complex spatial-temporal dependencies. Graph structures can effectively capture spatial-temporal dependencies in time series data, but such methods usually require a predefined graph structure and have limitations when dealing with dynamically changing time series relationships. Furthermore, hybrid models such as N-BEATS (Neural Basis Expansion Analysis for Interpretable Time Series Forecasting) attempt to combine deep learning and classical time series decomposition techniques to improve model interpretability while maintaining forecast accuracy. However, such methods still face challenges when dealing with highly nonlinear and non-stationary time series. In summary, existing traditional time series analysis methods still have some shortcomings. In order to flexibly adapt to different time scales and complex patterns, efficiently utilize historical knowledge, and maintain good computational efficiency and model interpretability, it is urgent to design new time series analysis methods.
[0004] Recently, large language models (LLMs) have made breakthroughs in various natural language processing tasks, prompting researchers to explore their application in time series analysis. Studies have shown that LLMs have zero-sample time series prediction capabilities, but directly applying large language models to time series analysis faces challenges such as large computing resource requirements and difficulty adapting to specific domain knowledge. Summary of the Invention
[0005] The present application aims to provide a dynamic prompt mechanism-based adaptive time series analysis method and related device to solve one or more of the above technical problems. The dynamic prompt mechanism-based adaptive time series analysis scheme disclosed by the present application is a new scheme based on a large language model. The large language model used has good adaptability, robustness, generalization ability and prediction accuracy, can flexibly adapt to different time scales and complex patterns, can efficiently utilize historical knowledge, and also maintains computational efficiency and model interpretability.
[0006] To achieve the above-mentioned purpose, the present application adopts the following technical solutions:
[0007] In the first aspect of the present application, a dynamic prompt mechanism-based adaptive time series analysis method is provided, comprising the following steps:
[0008] Obtain the time series data to be analyzed, and use a sliding window method to construct time series subsequences;
[0009] Extract the feature representation of each time series subsequence, and generate a dynamic prompt for each time series subsequence based on a dynamic prompt pool;
[0010] Combine the feature representation of the selected time series subsequence with the dynamic prompt based on the analysis task type of the time series data to be analyzed, and input the combination result into a large language model to obtain the analysis result of the time series data through the large language model;
[0011] The large language model is provided with an adaptive window length optimization mechanism.
[0012] The adaptive time series analysis method of the present application is further improved in that, in the step of generating a dynamic prompt for each time series subsequence based on a dynamic prompt pool,
[0013] The dynamic prompt pool is an initialized dynamic prompt pool or a dynamically updated dynamic prompt pool; wherein,
[0014] The acquisition step of the initialized dynamic prompt pool includes: using a pre-trained Transformer model to encode the training data to generate an initial key-value pair set, and then optimizing the prompt pool structure through clustering to obtain the initialized dynamic prompt pool; wherein each prompt is represented as a key-value pair (k, v); k d is a key vector, R d is a d-dimensional real vector; v l ×d is a value matrix, d is the embedding dimension, l is the prompt length, R l×d is an l-row d-column real matrix;
[0015] After the initialized dynamic prompt pool is dynamically updated based on the analysis result of the time series data, a dynamically updated dynamic prompt pool is obtained.
[0016] Further improvement of the adaptive time series analysis method of the application is that in the step of generating dynamic prompts for each time series subsequence based on the dynamic prompt pool,
[0017] For the time series subsequence S t , the cosine similarity sim(f t , k t ) of the feature representation f m of the time series subsequence S t and each key vector k m in the dynamic prompt pool is calculated, and the expression is:
[0018] sim(f t , k m ) = (f t ·k m ) / (‖f t ‖‖k m ‖);
[0019] In the formula, f t ·k m represents the dot product of vectors, and ‖f t ‖‖k m ‖ represents the multiplication of vector modules;
[0020] Based on the ranking of cosine similarity, the K prompts with the highest similarity are selected to form a prompt value matrix;
[0021] An attention mechanism is applied to the prompt value matrix to generate the final dynamic prompt, which is represented as:
[0022] p t =∑ i α i v i ;
[0023]
[0024] In the formula, p t represents the generated final dynamic prompt; α i represents the attention weight of the i-th prompt; represents the transpose of f t ; v i represents the value vector of the i-th prompt; W q represents a learnable query matrix parameter; k i represents the key vector of the i-th prompt.
[0025] Further improvement of the adaptive time series analysis method of the present application is that, based on the analysis task type of the time series data to be analyzed, the step of combining the feature representation of the selected time series sub-sequence with the dynamic prompt,
[0026] For the prediction task, the feature representation of the selected time series sub-sequence is combined with the dynamic prompt using a feedforward neural network;
[0027] For missing data imputation, the feature representation of the selected time series sub-sequence is combined with the dynamic prompt using a gated recurrent unit.
[0028] Further improvement of the adaptive time series analysis method of the present application is that, in the adaptive window length optimization mechanism, a set of window length candidates is pre-set, a time series sub-sequence is constructed for each candidate window length and features are extracted, then a comprehensive score is calculated for each window length, and based on the comprehensive score of each candidate window length, the optimal window length is dynamically selected; wherein,
[0029] The calculation expression of the comprehensive score is:
[0030]
[0031] In the formula, τ m represents the mth candidate window length; k j represents the jth key vector; represents the prediction mean square error when using the window length τ m ; represents the similarity between the features extracted under the window length τ m and the prompt key vector k j ; represents the information entropy of the features extracted under the window length τ m ; α, β, γ respectively represent the weight coefficients of each index; N represents the number of evaluated prompt key vectors;
[0032] The optimal window length τ opt selected dynamically is:
[0033]
[0034] Further improvement of the adaptive time series analysis method of the present application is that, in the adaptive window length optimization mechanism, a smoothing mechanism is also introduced; wherein,
[0035] τ t = (1- λ) τ t-1 + λ τ opt ;
[0036] In the formula, λ is a smoothing factor.
[0037] The adaptive time series analysis method of the present application is further improved in that the large language model is also provided with a feedback optimization mechanism based on reinforcement learning, and the decision strategy is optimized using the policy gradient method.
[0038] The adaptive time series analysis method of the present application is further improved in that the large language model also uses the SelfExtend method to process the input sequence.
[0039] The adaptive time series analysis method of the present application is further improved in that the large language model is also provided with an explainability module; wherein,
[0040] The explainability module is used to calculate the contribution of each prompt to the final prediction using SHAP values, and the calculation expression is:
[0041]
[0042] In the formula, φ n represents the SHAP value of the nth feature; F represents the set of all features; S represents a subset of features that does not contain the nth feature; |S| represents the number of features in the subset S; |F| represents the total number of features; f S (x S ) represents the model output using only the feature subset S for prediction; f S∪{n} (x S∪{n} ) represents the model output after adding the nth feature; is the combination weight, used to balance the influence of different feature combinations;
[0043] The explainability module is also used to visualize the attention weight α i in the dynamic prompt generation process, and uses the integrated gradient method to calculate the importance score of the input feature, and the calculation expression is:
[0044]
[0045] In the formula, IG n (x) represents the integrated gradient value of the nth feature x; x represents the actual feature value vector of the current input, x n represents the actual input value of the nth feature; x' represents the baseline input, which is a reference point value, x' n represents the baseline input value of the nth feature; f represents the prediction model function; ω represents the integral path parameter; represents the partial derivative of the model with respect to the nth feature.
[0046] In the second aspect of the present application, a dynamic prompt mechanism-based adaptive time series analysis system is provided, comprising:
[0047] a time series subsequence construction module configured to obtain time series data to be analyzed and construct time series subsequences using a sliding window method;
[0048] a dynamic prompt generation module configured to extract feature representations of the time series subsequences and generate dynamic prompts for the time series subsequences based on a dynamic prompt pool;
[0049] an analysis module configured to combine the feature representations of the selected time series subsequences with the dynamic prompts based on a type of analysis task of the time series data to be analyzed, and input the combination result into a large language model to obtain an analysis result of the time series data through the large language model;
[0050] wherein the large language model is provided with an adaptive window length optimization mechanism.
[0051] Compared with the prior art, the present application has the following beneficial effects:
[0052] The present application discloses an adaptive time series analysis method based on a dynamic prompt mechanism, which focuses on solving the limitations of fixed window length in traditional time series analysis methods. In complex time series data, different data may require different lengths of historical information for accurate modeling. Fixed window length is difficult to adapt to this diversity, which may lead to information loss or the introduction of irrelevant information. The technical solution disclosed in the present application sets an adaptive window length optimization mechanism, which enables the model to automatically adjust the length of historical information to be focused on, adapt to different time scales, and effectively solve the limitations of fixed window length. In addition, the present application provides a method for flexibly capturing and utilizing relevant historical information through a dynamic prompt mechanism, which can improve the adaptability and prediction accuracy of the large language model.
[0053] The present application is dedicated to more effectively capturing and processing complex patterns and trends in time series data. Time series data in practical applications often contains complex seasonal, periodic changes and outliers. These patterns may change at different time scales, and traditional methods are difficult to fully capture these complex patterns. The dynamic prompt mechanism of the present application retrieves historical prompts similar to the current data pattern, enhancing the large language model's ability to recognize and understand these complex patterns. The present application aims to improve the generalization ability of the time series analysis large language model, especially when facing data distribution shifts. In practical applications, the statistical characteristics of training data and test data often differ, which poses a challenge to the generalization ability of the large language model. The dynamic prompt mechanism of the present application retrieves relevant historical experience, enabling the model to better adapt to new, unseen data distributions, thereby improving the robustness and generalization ability of the large language model. BRIEF DESCRIPTION OF DRAWINGS
[0054] In order to more clearly illustrate the technical solutions of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below; obviously, the drawings in the following description are some embodiments of the present application, and other drawings can also be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0055] Figure 1 is a schematic diagram of a self-adaptive time series analysis method based on a dynamic prompting mechanism in an embodiment of the present application.
[0056] Figure 2 is a schematic diagram of a self-adaptive time series analysis system based on a dynamic prompting mechanism in an embodiment of the present application. DETAILED DESCRIPTION
[0057] In order to make the objects, technical solutions and advantages of the present application clearer, the technical solutions in the present application will be described clearly and completely below in combination with the drawings in the embodiments of the present application; obviously, the described embodiment technical solutions are some embodiments of the present application, not all the embodiments.
[0058] Based on the technical solutions disclosed in the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device including a series of steps or units does not have to be limited to only those steps or units clearly listed, but can include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0059] Referring to Figure 1 In the embodiments of the present application, a self-adaptive time series analysis method based on a dynamic prompting mechanism is disclosed, which specifically includes the following steps:
[0060] Step 1, obtaining time series data to be analyzed, and using a sliding window method to construct time series sub-sequences;
[0061] In an optional technical solution, after obtaining the time series data to be analyzed, data standardization is first performed, and then a sliding window method is used to construct time series sub-sequences;
[0062] In a specific example technical solution, taking the PEMS-BAY dataset as an example, the dataset contains traffic flow data of 325 sensors at 52116 time points, and the data of one sensor (for example, such as selecting the sensor numbered 100) is selected; for the selected sensor, the traffic flow data recorded every 5 minutes for 30 consecutive days is obtained, and the data is z-score standardized, and then a sliding window of 1 hour (12 time steps) is used to construct a time series subsequence;
[0063] Specifically, the following phenomena can be observed:
[0064] 1) The traffic flow on weekdays presents a clear double-peak pattern, with significant increases in traffic flow during the morning peak (7:00-9:00) and evening peak (17:00-19:00) periods;
[0065] 2) The traffic flow on weekends is relatively flat, but there is a small peak in the afternoon (14:00-16:00);
[0066] 3) The overall traffic flow on rainy days is about 15% lower than on sunny days, and the peak of the peak period is delayed by about 30 minutes.
[0067] Step 2, extract the feature representation of each time series subsequence, and generate the dynamic prompt of each time series subsequence based on the initialized dynamic prompt pool;
[0068] In an optional technical solution, the initialization of the dynamic prompt pool includes: using a pre-trained Transformer model to encode the training data to generate an initial key-value pair set, and then optimizing the prompt pool structure through clustering to obtain the initialized dynamic prompt pool;
[0069] In a specific example technical solution, based on the observation results of step 1, the traffic patterns are encoded into the following typical patterns:
[0070] 1) "Weekday double-peak pattern";
[0071] 2) "Weekend single-peak pattern";
[0072] 3) "Rainy day delayed peak pattern";
[0073] 4) "Late night low flow pattern";
[0074] The above four patterns are encoded into key-value pairs and organized into a structured prompt pool through clustering.
[0075] Based on the four typical patterns described above, in further exemplary technical solutions, a 1-hour sub-sequence at 8:30 on Tuesday morning is assumed to be analyzed: first, the feature representation of the 1-hour sub-sequence is extracted, such as average traffic (e.g., 1200 vehicles / hour), traffic growth rate (e.g., an increase of 40% compared to the previous hour), etc.; these extracted features are compared with the patterns in the prompt pool, and the "workday double-peak pattern" can be retrieved as the most relevant dynamic prompt.
[0076] In step 3, based on the analysis task type of the time series data to be analyzed, the feature representation of the selected time series sub-sequence is combined with the dynamic prompt and input into the large language model, and the analysis result is obtained through the large language model.
[0077] In optional technical solutions, the neural network structure corresponding to the analysis task type of the time series data to be analyzed is determined first, and then the feature representation of the selected time series sub-sequence is combined with the dynamic prompt using the determined neural network.
[0078] In specific exemplary technical solutions, the analysis task type is to predict the traffic flow in the next 1 hour, and the determined neural network structure is a feedforward neural network. The combination of the traffic data features of the current 1-hour sub-sequence and the dynamic prompt "workday double-peak pattern" retrieved from the prompt pool is input into the large language model, and the traffic flow in the next 1 hour is predicted through the large language model. For example, for the traffic flow prediction task, the feature representation of the current 1-hour traffic data is combined with the "workday double-peak pattern" retrieved from the prompt pool using the feedforward neural network and is input into the subsequent prediction, and the preliminary prediction of the traffic flow in the next hour is 1350 vehicles / hour.
[0079] In the embodiment of the application, in the step of obtaining the analysis result through the large language model, the large language model is provided with a multi-dimensional adaptive optimization mechanism.
[0080] In exemplary technical solutions, the traffic flow during the morning peak period (8:30-9:30) on Tuesday is predicted as an example. Based on the prompt of the "workday double-peak pattern" and the current observation data, the preliminary prediction of the traffic flow in the next hour is 1350 vehicles / hour. In order to improve the prediction accuracy, the present application optimizes this prediction result through a multi-dimensional adaptive optimization mechanism.
[0081] Firstly, in the adaptive analysis of the time dimension, the system observes that the traffic in the 8:15-8:30 period is significantly faster than in the 8:00-8:15 period (increased from 1100 vehicles / hour to 1200 vehicles / hour); considering this rapid change trend, the adaptive window mechanism dynamically adjusts the analysis window from 1 hour to 30 minutes to capture the traffic change characteristics more sensitively, and the prediction value is adjusted to 1380 vehicles / hour based on the recalculated time window.
[0082] Secondly, the patterns in the prompt pool are dynamically updated, including: by analyzing the data of the same period in the past three weeks, it is found that the average traffic of this period is about 1400 vehicles / hour, and accordingly the peak characteristics of the "double peak pattern of weekdays" are updated, which further optimizes the prediction value to 1390 vehicles / hour, better reflecting the historical statistical rules.
[0083] Then, the prediction strategy is optimized through reinforcement learning, including: considering the current observed rapid growth trend, the system adjusts the feature weight distribution, increasing the weight of recent trends to 0.6 and adjusting the weight of historical patterns to 0.4, which optimizes the final prediction value to 1395 vehicles / hour.
[0084] Finally, the explainability module of the present application performs a detailed attribution analysis on the final prediction value of 1395 vehicles / hour. The results show that the recent rapid growth trend contributes 45% of the influence, the historical weekday pattern contributes 40% of the influence, the good weather on the day contributes 10% of the influence, and other factors contribute 5% of the influence. This clear attribution analysis not only improves the credibility of the prediction result, but also provides a basis for subsequent optimization.
[0085] Through this series of adaptive optimization, the confidence interval of the prediction result is reduced from ±100 vehicles / hour to ±50 vehicles / hour, and the confidence is improved from 85% to 93%. This significant performance improvement fully embodies the adaptive analysis capability of the present application based on the dynamic prompt mechanism, which can dynamically adjust the analysis strategy according to real-time data and continuously optimize the prediction performance, while maintaining high explainability. This adaptive optimization mechanism makes the present application particularly suitable for handling complex and variable time series analysis tasks.
[0086] In one specific embodiment of the present application, an adaptive time series analysis method based on a dynamic prompt mechanism is provided, and the specific process is as follows:
[0087] Step S1, obtaining time series data to be analyzed, using a sliding window method to construct time series sub-sequences; wherein,
[0088] The original time series data to be analyzed is represented as X∈R N×T, X is a data matrix, representing a dataset composed of N univariate time series, T represents the number of timestamps;
[0089] Each time series in the data matrix X is z-score standardized to ensure that data of different scales can be compared, and the calculation expression of the standardization is:
[0090]
[0091] In the formula, X norm is the standardized time series; μ is the mean vector; σ is the standard deviation vector;
[0092] The expression for constructing a time series subsequence using a sliding window method is:
[0093]
[0094] In the formula, S t is the time series subsequence; τ is a pre-defined window size; is the window time series data with a time length of τ;
[0095] Interpretively, the steps for constructing the time series subsequence are used to provide a basis for subsequent dynamic prompt generation.
[0096] Step S2, based on the initialized dynamic prompt pool, generating a dynamic prompt for each time series subsequence; wherein,
[0097] The initialization of the dynamic prompt pool is the core component of the technical solution of the present application to cope with complex patterns and trend capture; wherein each prompt is represented as a key-value pair (k, v), k∈R d is the key vector, R d is a d-dimensional real number vector; v∈R l×d is the value matrix, d is the embedding dimension, l is the prompt length, R l×d is an l-row d-column real number matrix;
[0098] In the embodiment of the present application, a pre-trained Transformer model is used to encode the training data to obtain an initial key-value pair set, represented as:
[0099] P={(k1,v1),(k2,v2),…,(k M ,v M )};
[0100] In the formula, P is the initial key-value pair set; (k M ,v M ) is the Mth key-value pair, k M is the key vector in the Mth key-value pair, and v Mthe value matrix in the Mth pair of key-value pairs;
[0101] Further, in order to improve the retrieval efficiency and reduce redundancy, the initialized key vector is clustered by K-means, denoted as:
[0102]
[0103] wherein, represents finding a clustering scheme C that minimizes the objective function; k represents the key vector in the hint pool; μ i represents the center vector of the ith cluster; C i represents the ith cluster, which contains all the key vectors assigned to the cluster; M represents the preset number of clusters;
[0104] Explanatorily, the steps herein not only optimize the structure of the hint pool, but also lay a foundation for subsequent fast retrieval; this hint pool not only stores historical patterns and trend information, but also provides the possibility for knowledge reuse and migration.
[0105] In the dynamic hint generation and retrieval stage, for each input time series subsequence S t , first, a multi-scale convolutional neural network is used to extract its feature representation:
[0106]
[0107] wherein, f t represents the feature representation of the time series subsequence S t ; CNN i represents convolutional layers of different scales;
[0108] Such multi-scale feature extraction helps to capture patterns and trends at different time scales, enhancing the understanding ability of complex time dynamics;
[0109] Then, the cosine similarity sim(f t , k m ) between f t and each key vector k m in the hint pool is calculated, and the calculation expression is:
[0110] sim(f t , k m ) = (f t · k m ) / (‖f t ‖‖k m ‖);
[0111] wherein, f t · k m represents the dot product of vectors, and ‖f t ‖‖km ‖ vector module multiplication;
[0112] Ranking based on cosine similarity, select the top K prompts with the highest similarity;
[0113] Apply attention mechanism to the retrieved prompt value matrix to generate the final dynamic prompt, denoted as:
[0114] p t =∑ i α i v i ;
[0115]
[0116] In the formula, p t represents the generated final dynamic prompt; α i represents the attention weight of the i-th prompt; represents the transpose of f t ; v i represents the value vector of the i-th prompt; W q represents the learnable query matrix parameter; k i represents the key vector of the i-th prompt;
[0117] Interpretively, the top K prompts with the highest similarity are selected, and the retrieved prompt value matrix is combined by attention mechanism to generate the final dynamic prompt. The specific calculation process is as follows: first, calculate the attention weight α i of each prompt, which is obtained by the similarity between f t and the prompt key vector k i , where the learnable query matrix W q is introduced to enhance the flexibility of similarity calculation; then all the retrieved prompt value vectors are weighted and summed according to their corresponding attention weights to obtain the final dynamic prompt. This weighted combination method based on attention mechanism makes the application capable of adaptively selecting and fusing the most relevant historical knowledge according to the characteristics of the input data, thereby improving the recognition ability and generalization performance of complex time series patterns;
[0118] Step S3, based on the analysis task type of the time series data to be analyzed, combine the feature representation of the selected time series subsequence with the dynamic prompt and input it into the large language model, and obtain the analysis result through the large language model; wherein,
[0119] In order to adapt to different time series analysis tasks, the application designs a task-specific dynamic prompt application mechanism, which adopts different neural network structures to combine the dynamic prompt p t with the feature representation ft combining;
[0120] For example, for the prediction task, a feed-forward neural network is used, denoted as:
[0121] h t = FFN([f t ; p t ]); where [f t ; p t ] represents the concatenation operation of f t and dynamic prompt p t ;
[0122] For example, for the missing data imputation, a gated recurrent unit is used, denoted as:
[0123] h t = GRU(f t , p t );
[0124] In summary, this flexible task adaptation mechanism can be generally represented as:
[0125] h t = TaskNetwork(f t , p t ); where TaskNetwork varies according to the specific task type;
[0126] where h t represents the task-specific output feature representation; FFN represents the feed-forward neural network; GRU represents the gated recurrent unit; and TaskNetwork represents the task-specific neural network structure.
[0127] The task-specific dynamic prompt application mechanism of the present application has the following advantages:
[0128] 1) Targeted: by designing a special network structure for different types of tasks, the feature fusion process is more adapted to the task requirements;
[0129] 2) Flexibility: the most suitable network structure can be selected or designed according to the characteristics of the specific task;
[0130] 3) Universality: maintains a unified framework form, facilitating extension to new task types;
[0131] Through this mechanism, the present application can achieve efficient feature fusion and processing for different types of time series analysis tasks while maintaining the uniformity of the framework, thereby obtaining good task-specific performance.
[0132] In a specific embodiment of the present invention, in order to further improve the adaptability and generalization ability of the model, an adaptive window length optimization mechanism is adopted; wherein a window length candidate set W = {τ1,τ2,…,τ n}, construct a time series subsequence for each candidate window length and extract features, then calculate a comprehensive score for each window length, the calculation expression is:
[0133]
[0134] Where, τ m represents the length of the mth candidate window; k j represents the j-th key vector; Indicates the use of window length τ m The mean square error of prediction when ; represents the window length τ m The extracted features and the hint key vector k j similarity; represents the window length τ m The information entropy of the extracted features is given below; α, β, and γ represent the weight coefficients of each indicator respectively; N represents the number of prompt key vectors evaluated.
[0135] Based on the scores calculated above, the optimal window length is dynamically selected, which is expressed as:
[0136]
[0137] Furthermore, in order to avoid frequent changes in window length, a smoothing mechanism is introduced, which is expressed as:
[0138] τ t =(1-λ)τ t-1 +λτ opt ;
[0139] Where λ is the smoothing factor;
[0140] This mechanism enables the model to automatically adjust the length of historical information of interest, adapt to patterns at different time scales, and effectively address the limitations of fixed window length.
[0141] Regarding a specific embodiment of the adaptive window length mechanism, the window length candidate set W is set to {30 minutes, 1 hour, 2 hours};
[0142] During the morning peak period (e.g. 7:00-9:00 AM), calculate the length score of each window;
[0143] 30-minute window: low MSE, high similarity, and high information entropy;
[0144] 1 hour window: MSE moderate, similarity moderate, information entropy moderate;
[0145] 2 hour window: MSE higher, similarity low, information entropy small;
[0146] In summary, the 30-minute window is selected as the optimal window length, and the smoothing mechanism (lambda = 0.3) is gradually adjusted to avoid mutation.
[0147] In an embodiment of the present application, a feedback optimization mechanism based on reinforcement learning is also designed to further enhance the adaptive learning ability of the model; wherein,
[0148] Define the state space S (including the current data characteristics, the selected prompt and the task type), the action space A (including prompt selection, window length adjustment and other operations) and the reward function R (based on the performance of the model on the validation set);
[0149] Use the policy gradient method to optimize the decision strategy, represented as:
[0150]
[0151] In the formula, π θ is a parameterized policy function, R t is the discounted cumulative reward from time t;
[0152] The technical means of the embodiment of the present application can continuously adjust its behavior according to real-time feedback and improve its performance in a dynamically changing environment.
[0153] In the embodiment of the reinforcement learning optimization mechanism, the state is: the current traffic is 1200 vehicles / hour, the time is the morning peak of weekdays, and the weather is sunny; the action is: select a 30-minute window and use the "weekday peak period" prediction strategy; the reward is: give positive feedback according to the prediction accuracy.
[0154] In an embodiment of the present application, in order to improve the calculation efficiency, especially when processing long sequences, the SelfExtend technology is used, which can effectively process long sequence inputs through grouping attention and neighborhood attention mechanisms; wherein,
[0155] The input sequence is divided into G groups, represented as:
[0156] X = [X1, …, X G ];
[0157] Apply self-attention mechanism to each group:
[0158]
[0159] Apply neighborhood attention between adjacent groups:
[0160] O g = Attention(A g , [A g-1 , A g , A g+1 ], [A g-1 , A g , A g+1 ]);
[0161] where W Q , W K , W V are learnable weight matrices;
[0162] The technical means of the embodiment of the application not only improves the efficiency of processing long sequences, but also maintains the ability to capture long-term dependencies.
[0163] In an embodiment of the efficient sequence processing mechanism, 24 hours of data are divided into 8 groups of 3 hours for processing; self-attention is calculated within the group to capture local traffic patterns; attention is calculated between adjacent groups to maintain temporal continuity.
[0164] In a specific embodiment of the application, in order to enhance the explainability of the model, an explainability module is used, which calculates the contribution of each hint to the final prediction using SHAP (SHapley Additive exPlanations) value, and the calculation expression is:
[0165]
[0166] In the formula, φ n represents the SHAP value of the nth feature; F represents the set of all features; S represents a subset of features that does not contain the nth feature; |S| represents the number of features in the subset S; |F| represents the total number of features; f S (x S ) represents the model output using only the feature subset S for prediction; f S∪{n} (x S∪{n} ) represents the model output after adding the nth feature; is a combination weight used to balance the influence of different feature combinations;
[0167] The application can also visualize the attention weight alpha i during the dynamic hint generation process, and use the integrated gradient method to calculate the importance score of the input feature, and the calculation expression is:
[0168]
[0169] In the formula, IG n(x) represents the integrated gradient value of the nth feature x; x represents the actual feature value vector of the current input, x n represents the actual input value of the nth feature; x' represents the baseline input, which is a reference point value, x' n represents the baseline input value of the nth feature; f represents the prediction model function; ω represents the integral path parameter; represents the partial derivative of the model to the nth feature.
[0170] The technical means of the embodiments of the present application not only improves the transparency of model decision, but also provides insights for further optimization.
[0171] In the embodiments of the application of the explainable mechanism,
[0172] The feature importance analysis includes:
[0173] Historical traffic flow: SHAP value = 0.45 (positive contribution);
[0174] Time feature: SHAP value = 0.25 (positive contribution);
[0175] Weather condition: SHAP value =-0.15 (negative contribution);
[0176] The prediction explanation report includes:
[0177] Prediction result: traffic flow increases by 20%;
[0178] The main influencing factors include:
[0179] Historical similar pattern matching degree (contribution degree 45%);
[0180] Current time period feature (contribution degree 25%);
[0181] Weather influence (contribution degree 15%);
[0182] Other factors (contribution degree 15%);
[0183] Through this explainable mechanism, the present application can provide quantitative explanation of the prediction result, identify key influencing factors, assist decision makers to understand the basis of prediction, and provide guidance basis for model optimization.
[0184] In summary, firstly, the present invention focuses on solving the limitations of fixed window lengths in traditional time series analysis methods. In complex time series data, different data may require historical information of different lengths to accurately model; fixed window lengths are difficult to adapt to this diversity, which may lead to information loss or the introduction of irrelevant information. The present invention provides a method for flexibly capturing and utilizing relevant historical information through a dynamic prompt mechanism, thereby improving the adaptability and prediction accuracy of large language models. Secondly, the present invention is committed to more effectively capturing and processing complex patterns and trends in time series data. Time series data in practical applications often contain complex seasonality, cyclical changes, and outliers. These patterns may vary on different time scales, and traditional methods find it difficult to fully capture these complex patterns. The dynamic prompt mechanism of the present invention enhances the recognition and understanding capabilities of large language models for these complex patterns by retrieving historical prompts that are similar to current data patterns. The present invention aims to improve the generalization capability of large language models for time series analysis, particularly in the face of data distribution shifts. In practical applications, the statistical properties of training and test data often differ, posing a challenge to the generalization capability of large language models. The present invention's dynamic prompt mechanism enables the model to better adapt to new, unseen data distributions by retrieving relevant historical experience, thereby improving the robustness and generalization capability of large language models. The present invention addresses the problem of knowledge reuse and transfer in time series analysis. Certain patterns may recur across different time periods or datasets. Effectively leveraging these recurring patterns can significantly improve analysis efficiency and accuracy. The present invention implements knowledge encoding, storage, and retrieval by establishing and maintaining a prompt pool, enabling the model to effectively reuse and transfer learned knowledge, thereby improving its prediction and analysis capabilities for new data. Finally, the present invention aims to achieve adaptive learning in time series analysis. Time series data is inherently dynamic, requiring the model to continuously adapt to new data features and patterns. The present invention's dynamic prompt mechanism enables large language models to dynamically adjust their learning process based on new input data, adapting to data changes by retrieving the most relevant prompts, thereby achieving continuous performance improvement.
[0185] In general, this paper provides a flexible, efficient, and adaptive solution for the analysis of complex time series data through an innovative dynamic prompt mechanism, effectively solving multiple key technical challenges faced by traditional methods in processing complex time series data.
[0186] To further explain, in a specific embodiment of the present invention, an adaptive window length mechanism is implemented, and the decision strategy is optimized through reinforcement learning, thereby improving computational efficiency and model interpretability; wherein,
[0187] Regarding the adaptive window: when detecting rapid changes in traffic flow (such as during the early morning peak period 7:00-9:00), the adaptive window length mechanism of the present invention dynamically adjusts the sliding window length from 1 hour to 30 minutes based on the calculation results of the score(τ) function, which can more accurately capture the characteristics of the rapid changes in traffic flow;
[0188] Regarding reinforcement learning optimization: the reinforcement learning optimization mechanism of the present invention learns the optimal decision-making strategy by continuously accumulating state-action-reward experiences; for example, when detecting rainfall weather, based on historical data analysis results, the reinforcement learning optimizer will automatically adjust the prediction parameters and adopt the "rainy day peak delay mode" for prediction, thereby adapting to the special change rules of traffic flow in rainy days;
[0189] Regarding interpretability: the interpretability module of the present invention generates a prediction basis analysis report based on SHAP value calculation and integrated gradient method; for example, the current period (Tuesday 8:30 am) traffic flow prediction increases by 30%, which is based on the contribution of the weekday double peak mode feature 50%, the current period growth rate contribution 30%, and the historical same period data contribution 20%. This quantitative explanation provides a clear prediction basis;
[0190] Through the synergistic effect of the above technical features, the present invention realizes dynamic adaptive analysis of complex time series data, efficient extraction and utilization of historical knowledge, optimized allocation of computing resources, and interpretability analysis of prediction results. The above technical means enable the present invention to accurately grasp the dynamic change rules of time series data (such as traffic flow), provide high-precision prediction results and clear prediction basis.
[0191] The following is an embodiment of the device of the present invention, which can be used to execute the method embodiment of the present invention. For details not disclosed in the device embodiment, please refer to the method embodiment of the present invention.
[0192] Please refer to Figure 2 In the embodiment of the present invention, an adaptive time series analysis system based on a dynamic prompt mechanism is provided, which comprises:
[0193] A time series subsequence construction module is used to obtain time series data to be analyzed, and a sliding window method is used to construct time series subsequences;
[0194] A dynamic prompt generation module is used to extract feature representations of each time series subsequence, and generate dynamic prompts for each time series subsequence based on a dynamic prompt pool;
[0195] The analysis module is configured to combine the feature representation of the selected time series sub-sequence with the dynamic prompt based on a type of analysis task of the time series data to be analyzed, and input the combination result into a large language model to obtain an analysis result of the time series data through the large language model.
[0196] The large language model is provided with an adaptive window length optimization mechanism.
[0197] In an embodiment of the present application, a computer device is provided, which includes a processor and a memory for storing a computer program including program instructions, and the processor is configured to execute the program instructions stored in the computer storage medium. The processor can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., which are the computing core and control core of the terminal, and are suitable for implementing one or more instructions, and are specifically suitable for loading and executing one or more instructions in the computer storage medium to implement a corresponding method flow or a corresponding function. The processor in the embodiments of the present application can be used to execute the operation of the adaptive time series analysis method based on the dynamic prompt mechanism.
[0198] In an embodiment of the present application, a storage medium, specifically a computer readable storage medium (Memory) is provided, which is a memory device in a computer device, for storing programs and data. It can be understood that the computer readable storage medium herein can include an internal storage medium in the computer device, and of course can include an extended storage medium supported by the computer device. The computer readable storage medium provides a storage space, which stores an operating system of the terminal. Moreover, one or more instructions adapted to be loaded and executed by the processor are also stored in the storage space, and the instructions can be one or more computer programs (including program codes). It should be noted that the computer readable storage medium herein can be a high-speed RAM (Random Access Memory) memory, or a non-volatile memory such as at least one disk memory. The one or more instructions stored in the computer readable storage medium can be loaded and executed by the processor to implement the corresponding steps of the adaptive time series analysis method based on the dynamic prompting mechanism in the above embodiment.
[0199] Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. Therefore, the present application can take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Moreover, the present application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, optical storage, etc.) containing computer-usable program code.
[0200] The present application is described with reference to flowcharts and / or block diagrams of the method, device (system), and computer program product according to the embodiments of the present application. It should be understood that each flow and / or block in the flowcharts and / or block diagrams, and the combination of the flows and / or blocks in the flowcharts and / or block diagrams can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing apparatus to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing apparatus produce a device implemented in the flowcharts and / or block diagrams. Figure 1 The function specified in one or more flows and / or blocks Figure 1 The device that implements the function specified in one or more flows and / or blocks.
[0201] These computer program instructions can also be stored in a computer readable storage medium that can direct the computer or other programmable data processing apparatus to work in a specific manner, so that the instructions stored in the computer readable storage medium produce a manufactured product including instruction devices that implement the flowcharts and / or block diagrams. Figure 1one or more processes and / or blocks Figure 1 the function specified in the one or more blocks.
[0202] These computer program instructions can also be loaded into computer or other programmable data processing devices, so that a series of operation steps are performed on the computer or other programmable data processing devices to generate computer-implemented processes, so that the instructions executed on the computer or other programmable data processing devices provide processes for implementing the flow Figure 1 one or more processes and / or blocks Figure 1 the function specified in the one or more blocks.
[0203] Finally, it should be noted that: the above examples are only used to illustrate the technical solutions of the present application, but not to limit it, although the above embodiments of the present application have been described in detail, those skilled in the art should understand: the specific embodiments of the present application can be modified or replaced by the same, without departing from the spirit and scope of the present application, any modification or equivalent replacement, which should be covered within the scope of protection of the claims of the present application.
Claims
1. An adaptive time series analysis method based on a dynamic prompt mechanism, characterized in that: The following steps are involved: Obtain the time series data to be analyzed and construct the time series subsequence using the sliding window method; Extract the feature representation of each time series subsequence, and generate dynamic prompts for each time series subsequence based on the dynamic prompt pool; Based on the analysis task type of the time series data to be analyzed, the feature representation of the selected time series subsequence is combined with the dynamic prompt, and the combined result is input into the large language model to obtain the analysis result of the time series data through the large language model; Wherein, the large language model is provided with an adaptive window length optimization mechanism; In the step of generating dynamic prompts for each time series subsequence based on the dynamic prompt pool, For the time series subsequence S t , calculate the time series subsequence S t The feature representation f t With each key vector k in the dynamic hint pool m The cosine similarity sim(f t ,k m ), the calculation expression is: sim(f t ,k m )=(f t ·k m ) / (‖f t ‖‖k m ‖); Where, f t ·k m represents the dot product of the vectors, ‖f t ‖‖k m ‖ represents the multiplication of vector norms; Based on the cosine similarity ranking, the K prompts with the highest similarity are selected to form the prompt value matrix; Applying the attention mechanism to the prompt value matrix generates the final dynamic prompt, which is expressed as: p t =∑ i a i v i ; Where p t represents the final dynamic prompt generated; α i represents the attention weight of the i-th prompt; represents f t The transpose of v i W represents the value vector of the i-th prompt; q represents the learnable query matrix parameters; k i represents the key vector of the i-th prompt; In the adaptive window length optimization mechanism, a set of window length candidates is preset, a time series subsequence is constructed for each candidate window length and features are extracted, and then a comprehensive score of each window length is calculated. Based on the comprehensive scores of each candidate window length, the optimal window length is dynamically selected; wherein, The calculation expression of the comprehensive score is: Where, τ m represents the length of the mth candidate window; k j represents the j-th key vector; Indicates the use of window length τ m The mean square error of prediction when ; represents the window length τ m The extracted features and the hint key vector k j similarity; represents the window length τ m The information entropy of the extracted features; α, β, and γ represent the weight coefficients of each indicator respectively; N represents the number of prompt key vectors evaluated; Dynamically selected optimal window length τ opt Expressed as:
2. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: In the step of generating dynamic prompts for each time series subsequence based on the dynamic prompt pool, The dynamic prompt pool is an initialized dynamic prompt pool or a dynamically updated dynamic prompt pool; wherein, The step of obtaining the initialized dynamic prompt pool includes: encoding the training data using a pre-trained Transformer model to generate an initial set of key-value pairs, and then optimizing the prompt pool structure by clustering to obtain the initialized dynamic prompt pool; wherein each prompt is represented as a key-value pair (k, v); k∈R d is the key vector, R d is a d-dimensional real vector; v∈R l×d is the value matrix, d is the embedding dimension, l is the hint length, R l×d is a real matrix with l rows and d columns; After dynamically updating the initialized dynamic prompt pool based on the analysis result of the time series data, a dynamically updated dynamic prompt pool is obtained.
3. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: In the step of combining the feature representation of the selected time series subsequence with the dynamic prompt based on the analysis task type of the time series data to be analyzed, For prediction tasks, a feedforward neural network is used to combine the feature representation of the selected time series subsequence with dynamic cues; For missing data interpolation, a gated recurrent unit is used to combine the feature representation of the selected time series subsequence with dynamic cues.
4. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: The adaptive window length optimization mechanism also introduces a smoothing mechanism; wherein, t t =(1-λ)τ t-1 +lt opt ; Where λ is the smoothing factor.
5. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: The large language model is also provided with a feedback optimization mechanism based on reinforcement learning, which uses a policy gradient method to optimize the decision-making strategy.
6. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: The large language model also uses the SelfExtend method to process the input sequence.
7. The adaptive time series analysis method based on a dynamic prompt mechanism according to claim 1, characterized in that: The large language model is also provided with an interpretability module; wherein, The interpretability module is used to calculate the contribution of each hint to the final prediction using the SHAP value, calculating the expression: Where, φ n represents the SHAP value of the nth feature; F represents the set of all features; S represents the feature subset that does not contain feature n; |S| represents the number of features in subset S; |F| represents the total number of features; f S (x S ) represents the model output using only the feature subset S for prediction; f S∪{n} (x S∪{n} ) represents the model output after adding the nth feature; is the combination weight, which is used to balance the impact of different feature combinations; The interpretability module is also used to visualize the attention weights α during the dynamic cue generation process. i , and use the integrated gradient method to calculate the importance score of the input feature. The calculation expression is: Where, IG n (x) represents the integrated gradient value of the nth feature x; x represents the actual feature value vector of the current input, x n represents the actual input value of the nth feature; x′ represents the baseline input, which is a reference point value, n represents the baseline input value of the nth feature; f represents the prediction model function; ω represents the integral path parameter; Represents the partial derivative of the model with respect to the nth feature.
8. An adaptive time series analysis system based on a dynamic prompt mechanism, characterized in that: include: The time series subsequence construction module is used to obtain the time series data to be analyzed and construct the time series subsequence using the sliding window method; A dynamic prompt generation module is used to extract the feature representation of each time series subsequence and generate dynamic prompts for each time series subsequence based on the dynamic prompt pool; An analysis module, configured to combine the feature representation of a selected time series subsequence with a dynamic prompt based on the analysis task type of the time series data to be analyzed, and input the combined result into a large language model to obtain an analysis result of the time series data through the large language model; Wherein, the large language model is provided with an adaptive window length optimization mechanism; In the step of generating dynamic prompts for each time series subsequence based on the dynamic prompt pool, For the time series subsequence S t , calculate the time series subsequence S t The feature representation f t With each key vector k in the dynamic hint pool m The cosine similarity sim(f t ,k m ), the calculation expression is: sim(f t ,k m )=(f t ·k m ) / (‖f t ‖‖k m ‖); Where, f t ·k m represents the dot product of the vectors, ‖f t ‖‖k m ‖ represents the multiplication of vector norms; Based on the cosine similarity ranking, the K prompts with the highest similarity are selected to form the prompt value matrix; Applying the attention mechanism to the prompt value matrix generates the final dynamic prompt, which is expressed as: p t =∑ i a i v i ; Where p t represents the final dynamic prompt generated; α i represents the attention weight of the i-th prompt; represents f t The transpose of v i W represents the value vector of the i-th prompt; q represents the learnable query matrix parameters; k i represents the key vector of the i-th prompt; In the adaptive window length optimization mechanism, a set of window length candidates is preset, a time series subsequence is constructed for each candidate window length and features are extracted, and then a comprehensive score of each window length is calculated. Based on the comprehensive scores of each candidate window length, the optimal window length is dynamically selected; wherein, The calculation expression of the comprehensive score is: Where, τ m represents the length of the mth candidate window; k j represents the j-th key vector; Indicates the use of window length τ m The mean square error of prediction when ; represents the window length τ m The extracted features and the hint key vector k j similarity; represents the window length τ m The information entropy of the extracted features; α, β, and γ represent the weight coefficients of each indicator respectively; N represents the number of prompt key vectors evaluated; Dynamically selected optimal window length τ opt Expressed as:
Citation Information
Patent Citations
Traffic flow prediction method and device based on prompt generation pre-training transformation network
CN118280115A