Traffic time sequence modeling method based on traffic semantic representation
By aligning environmental factors and road network attributes in the traffic semantic space and combining them with an improved long short-term memory network for traffic state prediction, the problems of long-term prediction error accumulation and neglect of environmental factors are solved, and traffic speed prediction with higher accuracy and robustness is achieved.
Patent Information
- Application Number
- CN202511637183.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-10
- Publication Date
- 2026-02-13
AI Technical Summary
Existing traffic speed prediction methods suffer from error accumulation in long-term prediction accuracy and fail to effectively integrate traffic environment factors, resulting in insufficient prediction accuracy and robustness.
A temporal modeling method based on traffic semantic representation is adopted. By aligning environmental factors and road network attributes in the traffic semantic space through a traffic environment encoder and a road network encoder, and combining an improved long short-term memory network, the temporal inference of traffic state is performed to predict traffic speed.
It improves the accuracy and robustness of long-term traffic speed prediction, enhances the ability to identify and adapt to abnormal traffic events, and solves the problems of prediction error accumulation and neglect of environmental factors in existing technologies.
Smart Images

Figure CN121525458A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of intelligent transportation systems, and particularly relates to a traffic time sequence modeling method based on traffic semantic representation. BACKGROUND
[0002] The intelligent transportation system develops rapidly, providing massive data for road traffic research. Mining traffic state features from these data has become a major research hotspot. At the same time, long-term accurate traffic speed prediction is also an important task of the intelligent transportation system, which plays an important role in improving traffic efficiency and ensuring traffic safety.
[0003] The existing methods have two significant challenges in long-term prediction. One is the challenge of long-term prediction, and the other is the challenge of integrating environmental factors. First, when predicting long-term, the model usually needs to predict the future speed through multiple iterations. However, the prediction error of each step will gradually accumulate, resulting in a large error in the final prediction result. For example, when predicting traffic speed for an hour or even longer, even if the prediction error of each step is small at the beginning, after multiple iterations, the accumulated error will still increase significantly. Secondly, traffic speed is not only affected by historical traffic data, but also by various environmental factors such as weather, time, traffic management measures, etc. The existing methods only predict speed based on traffic data itself, often ignoring the influence of traffic environmental factors on speed prediction, limiting the prediction accuracy and robustness.
[0004] Therefore, there is an urgent need for a traffic time sequence modeling method based on traffic semantic representation to solve the problem of long-term prediction accuracy in the existing technology, improve the identification and adaptability of abnormal traffic events, and provide a feasible path for building a robust and high-sensitivity intelligent traffic state prediction system. It helps to solve the problem of not responding in time to sudden and dynamic information in current traffic state prediction. SUMMARY
[0005] To solve the technical problems described in the background art and improve the time sequence modeling capability and prediction accuracy of traffic states in urban road networks.
[0006] The purpose of the present application is to provide a traffic time sequence modeling method based on traffic semantic representation, comprising the following steps:
[0007] Collect traffic environmental factors and traffic network attributes, and construct a traffic semantic space; use contrastive learning to train traffic semantic encoder and decoder, so that traffic environmental factors and traffic network attributes are aligned and encoded in the traffic semantic space;
[0008] Based on the traffic semantic feature time sequence deduction model, the traffic state is time sequence deduced on the traffic semantic space, and the predicted traffic state index is output.
[0009] The traffic semantic codec comprises a traffic environment encoder, a traffic road network encoder, and a traffic semantic decoder; the traffic semantic feature time sequence deduction model comprises a historical traffic flow time sequence feature extraction module and a future traffic flow time sequence feature deduction module fused with environment features; the traffic state index comprises a speed, a density, and a flow; the traffic environment factor comprises a weather, a time, a workday and holiday state, and a traffic policy; and the traffic road network attribute comprises a traffic road network speed.
[0010] The collection of the traffic environment factor and the traffic road network attribute and the construction of the traffic semantic space comprise:
[0011] Step S11: The traffic environment factor and the traffic road network attribute are acquired, and the traffic environment factor and the traffic road network attribute are cleaned, normalized, and structure-mapped;
[0012] Step S12: The traffic environment factor is input into the traffic environment encoder to obtain future traffic environment encoding, the traffic road network attribute is input into the traffic road network encoder to obtain historical traffic road network encoding, the traffic semantic codec is trained using contrastive learning, and the future traffic environment encoding and the historical traffic road network encoding are aligned to form a traffic semantic space;
[0013] Step S13: The pre-trained traffic environment encoder and the traffic road network encoder are combined with the traffic semantic decoder to form the traffic semantic codec.
[0014] The training of the traffic semantic codec using contrastive learning comprises:
[0015] A positive sample pair is defined as two encodings describing the same traffic state, and a negative sample pair is defined as encodings describing different traffic states, and similarity is measured by calculating the similarity between the encodings;
[0016] The cosine similarity is used to measure the similarity, and the temperature parameter and the Softmax function are used for normalization;
[0017] The InfoNCE loss is used as a loss function to optimize the performance of the encoder, so that the encodings generated by the traffic environment encoder and the traffic road network encoder can be effectively aligned in the traffic semantic space;
[0018] The calculation formula of the cosine similarity for measuring similarity is:
[0019] (1)
[0020] (2)
[0021] In the formula, A and B represent the traffic environment encoding and the traffic road network encoding, respectively, and representing the components of the encoding vector, d represents the dimension of the encoding, and K represents the batch size of the training; wherein is a temperature hyperparameter, and takes a value of 0.2 or 0.07, is a similarity function, and softmax is a normalization function;
[0022] The loss function is InfoNCE loss, which is:
[0023] (3)
[0024] wherein, similarity represents a similarity function, K represents a batch size, represents a positive sample pair, represents a negative sample pair.
[0025] The traffic environment encoder adopts a structure of a single feature extraction module and a multi-feature fusion module, the single feature extraction module performs one-hot encoding on a single environmental factor, and places the one-hot encoding result in a fully connected network for feature extraction to form a feature extraction layer; the parameters of the hidden fully connected network layer in the feature extraction layer are shared, and only the input layer and the output layer parameters are different; after obtaining a single feature, the single feature is spliced and placed in a feature fusion module for feature fusion and dimension reduction; the feature fusion module is a multi-layer fully connected network;
[0026] The traffic environment encoder outputs a traffic environment code, and the calculation process includes:
[0027] (4)
[0028] (5)
[0029] wherein, attr represents different traffic environment factors, X represents a single feature extraction result, C represents a traffic environment code, W and b are respectively a weight matrix and a bias, and δ represents an activation function LeakyReLU;
[0030] The traffic environment encoder outputs a dimension of 64.
[0031] The traffic network encoder obtains a traffic network code in combination with a graph multi-head layer and a global readout function, input is a traffic state of a road network at a certain time, output is a semantic code, and output dimension is 64; the graph multi-head attention layer obtains spatial dependence of the road network through multiple heads and layers; the global readout function integrates information of each node and outputs; the traffic network encoder introduces a multi-layer graph attention network and a residual connection to process road network information; the multi-layer graph attention network models connection strength between nodes through different weights; a skip connection is added between each layer to ensure that node information is not lost;
[0032] The calculation formula of the multi-head graph attention network with the residual mechanism is as follows:
[0033] (6)
[0034] (7)
[0035] (8)
[0036] (9)
[0037] In the formula, represents attention weight between node i and node j, h is a feature of the node, is a neighbor of node i, is a hidden feature of the l layer, W is a learnable weight matrix, a is a learnable vector, and δ and g are activation functions LeakyReLU; The global readout function is as follows:
[0038]
[0039] (10)
[0040] In the formula, W and b are a weight matrix and a bias respectively, and δ is an activation function LeakyReLU.
[0041] The traffic semantic decoder is symmetrical to the structure of the traffic network encoder; first, the traffic semantic encoding is converted into a feature on a road network node through an attribute allocation function; then, spatial dependence between different node features is considered through a multi-head attention layer; and finally, traffic speed is output
[0042] The training process of the traffic semantic decoder is as follows:
[0043] (11)
[0044] In the formula, X represents traffic flow in the road network;
[0045] In the traffic semantic decoder training process, the parameters of the traffic network encoder are in a frozen state.
[0046] The traffic semantic feature time sequence deduction model performs time sequence deduction on the traffic state in the traffic semantic space, and predicts the traffic state index, which includes:
[0047] Step S21: design a time sequence feature capturing module to capture the time sequence feature relationship in the traffic semantic space, and use an enhanced residual long short-term memory network to capture the time sequence features of the evolution of the traffic state over time;
[0048] Step S22: based on the completion of single-step time sequence feature capture by the time sequence feature capturing module, design a traffic semantic feature time sequence deduction model;
[0049] The traffic semantic feature time sequence deduction model includes two sub-networks connected to each other: a historical traffic feature extraction module for encoding the semantic evolution process of the historical traffic state; a future traffic speed reasoning module that fuses environmental factors, responsible for time sequence extrapolation of the traffic state combined with future environmental factors; and a priori encoding of future environmental factors as auxiliary input;
[0050] The future environment encoding is embedded in the future traffic flow time sequence feature deduction module that fuses environmental features;
[0051] The reasoning process of the historical traffic flow time sequence feature extraction module and the future traffic flow time sequence feature deduction module that fuses environmental features is as follows:
[0052] The historical traffic flow time sequence feature extraction module receives semantic encoding in the historical time sequence, and uses an enhanced residual long short-term memory network to extract its time sequence dynamic information;
[0053] The end state of the historical traffic flow time sequence feature extraction module serves as the initial state of the future traffic flow time sequence feature deduction module that fuses environmental features, and combines with the future environment encoding input to perform extrapolation of the semantic evolution of the traffic state;
[0054] The future traffic flow time sequence feature deduction module that fuses environmental features generates future traffic semantic encoding at each time step, and restores it to a specific traffic state through a decoder;
[0055] In the training process, the semantic encoder and decoder are frozen, and only the enhanced residual long short-term memory network is optimized to improve training efficiency and stability.
[0056] When predicting the future speed, the pre-trained traffic semantic decoder directly decodes the semantic encoding output by the future traffic flow time sequence feature deduction module that fuses environmental features at each time step, and maps the semantic encoding to the actual road network traffic state.
[0057] The enhanced residual long short-term memory network at the input of the LSTM unit and output Skip connections are added between them, so that the encoding of the traffic semantic space can be directly passed to the output of the LSTM; the enhanced residual long short-term memory network maintains three gating mechanisms, including: input gate, forget gate and output gate;
[0058] The calculation formula for the enhanced residual long short-term memory network includes:
[0059] (12)
[0060] (13)
[0061] (14)
[0062] (15)
[0063] (16)
[0064] (17)
[0065] In the formula, , and These represent the outputs of the input gate, forget gate, and output gate, respectively. The input represents the current time step; , , , , , , and It is the weight matrix of the input vector and the hidden state. , , and These are the corresponding bias terms; This represents the sigmoid activation function. This represents element-wise multiplication. Represents the hyperbolic tangent function. and These represent the output vectors of the cell state and the hidden state at the current time step, respectively.
[0066] The training process of the traffic semantic feature temporal inference model includes four stages: feature extraction, regularization, temporal modeling and parameter optimization.
[0067] Firstly, semantic features are extracted from traffic network characteristics and traffic environment factors, and L2 regularization processing is performed to enhance the numerical stability of the features;
[0068] Subsequently, the future traffic state is inferred and decoded by using a historical traffic flow time series feature extraction module and a future traffic flow time series feature deduction module with environmental characteristics, and a future speed prediction result is output.
[0069] During the training process, an error loss function between the predicted speed and the actual speed is constructed, and the parameters of the HTEM and the FTIMIE are iteratively updated through error back propagation by using an Adam optimizer, so that the ability of modeling the traffic state in the traffic semantic space is finally improved.
[0070] The output predicted traffic state indicators include:
[0071] A multi-scale future prediction result is output, wherein the multi-scale includes: the prediction period ranges from 15 minutes to 180 minutes; a plurality of error indicators are used to evaluate the model effect, and the plurality of error indicators include: RMSE, MAE and MAPE.
[0072] The beneficial effects of the present application are:
[0073] The application discloses a traffic time sequence modeling method based on traffic semantic representation, which is used for predicting traffic speed by fusing a time sequence model of traffic environment factors and traffic network data. The application firstly proposes a traffic semantic space, aligns and encodes traffic environment factors and traffic network attributes in the traffic semantic space, and performs time sequence deduction on traffic states on the traffic semantic space, so that the traffic speed is accurately predicted. The traffic time sequence modeling method based on traffic semantic representation disclosed by the application is named as TraEnv-ResLSTM, and is divided into two blocks: a traffic semantic encoder-decoder (TSED) and a traffic semantic feature time sequence deduction model (TSIM). The traffic semantic encoder-decoder includes a traffic environment encoder (TEE), a traffic network encoder (TNE) and a traffic semantic decoder (TSD); and the traffic time sequence deduction model includes a historical traffic flow time sequence feature extraction module (HTTEM) and a future traffic flow time sequence feature deduction module (FE-FTIM) fusing environment features. The external environment features (including weather, time, workday / rest day, traffic policy, etc.) and internal features (traffic network speed) of the traffic state are encoded into the traffic semantic space by two encoders respectively, and the improved long short-term memory network is used for performing semantic encoding time sequence deduction on the traffic state in the traffic semantic space. Then, the future traffic state semantic code deduced is decoded by the traffic semantic decoder to obtain the traffic speed of the network. The TraEnv-ResLSTM considers the external environment factors affecting the traffic speed when predicting the future speed, and reduces the accumulation of long-term prediction errors. Experimental results show that the method of the application is significantly better than existing methods in various prediction steps. The application solves the problem of long-time prediction accuracy in the prior art, improves the recognition and adaptability of abnormal traffic events, provides a feasible path for constructing a robust and high-sensitivity intelligent traffic state prediction system, and helps to solve the problem that the response to sudden and dynamic information is not timely in the current traffic state prediction. BRIEF DESCRIPTION OF DRAWINGS
[0074] Figure 1 FIG. 1 is a flowchart of the traffic time sequence modeling method based on traffic semantic representation of the application;
[0075] Figure 2 FIG. 5 is a schematic diagram of the traffic semantic information representation learning structure in the embodiment of the application;
[0076] Figure 3 FIG. 7 is a schematic diagram of the time sequence reasoning module ResLSTM in the embodiment of the application;
[0077] Figure 4 FIG. 9 is a schematic diagram of the traffic semantic time sequence reasoning model framework in the embodiment of the application;
[0078] Figure 5Figure 1 is a schematic diagram of the error distribution comparison of different methods in the embodiment of the present application, wherein (a) is the RMSE evaluation result of all models, (b) is the MAE evaluation result of all models, (c) is the MAPE evaluation result of all models, (d) is the RMSE evaluation result of TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models, (e) is the MAE evaluation result of TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models, and (f) is the MAPE evaluation result of TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models;
[0079] Figure 6 Figure 2 is a schematic diagram of the error distribution comparison of different speeds in the embodiment of the present application, wherein (a) is the result of 60-minute prediction step, (b) is the result of 120-minute prediction step, and (c) is the result of 180-minute prediction step;
[0080] Figure 7 Figure 3 is a schematic diagram of the error distribution of different methods at different times of the day in the embodiment of the present application, wherein (a) is SVR, (b) is LSTM, (c) is TCN, (d) is STGCN, (e) is GWN, (f) is ASTGCN, (g) is TraEnvNet, (h) is TraEnv-LSTM, and (i) is TraEnv-ResLSTM;
[0081] Figure 8 Figure 4 is a schematic diagram of the performance comparison of TraEnv-ResLSTM models of different variants in the embodiment of the present application, wherein (a) is the evaluation result of RMSE, (b) is the evaluation result of MAE, and (c) is the evaluation result of MAPE;
[0082] Figure 9(a) is a schematic diagram of the 2020.01.16 different speed prediction case of the Cajiaoying Bridge-Yongdingmen Bridge with a prediction step of 30 minutes in the embodiment of the present application;
[0083] Figure 9(b) is a schematic diagram of the 2020.01.16 different speed prediction case of the Cajiaoying Bridge-Yongdingmen Bridge with a prediction step of 60 minutes in the embodiment of the present application;
[0084] Figure 9(c) is a schematic diagram of the 2020.01.16 different speed prediction case of the Cajiaoying Bridge-Yongdingmen Bridge with a prediction step of 90 minutes in the embodiment of the present application;
[0085] Figure 9(d) is a schematic diagram of the 2020.01.16 different speed prediction case of the Cajiaoying Bridge-Yongdingmen Bridge with a prediction step of 120 minutes in the embodiment of the present application;
[0086] Figure 9(e) is a schematic diagram of different speed prediction cases of Caihuying Bridge-Yongdingmen Bridge with a prediction step of 150 minutes in an embodiment of the present invention on January 16, 2020.
[0087] Figure 9(f) is a schematic diagram of different speed prediction cases of Caihuying Bridge-Yongdingmen Bridge with a prediction step of 180 minutes in the embodiment of the present invention on January 16, 2020;
[0088] Figure 10(a) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge on January 16, 2020, with a prediction step length of 30 minutes in the embodiment of the present invention;
[0089] Figure 10(b) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge with a prediction step of 60 minutes in the embodiment of the present invention on January 16, 2020;
[0090] Figure 10(c) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge with a prediction step of 90 minutes in the embodiment of the present invention on January 16, 2020;
[0091] Figure 10(d) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge with a prediction step of 120 minutes in the embodiment of the present invention on January 16, 2020;
[0092] Figure 10(e) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge with a prediction step of 150 minutes in an embodiment of the present invention on January 16, 2020;
[0093] Figure 10(f) is a schematic diagram of different speed prediction cases of Zizhuyuan Bridge-Sijiqing Bridge with a prediction step of 180 minutes in an embodiment of the present invention on January 16, 2020. Detailed Implementation
[0094] This invention provides a traffic temporal modeling method based on traffic semantic representation. The invention will be further described in detail below with reference to the accompanying drawings.
[0095] like Figure 1 The embodiment of the present invention disclosed herein discloses a traffic temporal modeling method based on traffic semantic representation, comprising:
[0096] Traffic environmental factors and traffic network attributes are collected to construct a traffic semantic space; contrastive learning is used to train a traffic semantic codec to align and encode traffic environmental factors and traffic network attributes in the traffic semantic space.
[0097] Based on the traffic semantic feature temporal inference model, the traffic state is temporally inferred in the traffic semantic space, and the predicted traffic state index is output.
[0098] The traffic semantic codec comprises a traffic environment encoder, a traffic road network encoder, and a traffic semantic decoder; the traffic semantic feature time sequence deduction model comprises a historical traffic flow time sequence feature extraction module and a future traffic flow time sequence feature deduction module fused with environment features; the traffic state index comprises a speed, a density, and a flow; the traffic environment factor comprises a weather, a time, a workday and holiday state, and a traffic policy; and the traffic road network attribute comprises a traffic road network speed.
[0099] The specific implementation process of each step is described below.
[0100] Step S1: Collect traffic environment factors and traffic road network attributes to construct a traffic semantic space; and train a traffic semantic codec using contrastive learning to align and encode the traffic environment factors and the traffic road network attributes in the traffic semantic space.
[0101] Step S11: Obtain traffic environment factors and traffic road network attributes, and perform cleaning, normalization, and structure mapping processing on the traffic environment factors and the traffic road network attributes.
[0102] In this embodiment, data collection and processing are performed, the traffic environment factors comprise a weather, a time, a workday and holiday state, and a traffic policy; and the traffic road network attribute comprises a traffic road network speed. Traffic state and environment related data are collected, and cleaning, normalization, and structure mapping processing are performed.
[0103] Step S12: input the traffic environment factors into a traffic environment encoder to obtain future traffic environment encoding, input the traffic road network attributes into a traffic road network encoder to obtain historical traffic road network encoding, and train a traffic semantic codec using contrastive learning to align the future traffic environment encoding and the historical traffic road network encoding to form a traffic semantic space.
[0104] In this embodiment, semantic information learning is performed, and contrastive learning is used to train a traffic environment encoder and a network encoder, so that the traffic environment encoder and the network encoder can align traffic semantic information from two aspects in a traffic semantic space. In contrastive learning, a positive sample pair is defined as two encodings describing the same traffic state, and the remaining encodings are defined as negative sample pairs. Contrastive learning can measure the similarity between encodings, and the higher the similarity between positive sample pairs and the lower the similarity between negative sample pairs are expected. A traffic semantic information encoding framework is shown in Figure 2 The similarity is measured by calculating the cosine similarity between sample pairs, the cosine similarity is scaled by a temperature parameter τ, and is normalized to a probability distribution by Softmax, so the expected distance between positive sample pairs is 1 and the expected distance between negative sample pairs is 0. Therefore, the expected similarity matrix is a unit matrix with all diagonal lines being 1.
[0105] A positive sample pair is defined as two encodings describing the same traffic state; a negative sample pair is defined as encodings describing different traffic states, and similarity is measured by calculating the similarity between the encodings;
[0106] The cosine similarity is used to measure the similarity, and is normalized by a temperature parameter and a Softmax function;
[0107] The InfoNCE loss is used as the loss function to optimize the performance of the encoder, so that the encodings generated by the traffic environment encoder and the traffic network encoder can be effectively aligned in the traffic semantic space;
[0108] The calculation formula of the cosine similarity for measuring similarity is (1) and (2):
[0109] (1)
[0110] (2)
[0111] In the formula, A and B represent the traffic environment encoding and the traffic network encoding respectively, and represent the components of the encoding vector, d represents the dimension of the encoding, and K represents the batch size of training. In the formula is a temperature hyperparameter, and the value is 0.2 or 0.07, is the similarity of , and softmax is a normalization function;
[0112] In this embodiment, the loss function used is InfoNCE loss, as shown in formula (3):
[0113] (3)
[0114] In the formula, similarity represents a similarity function, and the similarity function is one of cosine similarity, Euclidean distance, and neural network; K is the batch size. represents a positive sample pair, represents a negative sample pair.
[0115] In this embodiment, TEE and TNE are the traffic environment encoder and the traffic network encoder respectively, which encode the environment and the network into low-dimensional representations, represented by X = TEE(environment) and Y = TNE(network).
[0116] Step S13: Combine the pre-trained traffic environment encoder and traffic network encoder with the traffic semantic decoder to form a traffic semantic encoder-decoder.
[0117] The traffic environment encoder is used for semantic information of external environment related to traffic state. The encoder adopts the structure of single feature extraction module and multi-feature fusion module, as shown in Figure 2 The single feature extraction module one-hot encodes single environmental factors and puts them into a fully connected network for feature extraction, i.e., a feature extraction layer. The parameters of the hidden fully connected network layer in the feature extraction layer are shared, and only the input layer and output layer parameters are different. Therefore, all the hidden layer parameters of the single feature extraction module are the same, and the same module can extract multiple features at the same time. After obtaining single features, they are spliced and put into the feature fusion module for feature fusion and dimension reduction.
[0118] The feature fusion module is still a multi-layer fully connected network, and the model outputs a traffic environment code, as shown in formulas (4) and (5).
[0119] (4)
[0120] (5)
[0121] In the formula, attr represents different traffic environment factors, X represents single feature extraction results, C represents traffic environment encoding, W and b are weight matrix and bias respectively, and δ represents the activation function LeakyReLU. The output dimension of the traffic environment encoder is 64.
[0122] In this embodiment, the traffic environment factors considered in the model are as follows: the day of the week is considered, and the day is considered as a working day or a rest day. As for the time, a day is divided into 288 time periods, and each time period is five minutes. In the division of peak hours, four time periods are divided according to the traffic flow on the road, which are early peak hours from 7:00 to 9:00, late peak hours from 17:00 to 19:00, free flow hours from 24:00 to 6:00 of the next day, and the remaining time periods are off-peak hours. Five kinds of weather are considered as weather factors, among which rain and snow are considered as one kind of weather condition. The Beijing odd-even number limit policy is considered as the management policy. This traffic rule restricts traffic according to the last number of the license plate. Two numbers are prohibited every day, a total of five pairs, which are 1&6, 2&7, 3&8, 4&9 and 5&0. The output dimension of the traffic environment encoder is 64.
[0123] The input of the traffic network encoder is the traffic state of the road network at a certain time, and the output is a semantic code. In order to ensure the same semantic space as the traffic environment encoding, the output dimension of the traffic network encoder is also 64. The encoder combines the graph multi-head layer and the global readout function to obtain the traffic network code. The architecture of the traffic network encoder is as shown in Figure 2The multi-head attention layer obtains the spatial dependence of the road network through multiple heads and layers. The global readout function integrates the information of each node and outputs.
[0124] In the road network, the traffic states of the connected road segments affect each other, such as the congestion of the downstream road segment quickly spreads to the upstream road segment. In order to model the influence of different road segments in the road network, a graph attention network and a residual connection are introduced to process the road network information. The multi-layer graph attention network models the connection strength between nodes through different weights, and the more layers, the more node neighbors are considered. In order to be able to fuse the node features extracted by the multi-layer network into the final output layer, a skip connection is added between each layer to ensure that the node information is not lost. The calculation formula of the multi-head graph attention network with residual mechanism is shown in equations (6) to (9):
[0125] (6)
[0126] (7)
[0127] (8)
[0128] (9)
[0129] In the formula, represents the attention weight between node i and node j, h is the feature of the node, is the neighbor of node i, is the hidden feature of layer l, W is the learnable weight matrix, a is the learnable vector, δ and g are the activation functions LeakyReLU.
[0130] In order to extract the features of the whole road network, the node features are fused into the road network features, and a global readout function is designed. The global readout function considers the features of each node, concatenates them and inputs them into a fully connected network to obtain the representation code of the traffic network. The global readout function calculation is shown in equation 10.
[0131] (10)
[0132] In the formula, W and b are the weight matrix and bias respectively, and δ is the activation function LeakyReLU.
[0133] In this embodiment, a simple and efficient traffic semantic decoder is designed, which is symmetrical with the traffic network encoder structure. The traffic network encoder and the traffic semantic decoder are combined to form a traffic network autoencoder. In the decoder, first, the traffic semantic encoding is converted into the features on the road network nodes by the attribute assignment function. Then, the spatial dependencies between different node features are considered through the multi-head attention layer, and finally the traffic speed is output. Formula (11) shows the process of model training.
[0134] (11)
[0135] In the formula, X represents the traffic flow in the road network.
[0136] In this embodiment, the parameters of the traffic network encoder are frozen during training, because the parameters of the traffic network encoder have been pre-trained in advance.
[0137] Step S2: based on the traffic semantic feature time sequence deduction model, the traffic state is time sequence deduced in the traffic semantic space;
[0138] The traffic semantic feature time sequence deduction model deduces the traffic state in the traffic semantic space, and predicts the traffic state index, including:
[0139] Step S21: design a time sequence feature capturing module to capture the time sequence feature relationship in the traffic semantic space, and use an enhanced residual long short-term memory network to capture the time sequence features of the traffic state evolution over time;
[0140] Step S22: based on the completion of single-step time sequence feature capture by the time sequence feature capture module, a traffic semantic feature time sequence deduction model is designed;
[0141] The traffic semantic feature time sequence deduction model includes two sub-networks connected to each other: a historical traffic feature extraction module for encoding the semantic evolution process of the historical traffic state; a future traffic speed reasoning module that combines environmental factors, responsible for the time sequence extrapolation of the traffic state combined with future environmental factors; and the prior encoding of the future environmental factors is introduced as auxiliary input;
[0142] The future environment encoding is embedded in the future traffic flow time sequence feature deduction module that fuses environmental features;
[0143] The reasoning process of the historical traffic flow time sequence feature extraction module and the future traffic flow time sequence feature deduction module that fuses environmental features is:
[0144] The historical traffic flow time sequence feature extraction module receives the semantic encoding in the historical time sequence, and uses an enhanced residual long short-term memory network to extract its time sequence dynamic information;
[0145] The end state of the historical traffic flow time sequence feature extraction module is taken as the initial state of the future traffic flow time sequence feature deduction module that fuses environmental features, and the future traffic semantic encoding is generated at each time step in combination with the future environment encoding input to extrapolate the evolution of the traffic state semantics.
[0146] The future traffic flow time sequence feature deduction module that fuses environmental features generates future traffic semantic encoding at each time step, and restores the specific traffic state through the decoder.
[0147] During the training process, the semantic encoder and decoder are frozen, and only the enhanced residual long short-term memory network is optimized to improve the training efficiency and stability.
[0148] When predicting the future speed, the pre-trained traffic semantic decoder directly decodes the semantic encoding output by the future traffic flow time sequence feature deduction module that fuses environmental features at each time step, and maps the semantic encoding to the actual road network traffic state.
[0149] In step S21, the time sequence feature capture module is designed:
[0150] In order to capture the time sequence feature relationship in the traffic semantic space, an enhanced residual long short-term memory network (ResLSTM) is proposed to capture the time sequence features of the evolution of traffic states over time. Traditional LSTM performs well in modeling tasks with time dependence, but its long-term prediction performance is limited in actual traffic state prediction, mainly in the problems of error accumulation over time and slow response to weak changes in short-term abnormal traffic states. Especially in high-frequency sampled traffic data, the traffic state changes between adjacent time slices are often extremely subtle, which puts higher requirements on the sensitivity of time sequence modeling.
[0151] Specifically, the classic LSTM uses a step-by-step iterative method to predict future states, and each step of prediction is based on the migration time. The output at the previous time may be an estimated value, leading to the continuous accumulation of prediction errors over time, and thus affecting the stability and accuracy of long-term prediction. In addition, traffic states usually change slowly at a fine-grained time scale (e.g., every 5 minutes), and classic LSTM tends to ignore these subtle time sequence dynamics, resulting in a decrease in feature capture ability.
[0152] To solve this problem, an improved LSTM, called ResLSTM, is introduced. ResLSTM adds a skip connection between the input and output of the LSTM unit, so that the encoding of the traffic semantic space can be directly transmitted to the output end of the LSTM, as shown in Figure 3 . Three gating mechanisms are maintained, including the input gate, the forget gate, and the output gate. This design has the following advantages:
[0153] (1) Alleviate the problem of vanishing gradient and error accumulation: Through residual connection, the original traffic semantic information is maintained and is not easy to be "forgotten" by the continuous gating operation;
[0154] (2) Enhance the ability to capture subtle changes: ResLSTM focuses on modeling the "incremental difference" between semantic encodings, effectively capturing the subtle but critical state changes between consecutive time points;
[0155] (3) Promote stable propagation of semantic space: Avoid redundant calculations caused by repeated learning of similar inputs, improve training efficiency and model convergence.
[0156] The calculation of the ResLSTM unit is shown in equations (12) to (17).
[0157] (12)
[0158] (13)
[0159] (14)
[0160] (15)
[0161] (16)
[0162] (17)
[0163] In the formula, , and represent the output of the input gate, the forget gate and the output gate respectively, represents the input at the current time step. , , , , , , and are the weight matrices of the input vector and the hidden state, , , and are the corresponding bias terms. represents the sigmoid activation function, represents element-wise multiplication, represents the hyperbolic tangent function, and represent the output vectors of the cell state and the hidden state at the current time step respectively.
[0164] Considering that the evolution of traffic states is often affected by various external disturbance factors, such as weather conditions, holiday arrangements or peak period rules, this section further introduces the external traffic environment coding into the input end of ResLSTM. This design not only enriches the input feature dimension of the model, but also enables the model to actively correct the prediction bias, effectively alleviating the cumulative error problem caused by the error of historical state estimation. By guiding the model to fully consider the interference and inducement of the external environment in the time series modeling process, ResLSTM shows stronger multi-step traffic prediction robustness and generalization ability.
[0165] Step S22: On the basis of completing single-step time series feature capture by the time series feature capture module, a traffic semantic feature time series inference model is designed.
[0166] In this embodiment, a time series feature reasoning module is designed.
[0167] On the basis of completing single-step time series feature capture, the present application further proposes a time series reasoning model framework TraEnv-ResLSTM for traffic semantic space, to realize dynamic evolution prediction of multi-time-step traffic states, as shown in FIG. 2. Figure 4 The model takes traffic semantic space as a unified representation basis, and realizes semantic migration and state evolution prediction in the time dimension by decoupling the modeling paths of historical traffic feature modeling and future traffic state reasoning.
[0168] The traffic semantic feature time series inference model is composed of two interconnected sub-networks: (1) a historical traffic feature extraction module (HTEM) for encoding the semantic evolution process of historical traffic states; and (2) a future traffic speed reasoning module (FTIMIE) that combines future environmental factors to extrapolate the time series of traffic states.
[0169] Unlike the traditional Encoder-Decoder structure, TraEnv-ResLSTM introduces prior encoding of future environmental factors as auxiliary input, which is an important innovation. In real-world scenarios, although future traffic states cannot be obtained, environmental variables such as weather and holidays can be obtained in advance. The present application utilizes this feature to embed future environmental coding in FTIMIE, effectively solving the problem of excessive dependence on historical features in traditional methods, which leads to error accumulation. The model not only maintains the inheritance of historical trends, but also has the ability to adjust the prediction path according to external conditions, thereby enhancing the adaptability and interpretability of the model to complex time-varying scenarios.
[0170] The historical traffic state modeling and the future traffic state inference use two different parameter ResLSTMs, and the last step state of the former ResLSTM is taken as the initial state of the latter ResLSTM. The specific reasoning process of the traffic semantic feature time series inference model is as follows:
[0171] (1) The HTEM receives semantic encoding in the historical time series, and uses ResLSTM to extract its time series dynamic information;
[0172] (2) The end state of the HTEM is taken as the initial state of the FTIMIE, and the future environment encoding is input to perform the extrapolation of the semantic evolution of the traffic state;
[0173] (3) The FTIMIE generates future traffic semantic encoding at each time step, and restores it to specific traffic states (such as speed) through the decoder;
[0174] (4) In the training process, the semantic encoder and decoder are frozen, and only the ResLSTM module is optimized to improve the training efficiency and stability.
[0175] In the TraEnv-ResLSTM, when predicting the future speed, the pre-trained traffic semantic decoder directly decodes the semantic encoding output by the FTIMIE at each time step, and maps the semantic encoding to the actual road network traffic state. In this embodiment, a traffic semantic time series inference model is built based on the Pytorch framework, and a training process of a traffic semantic time series inference model training algorithm (algorithm 1) is designed as shown in Table 1. The input of the model is the historical traffic speed and the future traffic environment information, and the output is the future traffic speed. Algorithm 1 realizes the time series prediction model based on the traffic semantic space by jointly optimizing the historical traffic feature extraction module and the future traffic speed inference module.
[0176] The training of the traffic semantic time series inference model mainly includes four stages of feature extraction, regularization, time series modeling and parameter optimization. The model first extracts semantic features from traffic network features and traffic environment factors, and performs L2 regularization processing to enhance the numerical stability of the features. Then, the historical traffic speed encodes the historical time series features (HTEM), and combines the future environment factor features to perform time series inference and decoding of the future traffic state (FTIMIE) to output the future speed prediction result. In the training process, by constructing the error loss function between the predicted speed and the real speed, the Adam optimizer is used to perform error back propagation and iterative update on the parameters of HTEM and FTIMIE, and finally the ability of traffic state modeling in the traffic semantic space is improved.
[0177] Table 1: Traffic semantic time series inference model training pseudocode (algorithm 1) summary table
[0178]
[0179] Both HTEM and FTIME can adaptively control the length of time series. For example, half-hour, one-hour or two-hour historical speed series are input into the historical time series modeling module. Similarly, for future time series reasoning, five minutes, ten minutes, one hour or longer time series are selected. The length of both historical series and future series can be extended indefinitely. In this embodiment, in order to facilitate comparison with other methods and training resource constraints, one hour of historical speed is used to predict the speed of the next one hour when training the model. In testing, the model can predict the traffic speed of any future time step by adjusting the output step.
[0180] In summary, TraEnv-ResLSTM breaks through the technical bottlenecks of existing traffic time series modeling in structure design, information utilization and prediction logic, not only improves the performance of the model in long time span traffic prediction, but also provides methodological support for traffic state modeling under multi-task and multi-environmental conditions.
[0181] Step 3: output the predicted traffic state index;
[0182] The output predicted traffic state index includes:
[0183] The output multi-scale future prediction result, the multi-scale includes: the prediction period range is 15 minutes to 180 minutes; a plurality of error indicators are used for model effect evaluation, the plurality of error indicators includes: RMSE, MAE, MAPE.
[0184] In this embodiment, the output prediction result supports multi-scale future prediction of 15 minutes to 180 minutes;
[0185] The output traffic state index includes but is not limited to speed, density and flow;
[0186] A plurality of error indicators (such as RMSE, MAE, MAPE) are used for model effect evaluation.
[0187] The application will be further described below in conjunction with specific embodiments. Obviously, the described embodiments are only a part of the embodiments of the application, not all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor belong to the scope of protection of the application.
[0188] To verify the effectiveness of the application, the following verification experiments are performed:
[0189] Experiment A: Traffic semantic space construction
[0190] (1) Collect traffic data and weather, holiday information of Beijing main roads;
[0191] This patent uses the traffic flow data of Beijing urban expressway network. The data includes all ring roads within the five rings of the city and 39 main connecting lines, a total of 250 road segments, with an average length of 3 kilometers. The data comes from Baidu Map's floating vehicle data, which obtains the average speed of vehicles on the road segment by considering the speed of all floating vehicles at the current time. The data is preprocessed, first removing some problem data such as abnormal data with vehicle speed less than 0 and greater than 120 km / h, then filling in a small amount of missing data using linear interpolation, and finally normalizing the data to the maximum and minimum value. The data covers a period of 6 weeks from December 7, 2019 to January 17, 2020, a total of 42 days, with a sampling interval of 5 minutes. The 42 days of data are divided into the first 36 days as the training set, the 37th ~ 39th day as the validation set, and the 40th ~ 42nd day as the test set. In addition, this patent also collects the weather conditions and odd-even number limit policy information of Beijing during the same period.
[0192] (2) Map the road segment to the graph node and construct the topological structure graph;
[0193] Traffic network is defined as a graph , where is the set of nodes in the graph, which can be regarded as each road segment in the road network, is the number of road segments in the road network. is the set of edges in the graph that describes whether two nodes are connected. If and are connected, then , otherwise . is the adjacency matrix of graph . represents the connection weight between node and node , in this patent, the weight of adjacent nodes is set to 1, and the weight of non-adjacent nodes is set to 0. represents all the neighbor nodes directly connected to node .
[0194] (3) Use graph neural network to extract structural features and fuse with original traffic state encoding to form unified semantic vector.
[0195] Traffic environment encoder is used for semantic information of external environment related to traffic state. The encoder adopts the structure of single feature extraction module and multi-feature fusion module, such as Figure 2The single feature extraction module encodes the single environmental factor with one-hot encoding and puts it into a fully connected network for feature extraction, i.e., the feature extraction layer. The parameters of the hidden fully connected network layer in the feature extraction layer are shared, and only the input layer and output layer parameters are different. This means that all the hidden layer parameters of the single feature extraction module are the same, and the same module can extract multiple features at the same time. After obtaining the single feature, it is spliced and put into the feature fusion module for feature fusion and dimension reduction. The feature fusion module is still a multi-layer fully connected network, and the model outputs the traffic environment code.
[0196] The traffic environment factors considered in the model are as follows. The day of the week is considered, and the day is a weekday or a holiday. At the time, a day is divided into 288 time periods, with each time period being five minutes. In the division of peak hours, referring to the traffic flow on the road, four time periods are divided, which are early peak hours from 7:00 to 9:00, late peak hours from 17:00 to 19:00, free flow hours from 24:00 to the next 6:00, and the remaining time periods are off-peak hours. Five kinds of weather are considered, with rain and snow being considered as one weather condition. The Beijing odd-even number limit policy is considered in the management policy. This traffic rule restricts traffic by the last number of the license plate. Two numbers are prohibited every day, a total of five pairs, which are 1&6, 2&7, 3&8, 4&9, and 5&0. The final traffic environment encoder outputs a code dimension of 64.
[0197] The input of the traffic network encoder is the traffic state of the road network at a certain time, and the output is the semantic code. To ensure the same semantic space as the traffic environment code, the output dimension of the traffic network encoder is also 64. The encoder combines the graph multi-head layer and the global readout function to obtain the traffic network code. The architecture of the traffic network encoder is shown in Figure 2 The graph multi-head attention layer obtains the spatial dependence of the road network through multiple heads and layers. The global readout function integrates the information of each node and outputs.
[0198] In the road network, the traffic states of the connected road segments affect each other, such as downstream road congestion quickly spreading to upstream road segments. In order to model the influence of different road segments in the road network, graph attention networks and residual connections are introduced to process road network information. The multi-layer graph attention network models the connection strength between nodes through different weights, and the more layers, the more node neighbors are considered. In order to be able to fuse the node features extracted by the multi-layer network into the final output layer, a skip connection is added between each layer to ensure that the node information is not lost.
[0199] To extract the features of the whole road network, the node features are fused into the road network features, and a global readout function is designed. The global readout function considers the features of each node, concatenates them and inputs them into a fully connected network to obtain the representation code of the traffic network.
[0200] In this embodiment, a simple and efficient traffic semantic decoder is designed, which is symmetrical with the traffic network encoder structure. The traffic network encoder and the traffic semantic decoder are combined to form a traffic network autoencoder. In the decoder, first, the semantic code is converted into the features of the road network nodes by the attribute assignment function. Then, the spatial dependencies between different node features are considered through the multi-head attention layer, and finally the traffic speed is output.
[0201] Experiment B: Time series modeling and prediction
[0202] (1) Use enhanced LSTM to train the semantic encoding sequence and predict the traffic speed change in the next 3 hours;
[0203] On the basis of capturing single-step time series features, the invention further proposes a time series reasoning model framework TraEnv-ResLSTM for traffic semantic space to realize dynamic evolution prediction of multi-time step traffic state, as shown in Figure 4 The model takes the traffic semantic space as the unified representation basis, decouples the modeling paths of historical traffic feature modeling and future traffic state reasoning, and realizes semantic migration and state evolution prediction in the time dimension.
[0204] This module consists of two interconnected sub-networks: (1) Historical Traffic Feature Extraction Module (HTEM): used to encode the semantic evolution process of historical traffic state. (2) Future Traffic Speed Reasoning Module with Environmental Factor Integration (FTIMIE): responsible for combining future environmental factors to extrapolate traffic state in time.
[0205] The historical traffic state modeling and future traffic state reasoning use two ResLSTMs with different parameters, and the last step state of the former ResLSTM is used as the initial state of the latter ResLSTM. The specific reasoning process of the model is as follows:
[0206] 1. HTEM receives semantic encoding in the historical time series and uses ResLSTM to extract its time series dynamic information;
[0207] 2. The end state of HTEM is used as the initial state of FTIMIE, combined with future environment encoding input, to extrapolate the semantic evolution of traffic state;
[0208] 3. FTIMIE generates future traffic semantic encoding at each time step and restores it to specific traffic state (such as speed) through the decoder.
[0209] 4. In the training process, the semantic encoder-decoder is frozen, and only the ResLSTM module is optimized to improve training efficiency and stability.
[0210] In TraEnv-ResLSTM, when predicting future speed, the pre-trained traffic semantic decoder directly decodes the semantic encoding output by FTIMIE at each time step, and maps the semantic encoding to the actual road network traffic state. The traffic semantic time series inference model in this embodiment is built based on the Pytorch framework, and the training process as shown in Algorithm 1 is designed. The input of the model is the historical traffic speed and future traffic environment information, and the output is the future traffic speed. This algorithm realizes the time series prediction model based on traffic semantic space by jointly optimizing the historical traffic feature extraction module and the future traffic speed inference module.
[0211] The training of the traffic semantic time series inference model mainly includes four stages: feature extraction, regularization, time series modeling, and parameter optimization. The model first extracts semantic features from traffic network features and traffic environment factors, and performs L2 regularization processing to enhance the numerical stability of the features. Then, the historical traffic speed encodes the historical time series features (HTEM), and combines the future environment factor features to perform time series inference and decoding of future traffic state (FTIMIE), and outputs the future speed prediction result. During the training process, by constructing the error loss function between the predicted speed and the true speed, the Adam optimizer is used to perform error backpropagation and iterative update on the parameters of HTEM and FTIMIE, and finally improve the ability of traffic state modeling in the traffic semantic space.
[0212] Both HTEM and FTIME can adaptively control the length of the time series. For example, half-hour, one hour, or two hours of historical speed sequence is input into the historical time series modeling module. Similarly, for future time series inference, a time series of five minutes, ten minutes, one hour, or longer is selected. The length of the historical sequence and the future sequence can be extended indefinitely. In this embodiment, in order to facilitate comparison with other methods and training resource limitations, one hour of historical speed is used to predict the speed of the next one hour when training the model. In testing, the model can predict the traffic speed at any future time step by adjusting the output step.
[0213] Table 2 shows the prediction results of the method TraEnv-ResLSTM proposed in this embodiment and the baseline model on the Beijing road network data set. In order to facilitate understanding, the results of the future 12 time steps are reported (t+1 to t+12) ), with a time interval of 15 minutes.
[0214] The experimental results of the multi-step prediction error of different methods in this embodiment are compared as Figure 5The evaluation results of the RMSE of all models are shown in (a), the evaluation results of the MAE of all models are shown in (b), the evaluation results of the MAPE of all models are shown in (c), the evaluation results of the RMSE of the TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models are shown in (d), the evaluation results of the MAE of the TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models are shown in (e), and the evaluation results of the MAPE of the TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models are shown in (f). Figure 5 The test error indicators of different methods are shown, and the right half (d), (e) and (f) show the magnified results of the newly proposed TraEnvNet, TraEnv-LSTM and TraEnv-ResLSTM models.
[0215] In this embodiment, all deep learning models are trained based on the historical speed data of the previous hour to predict the traffic speed in the next hour. This means that the prediction of the traffic state more than 60 minutes in the future never appears in the training. In order to evaluate the time series extrapolation ability of the model, the ability of each model to predict the traffic speed in the next three hours is tested.
[0216] Table 2 Summary of the performance of different methods in predicting the traffic speed in the next three hours
[0217]
[0218] As can be seen from the results in Table 2, when the prediction step is more than 30 minutes, the TraEnv-ResLSTM is superior to other models in all evaluation indicators. When the prediction step exceeds the training time step, the prediction error of other models increases significantly. In contrast, the error of TraEnv-LSTM and TraEnv-ResLSTM increases only slightly when making long-term predictions. When predicting for two hours, the error increases by only 1.21% and 0.77% compared with one hour prediction; when predicting for three hours, the error increases by only 3.41% and 1.12% compared with one hour prediction. It can be seen that the proposed model has good scalability in time series model extrapolation, and when the model extrapolates data that is not encountered in training, the error increases less, and the prediction result of the model is stable. The TraEnv-ResLSTM achieves such good results because the traffic environment factors and traffic network attributes are aligned through the traffic semantic space, and the assistance of the traffic semantic space effectively reduces the error of long-term prediction. The TraEnv-ResLSTM not only models the spatio-temporal characteristics of traffic, but also integrates the influence of environmental factors on speed into the model.
[0219] Using a single error metric to evaluate a model has limitations. For example, MAPE may overstate or underestimate errors at low and high speeds. Therefore, this invention analyzes error metrics across different speed ranges. Speeds are discretized and grouped into steps of 10 km / h.
[0220] The error distribution comparison results at different speeds in this embodiment are as follows: Figure 6 As shown, (a) represents the prediction results with a 60-minute prediction step size, (b) represents the results with a 120-minute prediction step size, and (c) represents the results with a 180-minute prediction step size. The horizontal axis represents the speed value, and the vertical axis represents the error metric. In this invention, TraEnv-ResLSTM performs best at almost all speeds and has the smallest standard deviation of the error metric, demonstrating robustness in predicting various speeds. All models perform well in the speed range of 40-90 km / h, but have higher prediction errors at very low or very high speeds. For example, with a prediction step size of 60 minutes, for speeds below 10 km / h, the RMSE, MAE, and MAPE of TraEnv-ResLSTM are 15.34, 13.23, and 206.79%, respectively, while the corresponding values for LSTM are 26.16, 19.51, and 305.69%. The model of this invention shows a significant improvement over LSTM. As the prediction step size increases, TraEnv-ResLSTM exhibits minimal error growth and maintains stable results at both low and high speeds.
[0221] (2) Introducing traffic semantic space significantly improves the long-term prediction capability of the model.
[0222] This patent comprehensively analyzes the daily error indices of all baseline models on the test set for each time period and generates a MAE distribution map. The comparison of the error distribution of different methods at different times of the day in this embodiment is shown below. Figure 7 As shown, (a) is SVR, (b) is LSTM, (c) is TCN, (d) is STGCN, (e) is GWN, (f) is ASTGCN, (g) is TraEnvNet, (h) is TraEnv-LSTM, and (i) is TraEnv-ResLSTM; Figure 7 The horizontal axis represents the prediction time step, and the vertical axis corresponds to different times of day. The shades of color in the graph correspond to the magnitude of the error, with darker colors indicating smaller errors. Figure 7It is clear that the performance of TraEnv-ResLSTM is superior to other methods in all time periods. It is worth noting that the larger errors are mainly concentrated in the morning and evening peak periods. In these periods, the traffic state becomes relatively complex, the number of vehicles on the road increases, and it is more prone to accidents and traffic congestion and other sudden situations. Therefore, in these two periods, the errors of all methods are relatively large.
[0223] As the prediction step increases, the error gradually increases, especially near the morning and evening peak periods, as shown by the gradually thickening bright yellow line in Figure 7 . It is worth noting that the MAE error of TraEnv-ResLSTM is significantly lower than other methods. In addition, as the prediction step increases, the error growth of TraEnv-ResLSTM is significantly smaller than other methods. This advantage is due to the introduction of traffic environment factor encoding and skip connection mechanism. This innovative mechanism enables traffic environment factors to be directly transmitted to the decoder end, effectively reducing the error accumulation problem in long-term prediction. In contrast, methods like LSTM, TCN, STGCN, GWN, and ASTGCN rely on previous prediction results without correction when making long-term speed prediction, resulting in error accumulation. TCN, STGCN, and GWN are based on the speed of the previous hour to predict the speed of the next hour, so there is a clear prediction boundary at the one-hour prediction step interval. ASTGCN alleviates some long-term prediction errors by modeling time dependencies through multiple attention mechanisms.
[0224] Among all methods, the traffic speed prediction in the early morning period is more accurate, while in the daytime flat peak period and the morning and evening peak periods, the prediction error is larger. This shows that more attention needs to be paid to the prediction of complex traffic situations and provides a direction for further optimization of subsequent models.
[0225] (3) Effectiveness verification of each module
[0226] In order to verify the contribution and effectiveness of each component and step in the method proposed in this embodiment, the following ablation experiments are performed. These experiments still use the speed data of the past one hour to predict the speed of the next three hours.
[0227] 1. The role of ResLSTM
[0228] From Figure 8The performance comparison between TraEnvNet and TraEnv-ResLSTM in Table 4 shows that TraEnv-ResLSTM performs the best in all prediction time steps. Thanks to the ResLSTM module, the RMSE, MAE, and MAPE of three-hour prediction are reduced by 5.64%, 11.34%, and 7.69%, respectively. This improvement is mainly attributed to the ResLSTM module that captures the temporal feature changes in the traffic semantic space. When only using environmental factors for speed prediction, the model fails to effectively learn the temporal regularity of traffic semantic encoding. The introduction of the time-varying feature extraction module makes up for this deficiency, which also verifies the effectiveness of TraEnv-ResLSTM in capturing temporal traffic patterns.
[0229] 2. Role of Traffic Semantic Space
[0230] From Figure 8 The comparison between LSTM and TraEnv-ResLSTM in Table 4 shows that for the prediction of 15-minute time steps, the error of LSTM is smaller than that of TraEnv-ResLSTM. However, for the remaining prediction time steps, the error of LSTM is larger and increases rapidly, and the results for prediction steps exceeding one hour are almost uncontrollable. In contrast, TraEnv-ResLSTM exhibits stable prediction within three-hour time steps, with the average values of error RMSE, MAE, and MAPE being 6.49, 4.55, and 10.51%, respectively, and the corresponding standard deviations being 0.05, 0.04, and 0.06%, respectively. This stability is attributed to the construction of the traffic semantic space, which can well describe the nonlinear relationship between different traffic states, thus achieving more accurate temporal inference in this space than in the original space.
[0231] 3. Role of Skip-Connection
[0232] In the experiment, the present application improves LSTM by introducing skip-connection, so that traffic environment encoding can be directly transmitted to the decoder side. From Figure 8The comparison between TraEnv-LSTM and TraEnv-ResLSTM can draw the conclusion that the skip connection plays a greater role when the prediction time step increases. Without the skip connection, the ability of the environment encoding in the LSTM is seriously affected by the accumulated time error. After adding the skip connection, the model no longer only fits the time variation of the semantic encoding, but fits the difference between the current traffic state and the semantic encoding, which is smaller. By fitting small values, the performance of the time series inference model is improved. The next step prediction of TraEnv-LSTM depends heavily on the output of the previous step, and if the error of the previous step output is too large, the subsequent results will continue to accumulate on this error, leading to error explosion. In TraEnv-ResLSTM, the problem of error accumulation in traditional LSTM when performing time series inference is alleviated, and the environmental factor plays a role in correcting the speed prediction error.
[0233] 4. Role of pre-training the encoder-decoder
[0234] In the present application, the traffic environment encoder, the traffic road network encoder and the traffic semantic decoder have been pre-trained before training the traffic semantic time series inference model. An ablation experiment is conducted without using the pre-trained traffic semantic space. Figure 8 The results show that the performance of the model using pre-training is significantly better than that of the model without pre-training, and the reduction percentages of RMSE, MAE and MAPE are 20.73%, 22.13% and 33.58% respectively. At the same time, the use of pre-training paradigm also saves about 40% of the training time. This is because the model uses a block pre-training method to speed up the convergence speed of the model, and the model only optimizes a small part of parameters at each parameter update. This training method is very effective for training large models, saving training time and computing resources, and improving the accuracy of the model. In addition, the model trained in pre-training can also be used for other tasks, and each pre-trained module can be used separately.
[0235] (4) Road section case analysis
[0236] In order to evaluate the actual performance of the proposed model TraEnv-ResLSTM in the traffic speed prediction task, the present application carries out a section-by-section comparative analysis in the full road section range of the Beijing expressway network dataset, and selects two typical road sections as cases to carry out key display: respectively, the Caihuying Bridge-Yongdingmen Bridge and the Zizhu Bridge-Siqiqing Bridge. These two roads have certain representativeness in spatial position, traffic flow characteristics and congestion-prone degree, and can comprehensively reflect the prediction ability of the model under different traffic dynamic conditions.
[0237] In the present embodiment, the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 are shown in FIGS. 9(a) to 9(f) and FIGS. 10(a)-10(f):
[0238] FIG. 9(a) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 30 minutes in the embodiment of the present application;
[0239] FIG. 9(b) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 60 minutes in the embodiment of the present application;
[0240] FIG. 9(c) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 90 minutes in the embodiment of the present application;
[0241] FIG. 9(d) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 120 minutes in the embodiment of the present application;
[0242] FIG. 9(e) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 150 minutes in the embodiment of the present application;
[0243] FIG. 9(f) is a schematic diagram of the different speed prediction cases of the Caihuying Bridge-Yongdingmen Bridge 2020.01.16 with a prediction step of 180 minutes in the embodiment of the present application;
[0244] FIG. 10(a) is a schematic diagram of the different speed prediction cases of the Zizhu Bridge-Sijiqing Bridge 2020.01.16 with a prediction step of 30 minutes in the embodiment of the present application;
[0245] FIG. 10(b) is a schematic diagram of the different speed prediction cases of the Zizhu Bridge-Sijiqing Bridge 2020.01.16 with a prediction step of 60 minutes in the embodiment of the present application;
[0246] FIG. 10(c) is a schematic diagram of the different speed prediction cases of the Zizhu Bridge-Sijiqing Bridge 2020.01.16 with a prediction step of 90 minutes in the embodiment of the present application;
[0247] FIG. 10(d) is a schematic diagram of the different speed prediction cases of the Zizhu Bridge-Sijiqing Bridge 2020.01.16 with a prediction step of 120 minutes in the embodiment of the present application;
[0248] FIG. 10(e) is a schematic diagram of the different speed prediction cases of the Zizhu Bridge-Sijiqing Bridge 2020.01.16 with a prediction step of 150 minutes in the embodiment of the present application;
[0249] FIG. 10(f) is a schematic diagram of a 180-minute Zhanlunkeng-Sijiqingqiao 2020.01.16 different speed prediction case in the embodiment of the application.
[0250] As the prediction time step increases from 30 minutes to 180 minutes, the traditional models such as LSTM, TCN, GWN and ASTGCN perform well in the short-term prediction stage (30 minutes), but as the prediction step lengthens, the accuracy decreases and the trend distorts, all showing a clear error accumulation trend. Especially after 60 minutes, the predicted values of most models gradually deviate from the true values, and even lose the basic ability to depict the traffic trend, indicating that there is a structural bottleneck in long-term dependence modeling. This is mainly because these time series prediction methods have a gradual error accumulation problem, and there is no error correction mechanism in the prediction process.
[0251] In comparison, TraEnvNet, although slightly better than traditional models in overall trend fitting, provides consistent estimation results in all time ranges, but when faced with dramatic fluctuations in speed or sudden traffic anomalies, it is prone to over-smoothing problems, with a lag in response and a significant smoothing deviation in the prediction results. This phenomenon reflects the limited adaptability of the environmental semantic modeling mechanism in the model when dealing with non-stationary time series. TraEnv-LSTM and TraEnv-ResLSTM always show smaller errors, with TraEnv-ResLSTM being more accurate. The TraEnv-ResLSTM model, by introducing a traffic semantic encoding mechanism and a residual connection structure, preserves the information transmission of key prediction paths in the deep recursive learning framework, not only significantly alleviating the error accumulation problem in long-term information transmission, but also improving the sensitivity and memory capacity of the model to sudden changes. In the above two cases, TraEnv-ResLSTM always maintains a low prediction error, especially when there are sudden increases or decreases in traffic speed and other non-stationary disturbances, it can quickly capture the state transition signals, demonstrating its efficient response capability to complex traffic dynamics.
[0252] This case study not only verifies the significant advantage of TraEnv-ResLSTM in long-term prediction accuracy, but also further reveals its ability to identify and adapt to abnormal traffic events, providing a feasible path for building a robust and highly sensitive intelligent traffic state prediction system. From a broader perspective, the advantage of this model lies in its effective integration of semantic context modeling and deep nonlinear feature learning, which helps to solve the problem of delayed response to sudden and dynamic information in current traffic state prediction.
[0253] Another embodiment of the present application provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program stored in the memory, the processor executes the traffic timing modeling method based on traffic semantic representation according to the present application.
[0254] Another embodiment of the present application provides a computer readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the processor executes the traffic timing modeling method based on traffic semantic representation according to the present application.
Claims
1. A traffic time series modeling method based on traffic semantic representation, characterized in that, The method comprises the following steps: Collecting traffic environment factors and traffic network attributes to construct a traffic semantic space; training a traffic semantic encoder-decoder using contrastive learning to align and encode the traffic environment factors and traffic network attributes in the traffic semantic space; Based on the traffic semantic feature time sequence deduction model, the traffic state is deduced in the traffic semantic space, and the predicted traffic state index is output; The traffic semantic encoder-decoder comprises a traffic environment encoder, a traffic network encoder, and a traffic semantic decoder; the traffic semantic feature time sequence deduction model comprises a historical traffic flow time sequence feature extraction module and a future traffic flow time sequence feature deduction module with environmental feature fusion; the traffic state index comprises speed, density, and flow; the traffic environment factors comprise weather, time, workday and holiday status, and traffic policy; the traffic network attributes comprise traffic network speed.
2. The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The collection of traffic environment factors and traffic network attributes to construct a traffic semantic space comprises: Step S11: Collecting traffic environment factors and traffic network attributes, and performing cleaning, normalization, and structure mapping processing on the traffic environment factors and traffic network attributes; Step S12: Inputting the traffic environment factors into the traffic environment encoder to obtain future traffic environment encoding, inputting the traffic network attributes into the traffic network encoder to obtain historical traffic network encoding, training the traffic semantic encoder-decoder using contrastive learning, and aligning the future traffic environment encoding and the historical traffic network encoding to form a traffic semantic space; Step S13: Combining the pre-trained traffic environment encoder and traffic network encoder with the traffic semantic decoder to form a traffic semantic encoder-decoder. 3.The traffic semantic representation based traffic timing modeling method of claim 2, wherein, The training of the traffic semantic encoder-decoder using contrastive learning comprises: Defining a positive sample pair as two encodings describing the same traffic state; defining a negative sample pair as encodings describing different traffic states, and measuring similarity by calculating the similarity between the encodings; Using cosine similarity to measure similarity, and normalizing through a temperature parameter and a Softmax function; Using InfoNCE loss as the loss function to optimize the performance of the encoder, so that the encodings generated by the traffic environment encoder and the traffic network encoder can be effectively aligned in the traffic semantic space; The calculation formula of the cosine similarity to measure similarity is: (1) (2) In the formula, A and B represent traffic environment code and traffic road network code respectively, and represent the components of the encoding vector, d represents the dimension of the encoding, and K represents the batch size of the training; in the formula is a temperature hyperparameter, and the value is 0.2 or 0.07, is the similarity of , and softmax is a normalization function. The loss function is InfoNCE loss: (3) where similarity represents a similarity function, K represents a batch size, represents a positive sample pair, represents a negative sample pair.
4. The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The traffic environment encoder adopts the structure of a single feature extraction module and a multi-feature fusion module; the single feature extraction module one-hot encodes a single environment factor and places the one-hot encoding result in a fully connected network for feature extraction to form a feature extraction layer; The parameters of the hidden fully connected network layer in the feature extraction layer are shared, and only the input layer and output layer parameters are different; after obtaining a single feature, the single feature is spliced and placed in the feature fusion module for feature fusion and dimension reduction; The feature fusion module is a multi-layer fully connected network; The traffic environment encoder outputs a traffic environment code, and the calculation process comprises: (4) (5) In the formula, attr represents different traffic environment factors, X represents a single feature extraction result, C represents a traffic environment code, W and b are weight matrix and bias respectively, and δ represents an activation function LeakyReLU. The traffic environment encoder has an output dimension of 64.
5. The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The traffic network encoder combines a multi-head graph layer and a global readout function to obtain a traffic network code, and the input is a traffic state of a road network at a certain time, and the output is a semantic code, and the output dimension is 64; the multi-head graph attention layer obtains the spatial dependence of the road network through multiple heads and layers; the global readout function integrates the information of each node and outputs; the traffic network encoder introduces a multi-layer graph attention network and a residual connection to process road network information; The multi-layer graph attention network models the connection strength between nodes through different weights; a skip connection is added between each layer to ensure that the node information is not lost; The calculation formula of the multi-head graph attention network with a residual mechanism is: (6) (7) (8) (9) wherein, represents the attention weight between node i and node j, h is the feature of the node, is the neighbor of node i, is the hidden feature of the l-th layer, W is a learnable weight matrix, a is a learnable vector, δ and g are activation functions LeakyReLU; The global readout function is: (10) In the formula, W and b are weight matrix and bias respectively, and δ is an activation function LeakyReLU.
6. The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The traffic semantic decoder and the traffic network encoder are mutually symmetrical in structure; first, the traffic semantic code is converted into features on the nodes of the road network through an attribute assignment function; then, the spatial dependence between different node features is considered through a multi-head attention layer; and finally, the traffic speed is output The training process of the traffic semantic decoder is: (11) In the formula, X represents the traffic flow in the road network. During the training process of the traffic semantic decoder, the parameters of the traffic network encoder are in a frozen state.
7. The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The traffic semantic feature time series inference model performs time series inference on the traffic state in the traffic semantic space, and predicts traffic state indicators including: Step S21: A time series feature capturing module is designed to capture the time series feature relationship in the traffic semantic space, and an enhanced residual long short-term memory network is used to capture the time series features of the traffic state over time; Step S22: On the basis of the time series feature capturing module completing the single-step time series feature capturing, a traffic semantic feature time series inference model is designed; The traffic semantic feature time series inference model includes two interconnected sub-networks: a historical traffic feature extraction module for encoding the semantic evolution process of the historical traffic state; and a future traffic speed inference module that combines future environmental factors to perform time series extrapolation of the traffic state; a priori encoding of the future environment is introduced as auxiliary input; The future environment encoding is embedded in the future traffic flow time series feature inference module that combines environmental features; The inference process of the historical traffic flow time series feature extraction module and the future traffic flow time series feature inference module that combines environmental features is as follows: The historical traffic flow time series feature extraction module receives the semantic encoding in the historical time series, and uses an enhanced residual long short-term memory network to extract the time series dynamic information thereof; The end state of the historical traffic flow time series feature extraction module is used as the initial state of the future traffic flow time series feature inference module that combines environmental features, and the future environment encoding is input to perform time series extrapolation of the traffic state semantic evolution. The future traffic flow time series feature inference module fusing environmental features generates future traffic semantic encoding at each time step, and the decoder restores it to specific traffic states; During the training process, the semantic encoder and decoder are frozen, and only the enhanced residual long short-term memory network is optimized to improve training efficiency and stability; When predicting future speed, the pre-trained traffic semantic decoder directly decodes the semantic encoding output by the future traffic flow time series feature inference module fusing environmental features at each time step, and maps the semantic encoding to the actual road network traffic state.
8. The traffic semantic representation based traffic timing modeling method of claim 7, wherein, The enhanced residual long short-term memory network at the input of the LSTM unit and output Skip connections are added between them, so that the encoding of the traffic semantic space can be directly passed to the output of the LSTM; the enhanced residual long short-term memory network maintains three gating mechanisms, including: input gate, forget gate and output gate; The calculation formula of the enhanced residual long short-term memory network includes: (12) (13) (14) (15) (16) (17) In the formula, , and These represent the outputs of the input gate, forget gate, and output gate, respectively. The input represents the current time step; , , , , , , and It is the weight matrix of the input vector and the hidden state. , , and These are the corresponding bias terms; This represents the sigmoid activation function. This represents element-wise multiplication. Represents the hyperbolic tangent function. and These represent the output vectors of the cell state and the hidden state at the current time step, respectively. 9.The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The training process of the traffic semantic feature time series inference model includes four stages: feature extraction, regularization, time series modeling, and parameter optimization; First, semantic features are extracted from traffic network features and traffic environment factors, and L2 regularization is performed to enhance the numerical stability of the features; Then, the historical traffic flow time series feature extraction module and the future traffic flow time series feature inference module fusing environmental features are used to perform time series reasoning and decoding of future traffic states, and output future speed prediction results; During the training process, by constructing an error loss function between the predicted speed and the true speed, the Adam optimizer is used to perform error backpropagation and iterative update of the parameters of HTEM and FTIMIE, ultimately improving the ability to model traffic states in the traffic semantic space. 10.The traffic semantic representation based traffic timing modeling method of claim 1, wherein, The output predicted traffic state indicators include: Output multi-scale future prediction results, including prediction period ranges from 15 minutes to 180 minutes, and use multiple error indicators to evaluate the model effect, including RMSE, MAE, and MAPE.