A method and system for predicting and analyzing highway traffic flow time series based on LSTM
By integrating multi-dimensional feature fusion and a deep LSTM network, combined with residual correction and physical rationality verification, the problem of the coupling effect of environmental interference and sudden events in highway traffic flow prediction by LSTM models is solved, achieving higher prediction accuracy and stability, adapting to changes in traffic conditions, and reducing operation and maintenance costs.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHANDONG ZHENGCHEN TECH CO LTD
- Filing Date
- 2026-03-09
- Publication Date
- 2026-06-30
AI Technical Summary
Existing LSTM models fail to effectively characterize the coupled effects of environmental disturbances and sudden events in highway traffic flow prediction, and lack adaptive optimization capabilities, resulting in insufficient prediction robustness in complex operating scenarios.
A multi-dimensional feature fusion mechanism is adopted, including temporal, spatiotemporal, and interference features. A deep LSTM network is constructed by dynamically weighting the features through an attention mechanism. Combined with residual correction and physical rationality verification, the model parameters are dynamically adjusted for incremental training.
It improves the accuracy and stability of predictions in complex scenarios, can adapt to changes in traffic conditions, reduces operational complexity and computational costs, and enhances the practical value of predictions during peak hours, severe weather, and emergencies.
Smart Images

Figure CN122313686A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of highway management technology, specifically relating to a method and system for predicting and analyzing the temporal sequence of highway traffic flow based on LSTM. Background Technology
[0002] With the rapid development of Intelligent Transportation Systems (ITS), accurate prediction of temporal changes in highway traffic flow has become a key technological foundation for improving road network operational efficiency and supporting proactive traffic management and travel guidance. Traditional prediction methods, such as historical averaging and ARIMA models, are unable to effectively characterize the nonlinear, random, and strongly spatiotemporally dependent characteristics of traffic flow; while early machine learning methods (such as support vector machines and shallow neural networks) have limitations in handling long-sequence dependencies and multi-source heterogeneous data. In recent years, deep learning models, especially Long Short-Term Memory (LSTM) networks, have been widely applied in the field of traffic prediction due to their excellent temporal modeling capabilities. However, existing LSTM models mostly focus only on the historical sequence of a single traffic flow parameter, neglecting the coupling effects of environmental disturbances (such as rainfall and visibility), sudden traffic events (such as accidents and construction), and road network spatial correlations on the target road segment, resulting in insufficient prediction robustness in complex operating scenarios. In addition, most models adopt static training strategies, lacking feedback mechanisms for prediction errors and online adaptive optimization capabilities, making it difficult to adapt to the dynamic evolution of traffic conditions. Summary of the Invention
[0003] To address the aforementioned shortcomings of existing technologies, this invention provides a method, system, terminal, and storage medium for predictive analysis of highway traffic flow based on LSTM, in order to solve the aforementioned technical problems.
[0004] In a first aspect, the present invention provides a method for time-series prediction and analysis of highway traffic flow based on LSTM, comprising: S1. Collect traffic flow time-series parameters of the target highway segment; traffic flow time-series parameters include traffic flow parameters, environmental disturbance data, traffic event data, and time characteristic data; S2. Preprocess the traffic flow time sequence parameters collected in step S1; S3. Extract and fuse temporal features, spatiotemporal correlation features, and interference features from the preprocessed data to form a fused feature set; S4. Input the fused feature set into the pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and perform residual correction and rationality verification on the prediction results. S5. Based on the error between actual traffic flow data and prediction results, dynamically adjust the parameters of the neural network model and perform incremental training.
[0005] Further improvements to this technical solution include step S1, which includes: S11. Deploy microwave radar, geomagnetic coils and video checkpoint equipment at key sections of the target highway to collect traffic flow parameters including traffic flow, average vehicle speed and lane occupancy. S12. Access environmental disturbance data and traffic incident data related to the road section in real time through the road network operation monitoring platform, including rainfall intensity, visibility, wind speed, accident sign positions, construction sign positions and control level codes, and align them according to a unified timestamp; S13. Extract structured time context features, including the current hour, weekday type, and holiday identifiers, and integrate all collected data into a multi-dimensional time-series record with a unified spatiotemporal index to form the original input sample set: ; in, This represents the traffic flow at time t; This represents the average vehicle speed at time t; This represents the lane occupancy rate at time t; Let represent the rainfall intensity, visibility, and wind speed at time t, respectively. These are coded symbols for accidents, construction, and control events, respectively. For hours ; The week type is 1 for Monday; This is a holiday indicator (1 indicates a statutory holiday or a day off in lieu of a holiday).
[0006] Further improvements to this technical solution include step S2, which includes: S21. Use the sliding window 3σ criterion to identify and correct outliers in traffic flow time sequence parameters; S22. Imputation of missing data: For short-term missing data, linear interpolation of the effective values before and after the missing data is used; for long-term missing data, weighted estimation is performed using the historical correlation of adjacent road segments in the topology. S23. Perform Min-Max normalization on all preprocessed traffic flow time series parameters, and construct structured time series samples by slicing according to the preset historical window length.
[0007] Further improvements to this technical solution include step S3, which includes: S31. Perform multi-scale periodic decomposition on the normalized traffic flow sequence, extract daily and weekly periodic components using a sliding Fourier window, and calculate the complex amplitude corresponding to the k-th dominant frequency. Its discrete Fourier transform formula is: ; in, This represents the total number of sampling points within a day; The traffic flow value after preprocessing in step S2 and normalized to the interval [0,1] is the standardized traffic flow of the target highway segment at time t. Corresponding to a 24-hour cycle; Corresponding to a 168-hour cycle; the real and imaginary parts are taken as long-term time series features. ; S32. Construct a spatial correlation weight matrix between the target road segment and its topologically adjacent road segments. Calculate the inter-segment influence coefficient based on historical traffic correlation. Define the spatial weight of road segment i to target road segment k as follows: ; in, This is the set of upstream and downstream road segments directly connected to road segment k; The Pearson correlation coefficient of traffic flow between road segments i and k over the same period in the past 30 days is used to calculate the normalized traffic flow of adjacent road segments at the current time. Weighted aggregation into spatial context features: ; Forming spatiotemporal correlation feature vectors ; S33. Attention-weighted fusion of environmental disturbances and event-type features, including rainfall intensity. ,visibility Accident signs ,Men at work and time feature vector splicing as interference feature input The importance weights are calculated using a learnable single-layer attention network. : ; in, These are the parameters learned during the model training phase; To hide the dimension; the final weighted perturbation feature is The above three types of features are combined to form a fused feature set. , as input to the LSTM prediction model.
[0008] Further improvements to this technical solution include step S4, which includes: S41. Construct a deep temporal encoder consisting of three stacked LSTM layers, each containing 128 memory units. The layers are connected sequentially, with the hidden state sequence of the previous layer serving as the input to the next layer. The final hidden state of the third LSTM layer... After passing through a Dropout layer, it is connected to a fully connected output layer. The weight matrix of this output layer is... Map it to traffic flow forecasts for a preset future time interval. : ; in, To provide the output bias term, the model uses the mean squared error loss function during the training phase. Perform end-to-end optimization; S42. In the inference phase, perform residual correction on the preliminary prediction results, utilizing historical prediction residual sequences. Construct a first-order autoregressive AR(1) model to estimate the residual correction for the current time period. Among them, the autoregressive coefficient The final corrected predicted value is estimated online using the least squares method on the residual data of the most recent 7 days: ; in, This represents the predicted traffic flow at time t+i after residual compensation. To predict the step size; S43. Perform a physical rationality check on the corrected prediction results. If any Exceeding the theoretical capacity limit of the road section If the value is below zero, it will be truncated according to the following rules: ; in, This represents the maximum possible traffic flow for this road section. , Traffic congestion density, For free flow velocity, For the length of the road segment, This refers to the number of lanes.
[0009] Further improvements to this technical solution include step S4, which further includes: S40a. Before inputting the fused feature set into the LSTM neural network model, perform time step alignment and dimension verification on the input sequence; S40b: During LSTM model inference, the activation distribution of each hidden state is recorded in real time, and a gradient pruning mechanism is dynamically enabled based on a preset gradient magnitude threshold. like ,but: ; in, Indicates model loss For parameters The gradient; This is the preset upper limit of the gradient norm; S40c. After residual correction and before rationality verification, a confidence interval filtering mechanism based on the historical traffic variation coefficient of the road segment is introduced. If the corrected predicted value... Exceeding For intervals, the original predicted values are used as the final output; where, This represents the standard deviation of historical traffic flow for this road segment during the same time period. The confidence factor.
[0010] Further improvements to this technical solution include step S5, which includes: S51. After each prediction period ends, collect the actual traffic flow of the target road segment during the corresponding time period. and the final predicted value output from step S4. The mean absolute percentage error (MAPE) is calculated as a performance evaluation metric for the model. The formula is as follows: ; in, To prevent the smoothing constant from having a denominator of zero, if the smoothing constant is for three consecutive periods... Exceeding the preset threshold This triggers the dynamic adjustment mechanism for model parameters; S52. Adaptively adjust key hyperparameters of the LSTM model based on error feedback: If the error is concentrated in short-term predictions, increase the number of units in the first LSTM layer to 192 and reduce the learning rate; if the error is concentrated in long-term predictions, increase the memory capacity of the third LSTM layer and adjust the dropout rate p to 0.2; simultaneously, update the learning rate using an exponential moving average method. Its update rules are as follows: ; in, The initial learning rate, ; As the attenuation factor, ; Indicates the number of prediction periods required to perform one decay prediction; S53. Construct an incremental training sample set using the newly added measured data. ,in (i.e., data from the most recent 24 hours), while retaining the original model weights, the LSTM network is fine-tuned with a smaller batch size B=16 and a limited number of training epochs E=3, without re-initializing any layers, and the updated model parameters are written into the road segment-specific model version library to achieve continuous online learning and performance optimization for the target road segment.
[0011] Secondly, the present invention provides an LSTM-based highway traffic flow time-series prediction and analysis system, comprising: The high-speed data acquisition module is used to collect traffic flow time-series parameters of the target highway segment; the traffic flow time-series parameters include traffic flow parameters, environmental interference data, traffic event data, and time characteristic data; The data preprocessing module is used to preprocess the traffic flow time-series parameters collected in step S1; The feature extraction module is used to extract and fuse temporal features, spatiotemporal correlation features and interference features from the preprocessed data to form a fused feature set; The traffic flow prediction module is used to input the fused feature set into a pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and to perform residual correction and rationality verification on the prediction results. The model adjustment module is used to dynamically adjust the parameters of the neural network model and perform incremental training based on the error between the actual traffic flow data and the prediction results.
[0012] Thirdly, the present invention provides a terminal, comprising: Processor, memory, among which, This memory is used to store computer programs. The processor is used to retrieve and run the computer program from memory, causing the terminal to perform the terminal method described above.
[0013] Fourthly, the present invention provides a computer storage medium storing instructions that, when executed on a computer, cause the computer to perform the methods described in the above aspects.
[0014] The beneficial effects of this invention are as follows: By introducing a multi-dimensional feature fusion mechanism (temporal, spatiotemporal, and interference), particularly employing an attention mechanism to dynamically weight interference features and constructing a deep LSTM network to mine long-term temporal dependencies, this scheme can more comprehensively and adaptively characterize the complex nonlinear dynamics of traffic flow. Combined with post-processing optimizations such as residual correction and physical rationality verification, the system's accuracy and stability in predicting sudden disturbances such as rainfall and accidents are significantly enhanced, effectively overcoming the problem of large prediction biases in complex scenarios caused by traditional methods and single LSTM models.
[0015] This solution forms a closed loop from data acquisition, preprocessing, feature engineering to model prediction and optimization. By structurally integrating multi-source information such as environmental interference, traffic events, and road network spatial correlations, and designing corresponding feature extraction and fusion algorithms (such as Fourier decomposition, spatial weight matrix, and attention network), the model is equipped with the ability to understand and respond to the coupled influence of various complex real-world factors, significantly improving its practical value under non-ideal conditions such as peak hours, severe weather, and emergencies.
[0016] The clearly defined data preprocessing workflow, standardized feature construction methods, and efficient LSTM model structure (e.g., fixed number of layers and units) in this solution lay the foundation for rapid inference. Gradient pruning and other mechanisms ensure training stability. Incremental training and dynamic parameter adjustment strategies enable the model to learn online and quickly adapt to changes in traffic conditions without frequent full retraining, reducing the complexity and computational cost of long-term operation and maintenance, and making it more conducive to practical engineering deployment and continuous operation.
[0017] By constructing a standardized input sample set with explicit spatiotemporal indices and employing a general feature extraction method based on road segment topology (such as calculating the correlation between adjacent road segments), this approach does not heavily rely on the unique attributes of the target road segment. This allows the trained model or training process to be more easily transferred to other highway segments with similar traffic characteristics, enabling rapid adaptation through fine-tuning or incremental learning mechanisms, thus enhancing the universality and application value of the technology. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is a schematic flowchart illustrating a method according to an embodiment of the present invention.
[0020] Figure 2 This is a schematic block diagram of a system according to an embodiment of the present invention.
[0021] Figure 3 This is a schematic diagram of the structure of a terminal provided in an embodiment of the present invention. Detailed Implementation
[0022] To make the objectives, features, and advantages of this invention more apparent and understandable, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings of the specific embodiments. Obviously, the embodiments described below are only some embodiments of this invention, and not all embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0023] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used herein in the description of the invention is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0024] The LSTM-based highway traffic flow time-series prediction and analysis method provided in this embodiment of the invention is executed by a computer device, and correspondingly, the LSTM-based highway traffic flow time-series prediction and analysis system runs on the computer device.
[0025] Figure 1 This is a schematic flowchart illustrating a method according to an embodiment of the present invention. Wherein, Figure 1 The implementing entity can be an LSTM-based highway traffic flow time-series prediction and analysis system. Depending on different requirements, the order of steps in this flowchart can be changed, and some can be omitted.
[0026] like Figure 1 As shown, the method includes: S1. Collect traffic flow time-series parameters of the target highway segment; traffic flow time-series parameters include traffic flow parameters, environmental disturbance data, traffic event data, and time characteristic data; S2. Preprocess the traffic flow time sequence parameters collected in step S1; S3. Extract and fuse temporal features, spatiotemporal correlation features, and interference features from the preprocessed data to form a fused feature set; S4. Input the fused feature set into the pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and perform residual correction and rationality verification on the prediction results. S5. Based on the error between actual traffic flow data and prediction results, dynamically adjust the parameters of the neural network model and perform incremental training.
[0027] To facilitate understanding of the present invention, the following description further illustrates the LSTM-based highway traffic flow time-series prediction and analysis method provided by the present invention, based on the principle of the LSTM-based highway traffic flow time-series prediction and analysis method and in conjunction with the process of predicting and analyzing highway traffic flow time-series based on LSTM in the embodiments.
[0028] First, step S1 includes: S11. Deploy microwave radar, geomagnetic coils and video checkpoint equipment at key sections of the target highway to collect traffic flow parameters including traffic flow, average vehicle speed and lane occupancy. S12. Access environmental disturbance data and traffic incident data related to the road section in real time through the road network operation monitoring platform, including rainfall intensity, visibility, wind speed, accident sign positions, construction sign positions and control level codes, and align them according to a unified timestamp; S13. Extract structured time context features, including the current hour, weekday type, and holiday identifiers, and integrate all collected data into a multi-dimensional time-series record with a unified spatiotemporal index to form the original input sample set: ; in, This represents the traffic flow at time t; This represents the average vehicle speed at time t; This represents the lane occupancy rate at time t; Let represent the rainfall intensity, visibility, and wind speed at time t, respectively. These are coded symbols for accidents, construction, and control events, respectively. For hours ; The week type is 1 for Monday; This is a holiday indicator (1 indicates a statutory holiday or a day off in lieu of a holiday).
[0029] For the target highway section, priority is given to selecting locations with sudden changes in traffic flow or representative locations such as interchange entrances and exits, tunnel entrances and exits, both ends of bridges, accident-prone sections, and midpoints of the section as key sections; for six-lane highways, one key section is set up every 5-8 kilometers to ensure full coverage monitoring of traffic flow status across the entire section; each key section is equipped with independent data acquisition devices for each lane to avoid data interference between different lanes.
[0030] Magnetic coils: Deployed along the longitudinal direction of the lane at a distance of 30 meters from the stop line, with 2 coils (5 meters apart) in each lane, used for vehicle presence detection and speed assistance calibration. The coil response time is ≤10ms, and the detection accuracy is ≥98%. Microwave radar: Installed on a roadside gantry (6-8 meters high), with 2 units deployed in each section (1 unit in each direction). The radar detection range covers all lanes in the section, with a detection distance of 50-200 meters, a speed measurement range of 0-120 km / h, a speed measurement accuracy of ±1 km / h, and a sampling frequency of 10 Hz. Video checkpoint: Installed on the same gantry as the microwave radar, with the lens facing the direction of traffic flow, resolution ≥1920×1080, frame rate 25fps, supports license plate recognition and vehicle counting, recognition accuracy ≥95%, used for traffic flow verification and abnormal vehicle marking.
[0031] Data collection interval: uniformly set to 5 minutes / time, with devices triggering data collection synchronously to ensure data consistency across different devices on the same cross-section; Traffic flow ( ): The total number of vehicles passing through a lane of this section within 5 minutes is counted. The total flow rate of the entire section is the sum of the flow rates of each lane, and the unit is "vehicles / 5 minutes". Average vehicle speed ( ): Based on the instantaneous speed of a single vehicle collected by microwave radar, calculate the arithmetic mean of all vehicles passing through the section within 5 minutes, in "km / h", after removing data with instantaneous speeds <5km / h (congestion) and >120km / h (abnormal speeding); Lane occupancy rate ( The time it takes for a vehicle to pass is detected by a geomagnetic coil, and the calculation formula is as follows: Where n is the number of vehicles passing through the lane in 5 minutes. Let T be the time difference between the two coils for the i-th vehicle (i.e., the duration the vehicle occupies the coil), and let T be the sampling interval (300 seconds). The result is rounded to one decimal place.
[0032] Environmental interference data: Two types of data are accessed through the road network operation monitoring platform: one is the rainfall intensity collected by roadside meteorological sensors (deployed co-located with key sections). (Unit: mm / h), wind speed ( (Unit: m / s), sampling interval 5 minutes; secondly, visibility provided by regional weather stations ( (Unit: m), with a data collection interval of 10 minutes, data transmission using the MQTT protocol, and a latency of ≤3 seconds; Traffic incident data: Accessed through the traffic management department's incident reporting system and roadside camera AI recognition results, including three types of incidents: accidents, construction, and traffic control. Data transmission uses a REST API interface to push real-time information on the time, location, type, and severity of the incident.
[0033] Event coding rules: Accident sign position ( ): 0 indicates no accident, 1 indicates an accident (including minor scratches, collisions and other types of traffic accidents); Construction marker position ( : 0 indicates no construction, 1 indicates construction (including road maintenance, facility repair, and other construction activities that occupy lanes or affect traffic); Control level code ( : 0 indicates no control, 1 indicates light control (speed limit, lane restriction), 2 indicates moderate control (half-width closure), 3 indicates heavy control (full-width closure).
[0034] Unified time base: All data is converted to UTC time, accurate to the second (format: YYYY-MM-DD HH:MM:SS). Asynchronous data processing: For visibility and other data with 10-minute intervals, linear interpolation is used to complete the intervals to 5-minute intervals. The interpolation formula is as follows: Where T = 10 minutes (i.e., 2 acquisition intervals) and k = 5 minutes (i.e., 1 acquisition interval). The interpolated visibility at the intermediate time point; Alignment verification: For each 5-minute time node, verify that the timestamp deviation of traffic flow data, environmental data, and event data is ≤1 second. Data with deviation exceeding the standard is marked as "to be reviewed" and will be removed or corrected in subsequent preprocessing stages.
[0035] Temporal context feature extraction rules: Current hour ( ): Extracts the 24-hour clock based on the timestamp, with a value range of 0-23 (for example, 0 represents 00:00-00:59, and 23 represents 23:00-23:59). Week type ( ): Based on the date, 1 corresponds to Monday, 2 corresponds to Tuesday, ..., 7 corresponds to Sunday, and the value range is 1-7; Holiday signs ( ): Pre-import the list of national statutory holidays and adjusted workdays (updated annually). If the current date belongs to this list, then... ,otherwise The holidays include statutory holidays such as the Spring Festival and National Day, as well as officially announced adjusted working days.
[0036] Multidimensional time-series record integration specifications: Sample set structure: A two-dimensional data table is constructed using "timestamp-segment number-section number" as the composite primary key. Each row corresponds to a complete data record of a key section at a specific 5-minute time. The column fields include: timestamp, segment number, section number, and traffic flow. Average vehicle speed Lane occupancy Rainfall intensity ,visibility Wind speed Accident sign position Construction marker positions Control level code Hours Week type Holiday signs ; Data format requirements: Numerical data should be retained to 1-2 decimal places (flow rate should be an integer), coded data should be assigned values according to regulations (0 / 1 or 1-7, etc.), and missing data should be temporarily marked with NULL and filled in during subsequent preprocessing stages; Storage method: Uses a time-series database (such as InfluxDB) for storage, sets the data retention policy to 1 year, and supports fast query and batch export by road segment and time range.
[0037] Secondly, step S2 includes: S21. Use the sliding window 3σ criterion to identify and correct outliers in traffic flow time series parameters: ; ; in, The length of the sliding window for anomaly detection; and Let represent the local mean and standard deviation centered at t, with a window length of W = 9 sampling intervals (i.e., 45 minutes); The effective flow observation value at time i, and the outlier. Replaced with the linear interpolation result of non-abnormal neighboring points within the window; k is the target road segment number; The set of adjacent road segments that are topologically connected to the target road segment k; S22. Imputation of missing data: For short-term missing data, linear interpolation of the effective values before and after the missing data is used; for long-term missing data, weighted estimation is performed using the historical correlation of topologically adjacent road segments. ; in, The measured flow rate of adjacent road segment j at time t; weight It is obtained by normalizing the historical Pearson correlation coefficient, that is ; The Pearson correlation coefficient between traffic flow on road segments k and j during the same period over the past 30 days. S23. Perform Min-Max normalization on all preprocessed traffic flow time series parameters, and construct structured time series samples by slicing according to the preset historical window length.
[0038] Next, step S3 includes: S31. Perform multi-scale periodic decomposition on the normalized traffic flow sequence, extract daily and weekly periodic components using a sliding Fourier window, and calculate the complex amplitude corresponding to the k-th dominant frequency. Its discrete Fourier transform formula is: ; in, This represents the total number of sampling points within a day. ; The traffic flow value after preprocessing in step S2 and normalized to the interval [0, 1] is the standardized traffic flow of the target highway segment at time t. Corresponding to a 24-hour cycle, ; Corresponding to a 168-hour cycle, Take the real and imaginary parts as long-term time series features. ; S32. Construct a spatial correlation weight matrix between the target road segment and its topologically adjacent road segments. Calculate the inter-segment influence coefficient based on historical traffic correlation. Define the spatial weight of road segment i to target road segment k as follows: ; in, This is the set of upstream and downstream road segments directly connected to road segment k; The Pearson correlation coefficient of traffic flow between road segments i and k over the same period in the past 30 days is used to calculate the normalized traffic flow of adjacent road segments at the current time. Weighted aggregation into spatial context features: ; Forming spatiotemporal correlation feature vectors ; S33. Attention-weighted fusion of environmental disturbances and event-type features, including rainfall intensity. ,visibility Accident signs ,Men at work and time feature vector splicing as interference feature input The importance weights are calculated using a learnable single-layer attention network. : ; in, These are the parameters learned during the model training phase; To hide dimensions, The final weighted interference feature is The above three types of features are combined to form a fused feature set. , as input to the LSTM prediction model, where .
[0039] Then, step S4 includes: S41. Construct a deep temporal encoder consisting of three stacked LSTM layers, each containing 128 memory units. The layers are connected sequentially, with the hidden state sequence of the previous layer serving as the input to the next layer. The final hidden state of the third LSTM layer... After passing through a Dropout layer (dropout rate p=0.25), it is connected to a fully connected output layer. The weight matrix of this output layer is... Map it to a future preset time interval ( Traffic flow forecast (i.e., 30 minutes) : ; in, To provide the output bias term, the model uses the mean squared error loss function during the training phase. Perform end-to-end optimization; S42. In the inference phase, perform residual correction on the preliminary prediction results, utilizing historical prediction residual sequences. Construct a first-order autoregressive AR(1) model to estimate the residual correction for the current time period. Among them, the autoregressive coefficient The final corrected predicted value is estimated online using the least squares method on the residual data of the most recent 7 days: ; in, This represents the predicted traffic flow at time t+i after residual compensation. To predict the step size; S43. Perform a physical rationality check on the corrected prediction results. If any Exceeding the theoretical capacity limit of the road section If the value is below zero, it will be truncated according to the following rules: ; in, This represents the maximum possible traffic flow for this road section. , Traffic congestion density, For free flow velocity, For the length of the road segment, This refers to the number of lanes.
[0040] Furthermore, step S4 also includes: S40a. Before inputting the fused feature set into the LSTM neural network model, perform time step alignment and dimension verification on the input sequence; S40b: During LSTM model inference, the activation distribution of hidden states in each layer is recorded in real time, and a gradient clipping mechanism is dynamically enabled based on a preset gradient magnitude threshold to prevent gradient explosion during training or fine-tuning. like ,but: ; in, Indicates model loss For parameters The gradient; The upper limit of the gradient norm is preset. , used to stabilize backpropagation; S40c. After residual correction and before rationality verification, a confidence interval filtering mechanism based on the historical traffic variation coefficient of the road segment is introduced. If the corrected predicted value... Exceeding For intervals, the original predicted values are used as the final output; where, This represents the standard deviation of historical traffic flow for this road segment during the same time period. It is the confidence multiple; that is, if ,but ; represents the standard deviation of traffic flow for the road segment in the same historical period (e.g., the t+ith 5-minute period of each day in the past 30 days), reflecting the natural fluctuation level of that period; Corresponding to a confidence level of approximately 98.8% for the normal distribution, it is used to identify overcorrections that may be introduced by residual correction.
[0041] Gradient calculation and norm solution: During model training, after each iteration, the loss function C is calculated with respect to all trainable parameters θ (including LSTM unit weights, bias terms, and fully connected layer weights). Bias terms gradient of ) The gradient magnitude is calculated using the L2 norm, as shown in the formula below. Where M is the total number of trainable parameters. Let be the partial derivative of the loss function with respect to the k-th parameter.
[0042] Gradient clipping execution logic: Preset upper limit of gradient norm If the calculated The gradient is then clipped according to the following formula: ,in This is the clipped gradient. The clipped gradient is used for parameter updates to avoid gradient explosion, which can cause model training oscillations or non-convergence; if If so, the original gradient is used directly for parameter updates.
[0043] Model hierarchical structure details: Input layer: Receives the input sequence after S40a verification. The input dimension is [24, 20] (time step length × feature dimension), with no activation function, and it is only responsible for data transmission.
[0044] Hidden layers: Composed of three stacked LSTM units, each containing 128 memory units (neurons). The input to the first LSTM unit is the input layer output, and the output is the hidden state sequence. The input of the second-layer LSTM unit is Output the hidden state sequence The input of the third-layer LSTM unit is Output the hidden state sequence Take the hidden state of the last time step of the third layer. As input for subsequent layers.
[0045] Dropout layer: Following the third LSTM layer, with a dropout rate p=0.25, as shown in the formula. ;in, The Dropout layer output randomly discards 25% of neuron connections to suppress model overfitting.
[0046] Output layer: Fully connected layer, weight matrix (Prediction step size × hidden layer dimension), bias term The activation function uses linear activation and outputs preliminary predictions for the next 6 time steps. The formula is .
[0047] Key parameters and steps for model training: Optimizer: Adam optimizer selected, initial learning rate Momentum parameters , Weight decay coefficient .
[0048] Loss function: Mean squared error (MSE) is used, and the formula is as follows: Where N is the number of training samples, Let be the actual flow rate of the s-th sample at time t+i. This corresponds to the predicted value.
[0049] Training process: Divide the sample set into training set, validation set and test set in a 7:2:1 ratio; training epochs E=50, batch size B=32; calculate the loss value using the validation set after each training epoch; if the loss of the validation set does not decrease for 8 consecutive epochs, trigger the early stop mechanism to stop training; evaluate the model performance using the test set after training to ensure that the initial prediction error meets the requirements.
[0050] Finally, step S5 includes: S51. After each prediction period ends, collect the actual traffic flow of the target road segment during the corresponding time period. and the final predicted value output from step S4. The mean absolute percentage error (MAPE) is calculated as a performance evaluation metric for the model. The formula is as follows: ; in, To prevent the smoothing constant from having a denominator of zero, if the smoothing constant is for three consecutive periods... Exceeding the preset threshold This triggers the dynamic adjustment mechanism for model parameters; S52. Adaptive correction of key hyperparameters of the LSTM model based on error feedback: if the error is concentrated in the short-term prediction ( If the error is concentrated in the long-term prediction (), then increase the number of LSTM units in the first layer to 192 and reduce the learning rate; If this is the case, then the memory capacity of the third-layer LSTM is increased and the Dropout rate p is adjusted to 0.2; at the same time, the learning rate is updated using an exponential moving average method. Its update rules are as follows: ; in, The initial learning rate, ; As the attenuation factor, ; This indicates the number of prediction periods for one decay cycle. ; S53. Construct an incremental training sample set using the newly added measured data. ,in (i.e., data from the most recent 24 hours), while retaining the original model weights, the LSTM network is fine-tuned with a smaller batch size B=16 and a limited number of training epochs E=3, without re-initializing any layers, and the updated model parameters are written into the road segment-specific model version library to achieve continuous online learning and performance optimization for the target road segment.
[0051] In some embodiments, the LSTM-based highway traffic flow time-series prediction and analysis system 200 may include multiple functional modules composed of computer program segments. The computer programs for each program segment in the LSTM-based highway traffic flow time-series prediction and analysis system 200 may be stored in the memory of a computer device and executed by at least one processor to perform (see details). Figure 1 (Description) Functionality of LSTM-based temporal prediction analysis for highway traffic flow.
[0052] In this embodiment, the LSTM-based highway traffic flow time-series prediction and analysis system 200 can be divided into multiple functional modules according to its functions, such as... Figure 2 As shown. The functional modules may include: a high-speed data acquisition module 210, a data preprocessing module 220, a feature extraction module 230, a traffic flow prediction module 240, and a model adjustment module 250. The module referred to in this invention is a series of computer program segments that can be executed by at least one processor and perform a fixed function, stored in memory. In this embodiment, the functions of each module will be described in detail in subsequent embodiments.
[0053] Specifically, the high-speed data acquisition module 210 is used to acquire traffic flow time-series parameters of the target highway segment; the traffic flow time-series parameters include traffic flow parameters, environmental interference data, traffic event data, and time feature data; the data preprocessing module 220 is used to preprocess the traffic flow time-series parameters acquired in step S1; the feature extraction module 230 is used to extract and fuse time-series features, spatiotemporal correlation features, and interference features from the preprocessed data to form a fused feature set; the traffic flow prediction module 240 is used to input the fused feature set into a pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and to perform residual correction and rationality verification on the prediction results; the model adjustment module 250 is used to dynamically adjust the neural network model parameters and perform incremental training based on the error between the actual traffic flow data and the prediction results.
[0054] Figure 3 This is a schematic diagram of the structure of a terminal 300 provided in an embodiment of the present invention. The terminal 300 can be used to execute the LSTM-based highway traffic flow time-series prediction and analysis method provided in the embodiment of the present invention.
[0055] The terminal 300 may include a processor 310, a memory 320, and a communication module 330. These components communicate via one or more buses. Those skilled in the art will understand that the server structure shown in the figure does not constitute a limitation of the present invention. It may be a bus topology or a star topology, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0056] The memory 320 can be used to store the execution instructions of the processor 310. The memory 320 can be implemented by any type of volatile or non-volatile memory terminal or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. When the execution instructions in the memory 320 are executed by the processor 310, the terminal 300 is able to perform some or all of the steps in the above method embodiments.
[0057] The processor 310 serves as the control center of the storage terminal, connecting various parts of the electronic terminal via various interfaces and lines. It executes software programs and / or modules stored in the memory 320, and calls data stored in the memory to perform various functions of the electronic terminal and / or process data. The processor can be composed of integrated circuits (ICs), such as a single packaged IC or multiple packaged ICs with the same or different functions connected together. For example, the processor 310 may consist only of a central processing unit (CPU). In this embodiment of the invention, the CPU may have a single processing core or include multiple processing cores.
[0058] The communication module 330 is used to establish a communication channel, enabling the storage terminal to communicate with other terminals. It receives user data sent by other terminals or sends user data to other terminals.
[0059] The present invention also provides a computer storage medium, wherein the computer storage medium may store a program, which, when executed, may include some or all of the steps provided in the embodiments of the present invention. The storage medium may be a magnetic disk, an optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0060] Therefore, the technical effects that can be achieved by this invention and this embodiment can be found in the description above, and will not be repeated here.
[0061] Those skilled in the art will clearly understand that the techniques in the embodiments of the present invention can be implemented using software plus necessary general-purpose hardware platforms. Based on this understanding, the technical solutions in the embodiments of the present invention, or the parts that contribute to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium such as a USB flash drive, mobile hard drive, read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk, or other media capable of storing program code. It includes several instructions to cause a computer terminal (which may be a personal computer, server, or a second terminal, network terminal, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention.
[0062] The same or similar parts between the various embodiments in this specification can be referred to mutually. In particular, the terminal embodiments are basically similar to the method embodiments, so the description is relatively simple, and the relevant parts can be referred to the description in the method embodiments.
[0063] In the embodiments provided by this invention, it should be understood that the disclosed systems and methods can be implemented in other ways. For example, the system embodiments described above are merely illustrative. For instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between systems or modules may be electrical, mechanical, or other forms.
[0064] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0065] In addition, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module.
[0066] Although the present invention has been described in detail with reference to the accompanying drawings and preferred embodiments, the present invention is not limited thereto. Various equivalent modifications or substitutions can be made to the embodiments of the present invention by those skilled in the art without departing from the spirit and essence of the invention, and such modifications or substitutions should all be within the scope of the present invention. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should also be covered within the protection scope of the present invention.
Claims
1. A method for temporal prediction and analysis of highway traffic flow based on LSTM, characterized in that, include: S1. Collect traffic flow time-series parameters of the target highway segment; Traffic flow time series parameters include traffic flow parameters, environmental disturbance data, traffic event data, and time characteristic data; S2. Preprocess the traffic flow time sequence parameters collected in step S1; S3. Extract and fuse temporal features, spatiotemporal correlation features, and interference features from the preprocessed data to form a fused feature set; S4. Input the fused feature set into the pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and perform residual correction and rationality verification on the prediction results. S5. Based on the error between actual traffic flow data and prediction results, dynamically adjust the parameters of the neural network model and perform incremental training.
2. The method for time-series prediction and analysis of highway traffic flow based on LSTM according to claim 1, characterized in that, Step S1 includes: S11. Deploy microwave radar, geomagnetic coils and video checkpoint equipment at key sections of the target highway to collect traffic flow parameters including traffic flow, average vehicle speed and lane occupancy. S12. Real-time access to environmental disturbance data and traffic incident data related to the road section through the road network operation monitoring platform, including rainfall intensity, visibility, wind speed, accident sign positions, construction sign positions and control level codes, and alignment according to a unified timestamp; S13. Extract structured time context features, including the current hour, weekday type, and holiday identifiers, and integrate all collected data into a multi-dimensional time-series record with a unified spatiotemporal index to form the original input sample set: ; in, This represents the traffic flow at time t; This represents the average vehicle speed at time t; This represents the lane occupancy rate at time t; Let represent the rainfall intensity, visibility, and wind speed at time t, respectively. These are coded symbols for accidents, construction, and control events, respectively. For hours ; It is a weekday type; This is a sign for holidays.
3. The method for time-series prediction and analysis of highway traffic flow based on LSTM according to claim 1, characterized in that, Step S2 includes: S21. Use the sliding window 3σ criterion to identify and correct outliers in traffic flow time sequence parameters; S22. Imputation of missing data: For short-term missing data, linear interpolation of the effective values before and after the missing data is used; for long-term missing data, weighted estimation is performed using the historical correlation of adjacent road segments in the topology. S23. Perform Min-Max normalization on all preprocessed traffic flow time series parameters, and construct structured time series samples by slicing according to the preset historical window length.
4. The method for time-series prediction and analysis of highway traffic flow based on LSTM according to claim 2, characterized in that, Step S3 includes: S31. Perform multi-scale periodic decomposition on the normalized traffic flow sequence, extract daily and weekly periodic components using a sliding Fourier window, and calculate the complex amplitude corresponding to the k-th dominant frequency. Its discrete Fourier transform formula is: ; in, This represents the total number of sampling points within a day; The traffic flow value after preprocessing in step S2 and normalized to the interval [0, 1] is the standardized traffic flow of the target highway segment at time t. Corresponding to a 24-hour cycle; Corresponding to a 168-hour cycle; the real and imaginary parts are taken as long-term time series features. ; S32. Construct a spatial correlation weight matrix between the target road segment and its topologically adjacent road segments. Calculate the inter-segment influence coefficient based on historical traffic correlation. Define the spatial weight of road segment i to target road segment k as follows: ; in, This is the set of upstream and downstream road segments directly connected to road segment k; The Pearson correlation coefficient of traffic flow between road segments i and k over the same period in the past 30 days is used to calculate the normalized traffic flow of adjacent road segments at the current time. Weighted aggregation into spatial context features: ; Forming spatiotemporal correlation feature vectors ; S33. Attention-weighted fusion of environmental disturbances and event-type features, including rainfall intensity. ,visibility Accident signs ,Men at work and time feature vector splicing as interference feature input The importance weights are calculated using a learnable single-layer attention network. : ; in, These are the parameters learned during the model training phase; To hide the dimension; the final weighted perturbation feature is The above three types of features are combined to form a fused feature set. , as input to the LSTM prediction model.
5. The LSTM-based temporal prediction and analysis method for highway traffic flow according to claim 4, characterized in that, Step S4 includes: S41. Construct a deep temporal encoder consisting of three stacked LSTM layers, each containing 128 memory units. The layers are connected sequentially, with the hidden state sequence of the previous layer serving as the input to the next layer. The final hidden state of the third LSTM layer... After passing through a Dropout layer, it is connected to a fully connected output layer. The weight matrix of this output layer is... Map it to traffic flow forecasts for a preset future time interval. : ; in, To provide the output bias term, the model uses the mean squared error loss function during the training phase. Perform end-to-end optimization; S42. In the inference phase, perform residual correction on the preliminary prediction results, utilizing historical prediction residual sequences. Construct a first-order autoregressive AR(1) model to estimate the residual correction for the current time period. Among them, the autoregressive coefficient The final corrected predicted value is estimated online using the least squares method on the residual data of the most recent 7 days: ; in, This represents the predicted traffic flow at time t+i after residual compensation. To predict the step size; S43. Perform a physical rationality check on the corrected prediction results. If any Exceeding the theoretical capacity limit of the road section If the value is below zero, it will be truncated according to the following rules: ; in, This represents the maximum possible traffic flow for this road section. , Traffic congestion density, For free flow velocity, For the length of the road segment, This refers to the number of lanes.
6. The LSTM-based temporal prediction and analysis method for highway traffic flow according to claim 5, characterized in that, Step S4 also includes: S40a. Before inputting the fused feature set into the LSTM neural network model, perform time step alignment and dimension verification on the input sequence; S40b: During LSTM model inference, the activation distribution of each hidden state is recorded in real time, and a gradient pruning mechanism is dynamically enabled based on a preset gradient magnitude threshold. like ,but: ; in, Indicates model loss For parameters The gradient; This is the preset upper limit of the gradient norm; S40c. After residual correction and before rationality verification, a confidence interval filtering mechanism based on the historical traffic variation coefficient of the road segment is introduced. If the corrected predicted value... Exceeding For intervals, the original predicted values are used as the final output; where, This represents the standard deviation of historical traffic flow for this road segment during the same time period. The confidence factor.
7. The LSTM-based temporal prediction and analysis method for highway traffic flow according to claim 5, characterized in that, Step S5 includes: S51. After each prediction period ends, collect the actual traffic flow of the target road segment during the corresponding time period. and the final predicted value output from step S4. The mean absolute percentage error (MAPE) is calculated as a performance evaluation metric for the model. The formula is as follows: ; in, To prevent the smoothing constant from having a denominator of zero, if the smoothing constant is for three consecutive periods... Exceeding the preset threshold This triggers the dynamic adjustment mechanism for model parameters; S52. Adaptively adjust key hyperparameters of the LSTM model based on error feedback: If the error is concentrated in short-term predictions, increase the number of units in the first LSTM layer to 192 and reduce the learning rate; if the error is concentrated in long-term predictions, increase the memory capacity of the third LSTM layer and adjust the dropout rate p to 0.2; simultaneously, update the learning rate using an exponential moving average method. Its update rules are as follows: ; in, The initial learning rate, ; As the attenuation factor, ; Indicates the number of prediction periods required to perform one decay prediction; S53. Construct an incremental training sample set using the newly added measured data. ,in (i.e., data from the most recent 24 hours), while retaining the original model weights, the LSTM network is fine-tuned with a smaller batch size B=16 and a limited number of training epochs E=3, without re-initializing any layers, and the updated model parameters are written into the road segment-specific model version library to achieve continuous online learning and performance optimization for the target road segment.
8. A time-series traffic flow prediction and analysis system for highways based on LSTM, characterized in that, include: The high-speed data acquisition module is used to collect traffic flow time-series parameters of the target highway segment; Traffic flow time series parameters include traffic flow parameters, environmental disturbance data, traffic event data, and time characteristic data; The data preprocessing module is used to preprocess the traffic flow time-series parameters collected in step S1; The feature extraction module is used to extract and fuse temporal features, spatiotemporal correlation features and interference features from the preprocessed data to form a fused feature set; The traffic flow prediction module is used to input the fused feature set into a pre-trained neural network model containing several layers of LSTM units and Dropout layers to predict traffic flow, and to perform residual correction and rationality verification on the prediction results. The model adjustment module is used to dynamically adjust the parameters of the neural network model and perform incremental training based on the error between the actual traffic flow data and the prediction results.
9. A terminal, characterized in that, include: processor; Memory used to store the processor's execution instructions; The processor is configured to perform the method of any one of claims 1-7.
10. A computer-readable storage medium storing a computer program, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-7.