A multi-scale self-supervised and attention mechanism fusion traffic flow prediction method

CN122929783APending Publication Date: 2026-10-16山西省智慧交通实验室有限公司 +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611254597.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-18
Publication Date
2026-10-16

AI Technical Summary

Technical Problem

[0003]然而,现有交通流预测方法仍存在以下不足:第一,多数方法仅依赖历史周期数据建模交通规律,难以有效识别和表征由事故、恶劣天气或大型活动引发的非周期性突发事件,且对不同时间尺度下突发事件的瞬时、中期和长期影响缺乏系统建模能力;第二,现有方法在融合时间和空间特征时,多采用独立建模后再进行简单拼接或单向注意力的浅层融合方式,难以实现时间动态与空间传播之间的深度协同交互,限制了模型对复杂时空耦合关系的表达能力;第三,周期模式与事件特征之间的语义关联未能被充分挖掘,简单拼接或相加的融合方式难以反映二者在不同交通状态下的动态交互关系

Benefits of technology

1、本发明通过构建多尺度自监督时序重构机制,利用多个并行的时序重构分支分别处理不同长度的历史时间窗口,各分支通过自监督重构损失函数自动学习不同时间粒度下(瞬时扰动、中期事件、长期演化趋势)的异常事件模式。相较于现有技术中依赖外部标签或静态先验的事件建模方法,本发明无需人工标注即可从原始交通流数据中自主发现突发事件特征,显著提升了对非平稳交通扰动的感知能力与适应性。以周期性嵌入特征作为查询、以动态事件嵌入特征作为键和值,通过交叉注意力机制生成周期-事件融合特征。该设计使模型能够根据不同的周期上下文自适应地调整事件特征的贡献权重,相较于现有技术中简单拼接或逐元素相加的融合方式,显著增强了对周期模式与突发事件之间动态语义关联的表征能力。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122929783A_ABST
    Figure CN122929783A_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of traffic flow prediction, and particularly relates to a traffic flow prediction method combining multi-scale self-supervision and attention mechanism, comprising the following steps: obtaining historical traffic flow data and extracting periodic embedding features; generating periodic-event fusion features through cross-attention mechanism; inputting the periodic-event fusion features into time coding branches and space coding branches arranged in parallel respectively for processing, and correspondingly obtaining time-dependent features and space-dependent features; generating modulation parameters through bidirectional cross-attention, performing dynamic affine transformation on the features output by the other branch by using the modulation parameters, and outputting multi-layer spatiotemporal collaborative features. The application constructs a multi-scale self-supervision time series reconstruction mechanism, uses multiple parallel time series reconstruction branches to process historical time windows of different lengths respectively, and each branch automatically learns abnormal event patterns under different time granularities through a self-supervision reconstruction loss function.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of traffic flow prediction technology, specifically relating to a traffic flow prediction method that integrates multi-scale self-supervision and attention mechanisms. Background Technology

[0002] Traffic flow prediction is one of the core technologies of intelligent transportation systems. It predicts the future traffic conditions of road networks by analyzing historical traffic data, providing decision support for route planning, traffic control, and congestion mitigation. Early traffic flow prediction methods mainly relied on statistical and parametric models, such as historical averages and autoregressive moving average models. However, these methods struggle to capture the nonlinear relationships in traffic data. In recent years, with the development of deep learning technology, researchers have proposed various spatiotemporal prediction models based on graph neural networks and Transformers. Graph neural networks extract spatial dependencies by explicitly modeling the connections between road network nodes, while Transformers utilize self-attention mechanisms to capture long-range temporal dependencies, thus improving prediction accuracy to some extent. Some existing technologies also attempt to enhance spatiotemporal modeling capabilities through periodic partitioning, adaptive graph learning, or attention mechanisms.

[0003] However, existing traffic flow prediction methods still have the following shortcomings: First, most methods rely solely on historical periodic data to model traffic patterns, making it difficult to effectively identify and characterize non-periodic emergencies caused by accidents, severe weather, or large-scale events, and lacking the ability to systematically model the instantaneous, medium-term, and long-term impacts of emergencies at different time scales; Second, when fusing temporal and spatial features, existing methods often employ shallow fusion methods such as independent modeling followed by simple splicing or one-way attention, making it difficult to achieve deep collaborative interaction between temporal dynamics and spatial propagation, thus limiting the model's ability to express complex spatiotemporal coupling relationships; Third, the semantic association between periodic patterns and event features has not been fully explored, and simple splicing or addition methods are insufficient to reflect the dynamic interaction between the two under different traffic conditions. Summary of the Invention

[0004] To address the technical problems of existing traffic flow prediction methods, this invention provides a traffic flow prediction method that integrates multi-scale self-supervision and attention mechanisms. The aim is to construct a traffic flow prediction method that can automatically perceive multi-scale emergencies and achieve in-depth collaborative modeling of spatiotemporal features.

[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows: A traffic flow prediction method that integrates multi-scale self-supervised and attention mechanisms includes the following steps: S1. Obtain historical traffic flow data, extract periodic embedding features, and learn dynamic event embedding features from the historical traffic flow data through multi-scale self-supervised temporal reconstruction. S2. Using the periodic embedding feature as the query and the dynamic event embedding feature as the key and value, a periodic-event fusion feature is generated through a cross-attention mechanism; S3. Input the periodic-event fusion features into the parallel-set time coding branch and spatial coding branch for processing to obtain the time-dependent features and spatial-dependent features respectively; S4. Between each layer of the encoder in the temporal coding branch and the spatial coding branch, modulation parameters are generated through bidirectional cross-attention. The modulation parameters are then used to perform a dynamic affine transformation on the features output by the other branch, resulting in the output of multi-layer spatiotemporal collaborative features.

[0006] The implementation method of multi-scale self-supervised temporal reconstruction in step S1 is as follows: set up multiple parallel temporal reconstruction branches, each branch uses a historical time window of different length to process the input traffic flow sequence; each branch learns the traffic abnormal event pattern at the corresponding time granularity based on the self-supervised reconstruction loss function, and the outputs of all branches are fused to obtain dynamic event embedding features.

[0007] The extraction of periodic embedding features in step S1 specifically includes: obtaining the weekday index and intraday time slice index based on the timestamps of historical traffic flow data; retrieving the weekday embedding and daily embedding from the pre-built weekday embedding dictionary and daily embedding dictionary respectively; and concatenating the weekday embedding and daily embedding to generate periodic embedding features.

[0008] The time-encoding branch processing flow in step S3 is as follows: a gated recurrent unit is used to extract the local time dependency features of the period-event fusion features; then, a multi-head self-attention mechanism is used to perform global time modeling on the local time dependency features, and output the time dependency features.

[0009] The spatial encoding branch processing flow in step S3 is as follows: an adaptive fusion graph is constructed by fusing the geographic adjacency graph, the semantic similarity graph, and the dynamic learning graph; based on the adaptive fusion graph, a graph convolutional network is used to extract the local spatial dependency features of the periodic-event fusion features; then, a multi-head self-attention mechanism is used to perform global spatial modeling on the local spatial dependency features, and the spatial dependency features are output.

[0010] Step S4 generates modulation parameters through bidirectional cross-attention, including: Perform the first cross-attention calculation: take the temporal dependency feature output by the temporal encoding branch as the first query, and the spatial dependency feature output by the spatial encoding branch as the first key and the first value, and calculate to obtain the first temporal context vector; Perform the second cross-attention calculation: use the spatial dependency features output by the spatial encoding branch as the second query, and the temporal dependency features output by the temporal encoding branch as the second key and the second value, and calculate to obtain the second spatial context vector; The first temporal context vector and the second spatial context vector are used to generate modulation parameters.

[0011] Step S4, which involves performing a dynamic affine transformation using modulation parameters, includes: The first temporal context vector is input into the first multilayer perceptron to generate a scaling factor and bias term to adapt the spatial branch. The scaling factor and bias term are then used to perform an affine transformation on the spatial dependency features. The second spatial context vector is input into the second multilayer perceptron to generate a scaling factor and bias term that adapt to the time branch. The scaling factor and bias term are then used to perform an affine transformation on the time-dependent features.

[0012] Each temporal reconstruction branch adopts a GRU autoencoder structure; the self-supervised reconstruction loss is a multi-scale weighted reconstruction loss, which is obtained by weighted summation of the mean square error loss of each branch at the corresponding time scale; the generation of the dynamic event embedding features also includes a spatially aware aggregation step: based on the geographic adjacency matrix, Chebyshev multinomial spectral graph convolution is used to spatially aggregate the temporal hidden states output by each temporal reconstruction branch.

[0013] The dynamic learning graph is generated by operations on two sets of learnable node embedding matrices and bias vectors. The adjacency matrices corresponding to the geographic adjacency graph, semantic similarity graph, and dynamic learning graph are weighted by adaptive attention weights respectively. After weighted summation, the graph is obtained by symmetric normalization and sparsification.

[0014] Step S4 is followed by step S5: the spatiotemporal collaborative features output by the multi-layer spatiotemporal encoder are fused, and a prediction result is generated through a hybrid projection layer; the model is trained using a multi-task loss function, which includes the main prediction loss and the self-supervised reconstruction loss of the multi-scale self-supervised temporal reconstruction. The main prediction loss uses the Huber loss function; the multi-task loss function is calculated using the following formula: ,in The Huber loss is used for predicting the primary model, and λ is the weighting coefficient for the self-supervised reconstruction loss. This is the multi-scale weighted reconstruction loss.

[0015] Compared with the prior art, the beneficial effects of this invention are: 1. This invention constructs a multi-scale self-supervised temporal reconstruction mechanism, utilizing multiple parallel temporal reconstruction branches to process historical time windows of different lengths. Each branch automatically learns anomalous event patterns at different time granularities (instantaneous disturbances, mid-term events, and long-term evolution trends) through a self-supervised reconstruction loss function. Compared to existing event modeling methods that rely on external labels or static priors, this invention can autonomously discover sudden event characteristics from raw traffic flow data without manual annotation, significantly improving the perception and adaptability to non-stationary traffic disturbances. Using periodic embedded features as queries and dynamic event embedded features as keys and values, a cross-attention mechanism generates periodic-event fusion features. This design enables the model to adaptively adjust the contribution weights of event features according to different periodic contexts, significantly enhancing the representation ability of the dynamic semantic association between periodic patterns and sudden events compared to the simple concatenation or element-wise addition fusion methods in existing technologies.

[0016] 2. This invention introduces a bidirectional cross-attention mechanism between each encoder layer of the temporal and spatial coding branches. After generating modulation parameters, it performs dynamic affine transformations on the features of the other branch. Specifically, temporal features generate modulation parameters for spatial features through cross-attention, and spatial features also generate modulation parameters for temporal features, forming a bidirectional interactive path. Compared to the existing technology that independently models spatiotemporal features and then performs shallow fusion, this invention achieves deep collaborative interaction between temporal dynamics and spatial propagation, and can adaptively adjust the expression intensity of spatiotemporal features according to the current traffic state. Attached Figure Description

[0017] To more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings in the following description are merely exemplary, and those skilled in the art can derive other embodiments based on the provided drawings without creative effort.

[0018] The structures, proportions, sizes, etc. illustrated in this specification are only for the purpose of assisting those skilled in the art in understanding and reading the content disclosed herein, and are not intended to limit the conditions under which the present invention can be implemented. Therefore, they have no substantial technical significance. Any modifications to the structure, changes in the proportions, or adjustments to the size, without affecting the effects and objectives that the present invention can produce, should still fall within the scope of the technical content disclosed in the present invention.

[0019] Figure 1 This is a flowchart of a method according to an embodiment of the present invention. Detailed Implementation

[0020] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. These descriptions are only for further illustrating the features and advantages of the present invention, and not for limiting the claims of the present invention. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0021] The specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. The following examples are for illustrative purposes only and are not intended to limit the scope of the invention.

[0022] This invention provides a traffic flow prediction method that integrates multi-scale self-supervision and attention mechanisms, such as... Figure 1 As shown, it includes: S1. Obtain historical traffic flow data, extract periodic embedding features, and learn dynamic event embedding features from historical traffic flow data through multi-scale self-supervised temporal reconstruction.

[0023] As one possible implementation, step S1 involves extracting periodic embedding features by: obtaining the weekday index and intraday time slice index based on the timestamps of historical traffic flow data; retrieving the weekday embedding and daily embedding from the pre-built weekday embedding dictionary and daily embedding dictionary; and concatenating the weekday embedding and daily embedding into periodic embedding features.

[0024] For example, firstly, the original traffic sequence is processed through a fully connected layer. Mapped to a higher-dimensional space; where, Let be a three-dimensional real tensor space, with dimensions as follows: ; Input the total time step of the historical sequence; This represents the total number of sensor nodes in the road network. The original traffic flow feature dimension is used to obtain the initial feature embedding. ,in, embedding of initial features Dimension; , This is a mapping function for the fully connected layer, so that subsequent modules can process it. Considering that traffic flow data has obvious daily and weekly periodic characteristics, this embodiment pre-constructs two learnable periodic embedding dictionaries: a weekly periodic dictionary. Daily Cycle Dictionary ;in, Embed the vector dimension for a single cycle; This represents the dimension of a single daily periodic embedding vector. The weekly periodic dictionary stores the weekly periodic embeddings corresponding to different weekday indices, while the daily periodic dictionary stores the daily periodic embeddings corresponding to different intraday time slice indices. For example, if the sampling interval is 5 minutes, then there are 288 time slices within a day, and correspondingly, the daily periodic dictionary contains 288 learnable embedding vectors.

[0025] When extracting periodic embedding features, the corresponding weekday index and intraday time slice index are obtained for each sample in the historical traffic flow data based on its timestamp. Subsequently, the periodic embedding is retrieved from the periodic dictionary using the weekday index as the key. The daily cycle embedding is retrieved from the daily cycle dictionary using the intraday time slice index as the key. Finally, the weekly and daily periodic embeddings are concatenated to generate a unified periodic embedding feature. This serves as the input for the subsequent cycle-event fusion module.

[0026] It should be noted that the mapping process of the fully connected layer is not a necessary step in extracting periodic embedded features. Those skilled in the art can complete the fusion of the original features and periodic features as a whole in the data embedding stage according to actual needs.

[0027] As one possible implementation, the multi-scale self-supervised temporal reconstruction in step S1 includes: using multiple parallel temporal reconstruction branches to process historical time windows of different lengths, each branch learning abnormal event patterns at different time granularities through a self-supervised reconstruction loss function, and fusing the outputs of each branch into dynamic event embedding features.

[0028] While periodic patterns provide important prior information for traffic forecasting, sudden events (such as traffic accidents, severe weather, or large-scale events) can disrupt existing traffic patterns and significantly affect forecast accuracy. Existing methods that rely on static prior information struggle to effectively capture such non-stationary disturbances. To address this, embodiments of this application construct a multi-scale dynamic event encoder to extract spatiotemporal representations of events from raw traffic flow data using a self-supervised learning approach.

[0029] Specifically, the multi-scale dynamic event encoder comprises multiple parallel temporal reconstruction branches, each processing historical time windows of varying lengths to capture event features at different temporal granularities. Each branch employs an autoencoder structure built with gated recurrent units, mapping the input subsequence to a hidden representation, which is then reconstructed by the decoder. A self-supervised reconstruction loss function guides each branch to learn anomalous event patterns at the corresponding time scale, and the outputs of each branch are ultimately fused into dynamic event embedding features. This design eliminates the need for manual event labeling, enabling the model to automatically perceive and characterize the spatiotemporal characteristics of sudden traffic events.

[0030] For example, this application provides a multi-scale temporal reconstruction framework based on a GRU autoencoder, comprising three parallel branches. The short-scale branch processes the first T1 = T / 6 time steps, the medium-scale branch processes the first T2 = T / 2 time steps, and the long-scale branch processes all T3 = T time steps, respectively capturing instantaneous perturbations, intermediate events, and long-term evolution trends. Each branch encoder maps the input subsequence to a hidden representation, denoted as... , This is the set of temporal hidden features output by the three parallel GRU autoencoder branches in the multi-scale self-supervised temporal reconstruction module. It is a short-timescale branch. It is a branch with a medium time scale. For the long-term branch, the decoder reconstructs the original sequence. To guide the model to focus on anomalous patterns, a multi-scale weighted reconstruction loss is introduced:

[0031] in, For multi-scale weighted reconstruction loss, and Let i and j represent the reconstructed sequence at the i-th scale and the original input, respectively. These are the weighting coefficients. This is the mean squared error loss function.

[0032] For example, to explicitly model the propagation process of emergencies in a road network, the multi-scale dynamic event encoder also includes a spatial perception aggregation module. The spatial perception aggregation module constructs a geographic adjacency matrix based on road connectivity. Furthermore, graph convolution operations are used to spatially aggregate the hidden states at each time step.

[0033] As one possible implementation, the graph convolution operation employs a spectral graph convolution approximated by Chebyshev polynomials. Specifically, it reconstructs the hidden states of the long-scale branch outputs in a multi-scale temporal reconstruction branch. As input, where To hide the state dimension, spatial aggregation calculations are performed step-by-step: normalized graph Laplacian matrices and Chebyshev polynomials are used to weighted fuse neighbor information of each order. The order of the Chebyshev polynomial is a configurable hyperparameter used to control the receptive field size of spatial aggregation. By adjusting the order k, the spatial influence range from first-order neighbors to multi-hop neighbors can be flexibly captured.

[0034] Compared to standard graph convolution, Chebyshev polynomial approximation can effectively model the spatial propagation characteristics of sudden events in road networks while reducing computational complexity. After spatial aggregation processing, the final event embedding features are obtained. It integrates the anomaly patterns of each node with their spatial neighborhood information, among which, By embedding feature dimensions into events, a dynamic event representation with spatial awareness is provided for subsequent spatiotemporal modeling.

[0035] The formula is as follows:

[0036] in, For the normalized graph Laplace matrix, For the k-th order Chebyshev polynomial, For learnable parameters, This refers to the event hiding features that incorporate neighborhood information after spatial aggregation.

[0037] After obtaining periodic embedding features and dynamic event embedding features, in order to further enhance the model's ability to represent the spatiotemporal heterogeneity of traffic data, this application also introduces learnable spatiotemporal identity embedding and location encoding to construct a unified input representation containing complete spatiotemporal information.

[0038] Specifically, learnable temporal embeddings are introduced. and spatial embedding .in, Embedding dimensions for time, For spatial embedding, temporal embedding is used to characterize the dynamic changes at different time steps, while spatial embedding is used to characterize the spatial differences between different road network nodes. Furthermore, to preserve the temporal sequence information of traffic flow sequences, sine-cosine position coding is used to encode temporal positions.

[0039] in, For location index, For dimensional indexes, the time location encoding is denoted as... , Encoding dimension for time location, This is the encoded value corresponding to the i-th feature dimension.

[0040] For each time position in the sequence, the corresponding sine and cosine function values ​​are calculated based on the position's index and the feature dimension index, generating a time position encoding vector. This encoding method enables the model to perceive the sequential relationship between different time steps in the sequence, providing positional information for subsequent attention mechanisms.

[0041] The learnable temporal embeddings, spatial embeddings, and temporal location codes mentioned above are collectively incorporated into the data embedding layer and fused with original traffic features, periodic embedding features, and dynamic event embedding features to provide the spatiotemporal encoder with a unified input representation containing spatiotemporal identity information. Finally, all embeddings are concatenated to obtain a unified input representation.

[0042] in, For unified input embedding after integrating all information, For periodic-event cross-attention fusion features, Embedding learnable time-based identities. Embedding of learnable spatial node identities Encoding the time position for sine and cosine signals. This represents the total feature dimension after concatenation. This represents the total dimension after concatenation. As a periodic-event fusion feature dimension, Embedding dimensions for learnable time-based identities. Embedding dimensions for the identity of learnable spatial nodes. The time position encoding dimension for sine and cosine is used; for the sake of simplicity in subsequent notation, it will be uniformly referred to as [missing term]. It is X.

[0043] S2. Periodic-event fusion features are generated using periodic embedding features as queries and dynamic event embedding features as keys and values ​​through a cross-attention mechanism.

[0044] With periodic embedding features and dynamic event embedding features These are used as query, key, and value, respectively, to achieve context-aware feature interaction. Specifically, the input is mapped to the query, key, and value space through linear projection:

[0045] in, , , For learnable projection matrices, For periodic embedding features Feature dimensions, This represents the feature dimension for single-head attention. Multi-head attention is then used for computation.

[0046]

[0047] in, For the output of the i-th attention head, To split the Q, K, V submatrices up to the i-th head, For normalized activation functions, The output after fusion For each attention head, h represents the dimension, where h is the number of attention heads. To output the projection matrix for multi-head fusion, To unify the hidden layer dimensions of the model, a fused representation is finally obtained through residual connections and layer normalization:

[0048] in, To perform random deactivation regularization on the attention output H, This is a layer normalization operation.

[0049] S3. Input the periodic-event fusion features into the time coding branch and the spatial coding branch respectively for parallel processing to obtain time-dependent features and spatial-dependent features.

[0050] For example, the time encoding branch in step S3 includes: extracting local time dependency features of the period-event fusion features through a gated recurrent unit, and then performing global time modeling on the local time dependency features through a multi-head self-attention mechanism to obtain the time dependency features.

[0051] For example, the spatial encoding branch in step S3 includes: fusing the geographic adjacency graph, the semantic similarity graph, and the dynamic learning graph to construct an adaptive fusion graph; extracting local spatial dependency features of the periodic-event fusion features through a graph convolutional network; and then performing global spatial modeling on the local spatial dependency features through a multi-head self-attention mechanism to obtain spatial dependency features.

[0052] Time dependency modeling is a crucial step in traffic flow prediction. In real-world traffic scenarios, time dependencies exhibit two typical patterns: short-term continuous dependencies between adjacent time steps, and periodic similarity patterns across time steps. While traditional recurrent neural networks (RNNs) excel at capturing local time dependencies, they are prone to the vanishing gradient problem when processing long sequences; multi-head self-attention mechanisms, although capable of modeling global time dependencies, have limited ability to perceive local dynamic changes.

[0053] To take into account the modeling advantages of both local and global dependencies, this application embodiment designs a time-coding branch that integrates a gated recurrent unit and a multi-head self-attention mechanism.

[0054] Specifically, a gated recurrent unit (GRU) is first used to process the periodic-event fusion features, extracting local temporal dependencies from the sequence. The GRU, through its update and reset gate mechanisms, effectively mitigates the vanishing gradient problem in long sequences, preserving short-term, continuously changing pattern information. Subsequently, the local temporal dependencies output by the GRU are used as input to perform global temporal modeling through a multi-head self-attention mechanism, capturing long-range dependencies between different time steps in the sequence. The multi-head self-attention mechanism enables parallel computation of attention weights between time steps, allowing the model to perceive periodic similarity patterns across time steps.

[0055] Through the cascaded modeling of local and global time dependencies described above, the time-dependent features are finally obtained, which serve as the input for the subsequent spatiotemporal coordinated modulation module.

[0056] As one possible implementation, in order to extract local temporal patterns from the input sequence, the gated recurrent unit is configured to generate the query matrix, key matrix, and value matrix required for subsequent multi-head self-attention mechanisms.

[0057] Specifically, three independent gated loop unit branches are set up. Process the input sequences separately This generates corresponding query features, key features, and value features. Each gated recurrent unit branch operates according to a standard gated recurrent unit update mechanism: for the current input features and the previous hidden state, the degree of forgetting of historical information and the proportion of new information integration are controlled through the collaborative computation of update gates and reset gates. Specifically, the update gate determines how much of the previous hidden state is retained in the current time step, and the reset gate determines how much of the previous hidden state is used to calculate the current candidate state. Through element-wise multiplication and linear transformation of the learnable weight matrix, the current hidden state is finally output.

[0058] For example, the update process of the gated loop unit is as follows:

[0059]

[0060]

[0061]

[0062] in, and These represent updating the door and resetting the door, respectively. This represents element-wise multiplication. This is the hidden state from the previous moment. The input features at the current time, , and For learnable weight matrix, Let be the candidate hidden state at time t. The final output hidden feature of the GRU at time t is shown. This gated recurrent unit mechanism can effectively capture short-term temporal dependencies in the sequence, providing context-enhanced feature representations for subsequent global attention modeling, enabling the model to focus on long-term dependencies without losing information about local dynamic changes.

[0063] After obtaining the local temporal dependency features enhanced by the gated recurrent unit, a multi-head self-attention mechanism is used to model the global temporal dependency of the local features.

[0064] Specifically, the local time-dependent features are first mapped to a query matrix, a key matrix, and a value matrix through linear projection, and each matrix is ​​then split into multiple attention heads along the feature dimension, for example, h heads:

[0065]

[0066] in, , and This is the learnable parameter matrix.

[0067] Each attention head independently calculates its attention weights: the dot product of the transpose of the query matrix and the key matrix is ​​performed, scaled, and normalized to obtain the attention distribution, which is then weighted and summed with the value matrix to generate the output of that head. The outputs of each attention head are concatenated along the feature dimension and then linearly mapped to obtain the global temporal features.

[0068] in, This is the output projection matrix. To stabilize the training process and promote gradient propagation, a residual connection and layer normalization operation are introduced after the multi-head self-attention layer. The input features are added to the attention output and then normalized.

[0069] Furthermore, a feedforward neural network is used to perform a nonlinear transformation on the normalized features to enhance the model's expressive power.

[0070] in, For the input features of the FFN module, The weight matrix is ​​a learnable matrix. , This is the bias vector of the feedforward network. For the hidden layer dimension of the feedforward network, To unify the hidden layer dimension of the model, a feedforward neural network typically consists of two linear transformation layers and a non-linear activation function, where the hidden layer dimension is usually set to two to four times the input dimension. The output of the feedforward neural network is then processed through residual connections and layer normalization to obtain the final output of the temporal encoding branch, i.e., the temporal dependent features.

[0071] Spatial dependency modeling is crucial for traffic flow prediction. In traffic networks, spatial relationships mainly manifest in two typical patterns: adjacent nodes interact directly via roads, while geographically distant but functionally similar nodes may exhibit similar traffic patterns. Graph convolutional networks excel at capturing spatial dependencies in local neighborhoods but struggle to identify functional relationships between distant nodes; multi-head self-attention mechanisms can model global node interactions but have limited ability to perceive local topology.

[0072] To balance the modeling advantages of local spatial dependencies and global spatial associations, this application proposes a spatial encoding branch that integrates graph convolutional networks and multi-head self-attention mechanisms. Specifically, firstly, an adaptive graph learning module fuses geographical adjacency, semantic similarity, and dynamically learned relationships to construct an adaptive fusion graph containing multi-view spatial associations. Then, a graph convolutional network is used to extract local spatial dependencies from the periodic-event fusion features to capture direct interactions between adjacent nodes and the spatial propagation characteristics of multi-hop neighborhoods. Based on this, the local spatial features output by the graph convolutional network are input into the multi-head self-attention mechanism for global spatial modeling to identify remote functional associations between different nodes.

[0073] The effectiveness of graph convolutional networks depends on the quality of the graph structure, and a single type of adjacency matrix cannot fully reflect the complex spatial relationships in transportation networks. Therefore, embodiments of this application construct three different types of graph structures to mine the spatial relationships between nodes from three perspectives: physical connectivity, functional similarity, and dynamic changes.

[0074] The geographic adjacency graph is constructed based on the physical connectivity between sensor nodes in the road network. When there is a direct road connection between two nodes, a weight is assigned to the corresponding position in the adjacency matrix; otherwise, it is set to zero. The adjacency matrix is ​​represented as follows:

[0075] in, Let i represent the connection state between node i and node j. For the i-th road network sensor node, For the j-th road network sensor node, It is the set of all physical road edges in the road network.

[0076] Semantic similarity graphs are constructed by measuring the similarity of historical traffic flow sequences between nodes. A dynamic time warping algorithm is used to calculate the sequence similarity between each pair of nodes, and each node is connected to its K most similar nodes to form a spatial association graph reflecting functional similarity. Its expression is as follows:

[0077] in, Determine whether a semantic association edge is established between node i and node j. Let node j be the K neighbors with the highest similarity to node i.

[0078] The dynamic graph is generated through learnable node embeddings, without relying on predefined physical or semantic priors. Specifically, two learnable node embedding matrices are introduced. and a bias vector , This represents the total number of sensor nodes in the road network. Given the feature dimension of the node embedding vector, the dynamic adjacency matrix is ​​calculated based on the similarity of the embedding vectors:

[0079] in, To correct the linear activation function, This is a function for generating diagonal matrices.

[0080] This enables the model to adaptively extract potential spatial dependencies from the data.

[0081] After obtaining the above three graph structures, an attention mechanism is used to adaptively fuse the geographic adjacency graph, semantic similarity graph, and dynamic graph:

[0082] in, , , These correspond to the attention weights for dynamic graphs, geographic graphs, and semantic graphs, respectively. To adaptively fuse the adjacency matrix, To dynamically learn the adjacency matrix, It is a geographic adjacency matrix. This is a semantically similar adjacency matrix.

[0083] The attention mechanism dynamically calculates weight coefficients for each graph structure; a higher weight indicates a greater contribution of the graph to the current prediction task. The three weighted adjacency matrices are then summed to obtain the fused adaptive adjacency matrix.

[0084] Finally, the adaptive adjacency matrix is ​​symmetrically normalized and sparsified to ensure numerical stability and reduce computational complexity.

[0085] In obtaining the adaptive fusion map Then, spectral convolution operation is used to extract local spatial dependencies of periodic-event fusion features.

[0086] As one possible implementation, spectral graph convolution employs a Chebyshev polynomial approximation. Specifically, a spectral domain convolution is performed on the fused graph using a normalized graph Laplacian matrix and a Chebyshev polynomial, with weighted aggregation of neighbor information at each order through learnable convolution kernel parameters. The order of the Chebyshev polynomial is a configurable hyperparameter used to control the size of the spatial receptive field, thereby flexibly capturing the spatial influence range from first-order neighbors to multi-hop neighbors. The expression is as follows:

[0087] Where S is the output of the spectral convolution. For learnable convolution kernel parameters, Let be the k-th order Chebyshev polynomial transformation function. For the normalized graph Laplacian matrix, Input features to the graph convolution module.

[0088] After obtaining the local spatial features extracted by spectral graph convolution, a multi-head self-attention mechanism is used to model the global node interactions of the local spatial features S:

[0089]

[0090] in, , and For learnable parameter matrix, Let h be the query matrix of the h-th attention head. Let h be the key matrix of the h-th attention head. Let S be the value matrix of the h-th attention head, and S be the output of the spectral convolution. The feature result output by the h-th attention head. For the feature dimensions of a single attention head, To normalize by row.

[0091] Specifically, the local spatial features are first mapped to a query matrix, a key matrix, and a value matrix through linear projection, and each matrix is ​​then split into multiple attention heads along the feature dimensions. Each attention head independently calculates the attention weights between nodes: the dot product of the transposes of the query and key matrices is performed, scaled, and normalized to obtain the attention distribution, which is then weighted and summed with the value matrix to generate the head's output. The outputs of each attention head are concatenated along the feature dimensions and then linearly mapped to obtain the global spatial attention output.

[0092] in, This is the output projection matrix. To maintain the stability of the training process and promote gradient propagation, a residual connection and layer normalization operation are introduced after the multi-head self-attention layer. The input features are added to the attention output and then normalized.

[0093] Furthermore, a feedforward neural network is used to perform a nonlinear transformation on the normalized features to enhance the model's ability to express spatial dependencies.

[0094]

[0095] in, The output features of the feedforward neural network FFN; The final output of the spatial coding branch, The weight matrix is ​​a learnable matrix. , This is the bias vector of the feedforward network. For the hidden layer dimension of the feedforward network, To unify the hidden layer dimension of the model.

[0096] For example, a feedforward neural network consists of two linear transformation layers and a nonlinear activation function. The output of the feedforward neural network is then passed through residual connections and layer normalization to obtain the final output of the spatial coding branch, i.e., the spatial dependency feature.

[0097] This spatial dependency feature integrates the local neighborhood information of nodes with global functional associations, enabling comprehensive modeling of the complex spatial dependencies of transportation networks.

[0098] S4. In each layer of the encoder between the temporal coding branch and the spatial coding branch, modulation parameters are generated through bidirectional cross-attention. The modulation parameters are then used to perform dynamic affine transformation on the features of the other branch to output spatiotemporal co-features.

[0099] In a hierarchical spatiotemporal coding architecture, the temporal coding branch and the spatial coding branch process their respective features independently, resulting in insufficient information exchange between them. To enhance spatiotemporal coupling modeling capabilities, this application proposes an adaptive spatiotemporal co-modulation module, embedded between each layer's temporal encoder and spatial encoder. The adaptive spatiotemporal co-modulation module comprises three components: a cross-attention gating generator, a feature linear modulation parameter generation unit, and a feature linear modulation unit. The cross-attention gating generator establishes a bidirectional information path between temporal and spatial features; the feature linear modulation parameter generation unit generates scaling factors and bias terms based on the context vector generated by the cross-attention gating; and the feature linear modulation unit performs dynamic affine transformations on the features of the other branch using the scaling factors and bias terms. Through this structure, the module enables bidirectional co-modulation of spatiotemporal features, enhancing the model's ability to characterize complex spatiotemporal dynamics.

[0100] As one possible implementation, the generation of modulation parameters through bidirectional cross-attention in step S4 includes: using the temporal features output by the temporal coding branch as a first query, and the spatial features output by the spatial coding branch as a first key and a first value, to generate a first temporal context vector through the first cross-attention; using the spatial features output by the spatial coding branch as a second query, and the temporal features output by the temporal coding branch as a second key and a second value, to generate a second spatial context vector through the second cross-attention.

[0101] As one possible implementation, step S4, which uses modulation parameters to perform dynamic affine transformation on the features of another branch, includes: inputting a first time context vector into a first multilayer perceptron to generate a scaling factor and bias term for the time branch, and using the scaling factor and bias term for the time branch to perform an affine transformation on the spatial features; inputting a second spatial context vector into a second multilayer perceptron to generate a scaling factor and bias term for the spatial branch, and using the scaling factor and bias term for the spatial branch to perform an affine transformation on the temporal features.

[0102] The cross-attention gating generator establishes a direct information path between temporal and spatial features through a bidirectional cross-attention mechanism. Specifically, for the first... Temporal characteristics of layer encoder output and spatial features , For batch size, To input the time step of the historical sequence, This represents the total number of sensor nodes in the road network. To determine the hidden layer feature dimensions of a single-layer encoder, the query matrix, key matrix, and value matrix for the temporal and spatial branches are first generated using linear projection: , , , , This is a learnable projection matrix. The query matrix for temporal features and the key and value matrices for spatial features are used for cross-attention in the first direction; the query matrix for spatial features and the key and value matrices for temporal features are used for cross-attention in the second direction. Cross-attention calculation involves performing a dot product operation on the transposes of the query matrix and the key matrix, scaling and normalizing to obtain the attention weights, and then weighted summing these weights with the value matrix to generate a context vector. The context vector includes a first temporal context vector and a second spatial context vector, each encoding key information from the other feature dimension. The formula is as follows:

[0103]

[0104] in, and These are the first temporal context vector and the second spatial context vector, respectively.

[0105] The aforementioned context vectors are processed using independent multilayer perceptrons to generate feature linear modulation parameters for both temporal and spatial features. Specifically, the feature linear modulation parameters include a scaling factor and a bias term. The scaling factor adjusts the importance of each dimension of the feature, while the bias term adjusts the baseline level of the feature. The formula is as follows:

[0106]

[0107] in, and Scaling factor and As a bias term, during the feature modulation stage, affine transformations are performed on the original temporal and spatial features respectively; A multilayer perceptron specifically designed for time-branching; A multilayer perceptron is designed specifically for spatial branches. To ensure the scaling factor has bidirectional adjustment capabilities for both enhancement and suppression, an activation function 1 + tanh( The scaling factor is constrained to a preset range (0, 2):

[0108]

[0109] These are the updated temporal and spatial features after spatial context modulation. for The output bias term, for The output bias term; This is an element-wise multiplication; after the affine transformation, residual connections and layer normalization operations are introduced, and the modulated features are added to the original features before normalization:

[0110]

[0111] The first The temporal branch input feature tensor and the spatial branch input feature tensor of the layer encoder For the first Layer original time characteristics, The incremental temporal features modulated by spatial context information. For the first Layer original spatial characteristics, The incremental spatial features modulated by temporal context information. For layer normalization, the modulated temporal and spatial features of the layer are obtained and used as input to the next layer encoder.

[0112] The adaptive spatiotemporal collaborative modulation module guides the deep fusion of temporal and spatial features layer by layer, effectively characterizing the spatiotemporal dynamic evolution of complex traffic scenarios.

[0113] For example, after step S4, step S5 is also included: fusing the spatiotemporal collaborative features output by the multi-layer spatiotemporal encoder, generating prediction results through a hybrid projection layer; and training the model using a multi-task loss function, which includes the main prediction loss and the self-supervised reconstruction loss of multi-scale self-supervised temporal reconstruction.

[0114] After multi-layer adaptive spatiotemporal co-modulation, the temporal features output from each layer of the time coding branch are... Spatial features output from each layer of the spatial coding branch By fusing the results, we obtain the final spacetime representation:

[0115] For example, the output layer employs a hybrid projection structure, integrating the temporal and feature dimensions to generate a predicted sequence. This structure simplifies the network structure while maintaining the integrity of spatiotemporal information.

[0116] To simultaneously optimize traffic flow prediction performance and event representation capabilities, this embodiment employs a multi-task loss function for model training. The multi-task loss function comprises two parts: the main prediction loss and the self-supervised reconstruction loss for multi-scale self-supervised temporal reconstruction. These two parts are weighted and summed according to preset weights. The expression is as follows:

[0117] in, Train the total loss function for the model. Here is the Huber loss function. For the loss of self-supervised reconstruction, The loss weight hyperparameter is set to 0.2 in this embodiment; the main prediction loss uses the Huber loss function. The Huber loss function exhibits a quadratic form when the prediction error is less than a preset sensitivity threshold, and degenerates into a linear penalty when the prediction error is greater than or equal to the threshold. This design can improve the robustness of the model to abnormal fluctuations. The Huber loss function is as follows:

[0118] in, For real labels, The model predicts the output; For the loss of self-supervised reconstruction, The sensitivity threshold is defined as follows. The self-supervised reconstruction loss is the sum of the weighted reconstruction losses of each temporal reconstruction branch in the multi-scale dynamic event encoder. By jointly optimizing the main prediction task and the event reconstruction task, the dynamic event embedding features learned by the event encoder are made more beneficial to the final prediction.

[0119] The above description only illustrates the preferred embodiments of the present invention. However, the present invention is not limited to the above embodiments. Within the scope of knowledge possessed by those skilled in the art, various changes can be made without departing from the spirit of the present invention, and all such changes should be included within the protection scope of the present invention.

Claims

1. A traffic flow prediction method that integrates multi-scale self-supervised and attention mechanisms, characterized in that, Includes the following steps: S1. Obtain historical traffic flow data, extract periodic embedding features, and learn dynamic event embedding features from the historical traffic flow data through multi-scale self-supervised temporal reconstruction. S2. Using the periodic embedding feature as the query and the dynamic event embedding feature as the key and value, a periodic-event fusion feature is generated through a cross-attention mechanism; S3. Input the periodic-event fusion features into the parallel-set time coding branch and spatial coding branch for processing to obtain the time-dependent features and spatial-dependent features respectively; S4. Between each layer of the encoder in the temporal coding branch and the spatial coding branch, modulation parameters are generated through bidirectional cross-attention. The modulation parameters are then used to perform a dynamic affine transformation on the features output by the other branch, resulting in the output of multi-layer spatiotemporal collaborative features.

2. The traffic flow prediction method based on the fusion of multi-scale self-supervised and attention mechanisms according to claim 1, characterized in that, The implementation method of multi-scale self-supervised temporal reconstruction in step S1 is as follows: set up multiple parallel temporal reconstruction branches, each branch uses a historical time window of different length to process the input traffic flow sequence; each branch learns the traffic abnormal event pattern at the corresponding time granularity based on the self-supervised reconstruction loss function, and the outputs of all branches are fused to obtain dynamic event embedding features.

3. The traffic flow prediction method based on the fusion of multi-scale self-supervised and attention mechanisms according to claim 1, characterized in that, The extraction of periodic embedding features in step S1 specifically includes: obtaining the weekday index and intraday time slice index based on the timestamps of historical traffic flow data; retrieving the weekday embedding and daily embedding from the pre-built weekday embedding dictionary and daily embedding dictionary respectively; and concatenating the weekday embedding and daily embedding to generate periodic embedding features.

4. The traffic flow prediction method based on the fusion of multi-scale self-supervised and attention mechanisms according to claim 1, characterized in that, The time-encoding branch processing flow in step S3 is as follows: a gated recurrent unit is used to extract the local time dependency features of the period-event fusion features; then, a multi-head self-attention mechanism is used to perform global time modeling on the local time dependency features, and output the time dependency features.

5. The traffic flow prediction method based on the fusion of multi-scale self-supervised and attention mechanisms according to claim 1, characterized in that, The spatial encoding branch processing flow in step S3 is as follows: merging the geographic adjacency graph, semantic similarity graph, and dynamic learning graph to construct an adaptive fusion graph; based on the adaptive fusion graph, using a graph convolutional network to extract the local spatial dependency features of the periodic-event fusion features; Then, a multi-head self-attention mechanism is used to perform global spatial modeling on the local spatial dependency features, and the spatial dependency features are output.

6. The traffic flow prediction method based on the fusion of multi-scale self-supervised and attention mechanisms according to claim 1, characterized in that, Step S4 generates modulation parameters through bidirectional cross-attention, including: Perform the first cross-attention calculation: take the temporal dependency feature output by the temporal encoding branch as the first query, and the spatial dependency feature output by the spatial encoding branch as the first key and the first value, and calculate to obtain the first temporal context vector; Perform the second cross-attention calculation: use the spatial dependency features output by the spatial encoding branch as the second query, and the temporal dependency features output by the temporal encoding branch as the second key and the second value, and calculate to obtain the second spatial context vector; The first temporal context vector and the second spatial context vector are used to generate modulation parameters.

7. The traffic flow prediction method based on the fusion of multi-scale self-supervision and attention mechanisms according to claim 6, characterized in that, Step S4, which involves performing a dynamic affine transformation using modulation parameters, includes: The first temporal context vector is input into the first multilayer perceptron to generate a scaling factor and bias term to adapt the spatial branch. The scaling factor and bias term are then used to perform an affine transformation on the spatial dependency features. The second spatial context vector is input into the second multilayer perceptron to generate a scaling factor and bias term that adapt to the time branch. The scaling factor and bias term are then used to perform an affine transformation on the time-dependent features.

8. The traffic flow prediction method based on multi-scale self-supervision and attention mechanism fusion as described in claim 2, characterized in that: Each temporal reconstruction branch adopts a GRU autoencoder structure; the self-supervised reconstruction loss is a multi-scale weighted reconstruction loss, which is obtained by weighted summation of the mean square error loss of each branch at the corresponding time scale; the generation of the dynamic event embedding features also includes a spatially aware aggregation step: based on the geographic adjacency matrix, Chebyshev multinomial spectral graph convolution is used to spatially aggregate the temporal hidden states output by each temporal reconstruction branch.

9. The traffic flow prediction method based on the fusion of multi-scale self-supervision and attention mechanisms according to claim 5, characterized in that: The dynamic learning graph is generated by operations on two sets of learnable node embedding matrices and bias vectors. The adjacency matrices corresponding to the geographic adjacency graph, semantic similarity graph, and dynamic learning graph are weighted by adaptive attention weights respectively. After weighted summation, the graph is obtained by symmetric normalization and sparsification.

10. The traffic flow prediction method based on the fusion of multi-scale self-supervision and attention mechanisms according to claim 1, characterized in that: Step S4 is followed by step S5: the spatiotemporal collaborative features output by the multi-layer spatiotemporal encoder are fused, and a prediction result is generated through a hybrid projection layer; the model is trained using a multi-task loss function, which includes the main prediction loss and the self-supervised reconstruction loss of the multi-scale self-supervised temporal reconstruction. The main prediction loss uses the Huber loss function; the multi-task loss function is calculated using the following formula: ,in The loss is denoted by λ, which represents the weighting coefficient of the self-supervised reconstruction loss. This is the multi-scale weighted reconstruction loss.