Traffic flow state accident potential prediction method and system based on dynamic weight matrix
By constructing a dynamic weight matrix and a multimodal feature fusion method, the problems of fixed weights, insufficient multimodal data fusion, and poor sample adaptability in existing traffic accident prediction models are solved, and efficient prediction and real-time early warning of traffic flow status are achieved.
Patent Information
- Application Number
- CN202511298329.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-11
- Publication Date
- 2025-11-14
AI Technical Summary
Existing traffic accident prediction models lack the ability to model behavioral sequences and cannot effectively integrate traffic flow characteristics and driving behavior data, resulting in delayed risk warnings and sensitivity to sample imbalance issues.
By constructing a dynamic weight matrix, combining the XGBoost model and attention mechanism to calculate the weights of static features and dynamic behaviors, using a Transformer encoder for feature fusion, and using FocalLoss with dynamic sample weights for model training, a unified modeling of static environment and dynamic behavior is achieved.
It improves the accuracy and real-time performance of traffic accident hazard prediction, reduces reliance on scarce accident samples, and enhances the stability of model training and the timeliness of early warning.
Smart Images

Figure CN120954232A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent transportation and road safety technology, specifically to a method and system for predicting traffic flow state accident hazards using a dynamic weight matrix. Background Technology
[0002] Currently, with the widespread adoption of intelligent sensing devices, a wealth of structured data has accumulated in the road traffic environment, encompassing traffic flow monitoring data, vehicle trajectory data, and driver behavior data. How to efficiently utilize this multi-source data to achieve road risk prediction has become a crucial technical issue in traffic safety management. Traditional traffic accident prediction models are mostly based on static or discontinuous traffic flow characteristics such as vehicle speed, flow rate, and density, employing methods like logistic regression, support vector machines, and XGBoost to construct static classification models. However, these models have significant limitations: First, they lack the ability to model behavioral sequences, making it difficult to capture the temporal evolution of abnormal driving behaviors such as "rapid acceleration, rapid deceleration, and sharp turns" before an accident. Second, they cannot effectively integrate different modalities of data, such as traffic flow characteristics and driving behavior, making it difficult to achieve unified modeling of static environmental states and dynamic behavioral processes. Third, they are sensitive to sample imbalance; the scarcity of accident samples leads to unstable model training, affecting prediction performance. Furthermore, existing system architectures typically separate static feature analysis from dynamic behavior recognition, resulting in a lag in risk warnings. Summary of the Invention
[0003] To address the shortcomings of existing technologies, this invention provides a method and system for predicting traffic flow state accident hazards using a dynamic weight matrix, which solves the problems of fixed weights, insufficient multimodal data fusion, and poor sample adaptability in traditional accident hazard prediction models compared to existing technologies.
[0004] To achieve the above objectives, the present invention provides the following technical solution: a method for predicting traffic flow state accident hazards using a dynamic weight matrix, comprising the following steps:
[0005] S1. Data Acquisition and Feature Extraction: Multimodal traffic data is acquired from roadside sensor data and vehicle trajectory data, and static traffic flow features and dynamic driving behavior sequences are extracted from them; the static traffic flow features constitute a static feature vector, and the dynamic driving behavior sequence is a temporal set of driving behavior events within a preset time window;
[0006] S2. Constructing a dynamic weight matrix: Based on real-time traffic conditions, construct a dynamic weight matrix for adaptively fusing the static traffic flow features and the dynamic driving behavior sequence. The construction process of the dynamic weight matrix includes:
[0007] S21. Calculate static feature weights: Input the static feature vector into a pre-trained static risk prediction model to obtain a static accident prior probability, and determine the static feature weights based on the static accident prior probability.
[0008] S22. Calculate dynamic behavior weights: Use an attention mechanism to process each time step in the dynamic driving behavior sequence and calculate the dynamic behavior weights corresponding to each time step.
[0009] S3. Multimodal Feature Fusion and Prediction: Based on the dynamic weight matrix, multimodal features are weighted and fused, and the fused features are input into the accident hazard prediction network to output the accident hazard probability. The multimodal feature fusion process includes:
[0010] S31. The static feature vector is weighted using the static feature weights to obtain weighted static features;
[0011] S32. The dynamic driving behavior sequence processed by the Transformer encoder is weighted using the dynamic behavior weights to obtain weighted dynamic behavior features.
[0012] S33. The weighted static features and the weighted dynamic behavioral features are concatenated to form the final fused feature vector, which is then input into the accident hazard prediction network.
[0013] S4. Model Training and Result Output: The accident hazard prediction network is trained and optimized using a preset loss function, and an early warning judgment is made based on the output accident hazard probability. When the accident hazard probability exceeds a preset threshold, an early warning signal is triggered.
[0014] Furthermore, the static traffic flow characteristics in step S1 include: the average speed of vehicles upstream and downstream of the target road segment, the speed variation coefficient, the traffic congestion index, the number of lanes, and meteorological factors.
[0015] Furthermore, the dynamic driving behavior sequence in step S1 consists of multiple driving behavior vectors, where each driving behavior vector is a six-dimensional vector, defined as follows:
[0016] ,
[0017] in, This represents the relative time difference between the current action and the previous action. The duration of the current action, Encode the type of the current behavior. The maximum speed during the current action. The maximum acceleration during the current action. This represents the total number of actions up to the current time step.
[0018] Furthermore, the static risk prediction model in step S21 is an XGBoost model; the calculation formula for the static feature weights is:
[0019] ,
[0020] in, For static feature weights, The static prior probability of the accident is output by the XGBoost model. This represents the average risk probability of a dynamic behavior sequence obtained based on historical data statistics.
[0021] Furthermore, the formula for calculating the dynamic behavior weight in step S22 is as follows:
[0022] ,
[0023] in, For the first Dynamic behavior weights at each time step For the first The behavior vector at each time step The risk score is calculated based on the behavior vector. For learnable parameters, This represents the maximum length of the behavior sequence.
[0024] Furthermore, the accident hazard prediction network in step S3 is a fully connected neural network, which outputs the probability of the accident hazard after processing by an activation function.
[0025] Furthermore, the loss function used in step S4 is label-smoothed FocalLoss with dynamic sample weights, and its calculation formula is as follows:
[0026] ,
[0027] in, The loss value. The total number of samples, For the first The dynamic weights of each sample The model predicts the first The probability of hidden danger in a sample. To focus parameters, These are the actual labels after label smoothing.
[0028] This invention also provides a traffic flow state accident hazard prediction system based on a dynamic weight matrix, applied to the traffic flow state accident hazard prediction method based on a dynamic weight matrix described above, comprising:
[0029] The data acquisition module is used to acquire real-time static traffic flow data and dynamic driving behavior data from roadside sensors and on-board equipment;
[0030] The dynamic weight calculation module is connected to the data acquisition module and is used to receive the static traffic flow data and dynamic driving behavior data, and execute step S2 to construct a dynamic weight matrix.
[0031] The fusion prediction module, connected to the dynamic weight calculation module, is used to receive the static traffic flow features, dynamic driving behavior sequence and dynamic weight matrix, and execute step S3 to output the probability of accident hazards.
[0032] The early warning output module, connected to the fusion prediction module, is used to receive the probability of the accident hazard, and generate and output early warning information when the probability exceeds a preset threshold.
[0033] Furthermore, the dynamic weight calculation module deploys an XGBoost model and an attention mechanism calculation unit; the XGBoost model is used to generate static accident prior probabilities based on static traffic flow features to determine static feature weights; the attention mechanism calculation unit is used to process dynamic driving behavior sequences to determine dynamic behavior weights.
[0034] Furthermore, the fusion prediction module deploys a Transformer encoder and a fully connected neural network; the Transformer encoder is used to encode the dynamic driving behavior sequence; the fully connected neural network is used to receive the fused feature vector and output the final probability of accident hazards.
[0035] Beneficial effects
[0036] This invention accurately captures the temporal evolution patterns of abnormal behaviors such as "rapid acceleration and rapid deceleration" through temporal analysis of dynamic driving behavior sequences and a Transformer encoder. Relying on a dynamic weight matrix, it combines an XGBoost model and an attention mechanism to calculate the weights of static features and dynamic behaviors respectively, achieving efficient unified modeling of static traffic environments and dynamic driving behaviors. The use of label-smoothed FocalLoss with dynamic sample weights effectively enhances model training stability and reduces dependence on scarce accident samples. The collaborative operation of all system modules avoids the lag in separate processing of static and dynamic features, significantly improving the accuracy and real-time performance of accident hazard prediction, and providing more reliable technical support for traffic safety management. Attached Figure Description
[0037] Figure 1 This is a flowchart of the method of the present invention;
[0038] Figure 2 This is a system structure diagram of the present invention.
[0039] In the picture:
[0040] 101. Data acquisition module; 102. Dynamic weight calculation module; 103. Fusion prediction module; 104. Early warning output module. Detailed Implementation
[0041] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0042] Please see Figure 1This invention provides a method for predicting traffic flow state accident hazards using a dynamic weight matrix, comprising the following steps: Data acquisition and feature extraction: acquiring multimodal traffic data from roadside sensor data and vehicle trajectory data, and extracting static traffic flow features and dynamic driving behavior sequences from them. The static traffic flow features constitute a static feature vector, and the dynamic driving behavior sequence is a time series set of driving behavior events within a preset time window; Constructing a dynamic weight matrix: based on real-time traffic conditions, constructing a dynamic weight matrix for adaptively fusing static traffic flow features and dynamic driving behavior sequences. The construction process of the dynamic weight matrix includes: Calculating static feature weights: inputting the static feature vector into a pre-trained static risk prediction model to obtain a static accident prior probability, and determining the static feature weights based on this static accident prior probability; Calculating dynamic behavior weights: using an attention mechanism to calculate the dynamic behavior weights for each time step in the dynamic driving behavior sequence. The process involves several steps: First, dynamic behavior weights are calculated for each time step. Second, multimodal feature fusion and prediction are performed. Multimodal features are weighted and fused based on the dynamic weight matrix, and the fused features are input into the accident hazard prediction network to output the accident hazard probability. The multimodal feature fusion process includes: weighting the static feature vector using static feature weights to obtain weighted static features; weighting the dynamic driving behavior sequence processed by the Transformer encoder using dynamic behavior weights to obtain weighted dynamic behavior features; concatenating the weighted static features and weighted dynamic behavior features to form the final fused feature vector, which is then input into the accident hazard prediction network. Third, model training and result output are conducted. The accident hazard prediction network is trained and optimized using a preset loss function, and a warning judgment is made based on the output accident hazard probability. When the accident hazard probability exceeds a preset threshold, a warning signal is triggered.
[0043] The data acquisition and feature extraction process involves collecting multimodal traffic data from roadside sensor data and vehicle trajectory data, and separating static traffic flow features and dynamic driving behavior sequences. Specifically, raw data can be collected using roadside cameras, geomagnetic sensors, and vehicle-mounted GPS devices. Dynamic behavior sequences are extracted using a sliding time window, and static feature vectors are extracted using statistical methods. This step addresses the problem of traditional methods relying on a single static feature, enabling the simultaneous capture of traffic environment states and driving behavior time-series patterns. The dynamic weight matrix, generated based on real-time traffic conditions, adaptively adjusts the fusion ratio of static features and dynamic behavior sequences. Static weights are calculated using a pre-trained model, and dynamic weights are calculated using an attention mechanism. This feature overcomes the limitation of traditional methods in effectively fusing multimodal data, achieving unified modeling of static environment and dynamic behavior. Multimodal feature fusion and prediction involves concatenating weighted static features and dynamic behavior features into a fusion vector, which is then input into a prediction network to output hazard probabilities. Fully connected neural networks can be used to process the fusion features. This step adjusts the contribution of different modal features through dynamic weights, improving the model's sensitivity to accident hazards. The model training and output process involves optimizing the prediction network using a loss function with dynamic sample weights and triggering early warnings based on probability thresholds. Specifically, label smoothing (FocalLoss) can be used to alleviate sample imbalance. This feature reduces the model's dependence on scarce accident samples and enhances training stability.
[0044] The core innovation of this application lies in achieving adaptive fusion of static traffic flow features and dynamic driving behavior sequences through a dynamic weight matrix. By combining a pre-trained model and an attention mechanism, the weights of the two types of features are calculated separately. Multimodal feature fusion is used to capture the synergistic influence of traffic environment state and driving behavior temporal patterns. At the same time, a dynamic sample weight loss function is introduced to alleviate the data imbalance problem, thereby improving the accuracy and robustness of accident hazard prediction.
[0045] The working process and principle of this application are as follows: First, multimodal traffic data is obtained from roadside sensor data and vehicle trajectory data, and static traffic flow features and dynamic driving behavior sequences are extracted. The static traffic flow features constitute a static feature vector, and the dynamic driving behavior sequence is a temporal set of driving behavior events within a preset time window.
[0046] Next, a dynamic weight matrix is constructed to adaptively fuse static features and dynamic sequences. Specifically, the static feature vector is input into a pre-trained static risk prediction model to obtain the static accident prior probability, which is then used to determine the static feature weights. Simultaneously, an attention mechanism is used to process each time step of the dynamic driving behavior sequence, and the dynamic behavior weights for each time step are calculated.
[0047] Then, the multimodal features are weighted and fused based on the dynamic weight matrix. Static feature vectors are weighted using static feature weights to obtain weighted static features. Dynamic behavior sequences processed by the Transformer encoder are weighted using dynamic behavior weights to obtain weighted dynamic behavior features. The weighted static features and weighted dynamic behavior features are concatenated to form a fused feature vector, which is then input into the accident hazard prediction network.
[0048] Finally, the accident hazard prediction network is trained and optimized using a preset loss function, and early warning judgments are made based on the output accident hazard probabilities. When the accident hazard probability exceeds a preset threshold, an early warning signal is triggered.
[0049] This approach achieves adaptive fusion of static features and dynamic sequences through a dynamic weight matrix, overcoming the limitations of fixed weight allocation. The Transformer encoder effectively captures the temporal correlation of driving behavior sequences, while the attention mechanism extracts information from key time steps. The pre-defined loss function helps alleviate the sample imbalance problem and improves the model's sensitivity to minority class samples.
[0050] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0051] In the data acquisition and feature extraction steps, static traffic flow data such as vehicle speed and flow rate are obtained from roadside sensors, while dynamic driving behavior data such as acceleration and steering angle are obtained from onboard equipment. Static feature vectors include mean vehicle speed, speed variation coefficient, and traffic congestion index. Dynamic driving behavior sequences consist of multiple six-dimensional vectors, each containing information such as behavior type, duration, maximum speed, and maximum acceleration.
[0052] In the step of constructing the dynamic weight matrix, the XGBoost model is used as the static risk prediction model. The static feature vector is input into the XGBoost model to obtain the static prior probability of the accident. The static feature weight is calculated as the ratio of the static prior probability of the accident to the historical average risk probability. For the dynamic behavior sequence, a multi-head attention mechanism is used to calculate the importance score at each time step, and the dynamic behavior weight is obtained by normalization using the softmax function.
[0053] In the multimodal feature fusion and prediction step, firstly, element-wise multiplication of the static feature vector is performed using static feature weights to obtain weighted static features. Then, the dynamic driving behavior sequence is input into a Transformer encoder to obtain the encoded sequence representation. The encoded sequence is then weighted and summed using dynamic behavior weights to obtain weighted dynamic behavior features. The weighted static features and weighted dynamic behavior features are concatenated along the feature dimension to form a fused feature vector. Finally, the fused feature vector is input into an accident hazard prediction network composed of multiple fully connected layers, and the sigmoid activation function outputs the probability of the accident hazard.
[0054] In the model training and result output steps, a label-smoothed FocalLoss loss function with dynamic sample weights is used. The dynamic sample weights are adaptively adjusted according to the difficulty of the samples. The Adam optimizer is used to update the model parameters. During the testing phase, an early warning signal is triggered when the output probability of accident hazards exceeds 0.7.
[0055] This application further proposes static traffic flow characteristics including the average speed of vehicles upstream and downstream of the target road segment, the speed variation coefficient, the traffic congestion index, the number of lanes, and meteorological factors.
[0056] Among these features, the average speed of vehicles upstream and downstream is calculated to reflect the overall traffic flow speed; the speed variation coefficient is the ratio of the standard deviation to the mean, quantifying the degree of speed fluctuation; the traffic congestion index is generated based on the comparison of historical and real-time traffic flow, used to assess the congestion level; the number of lanes is obtained from road topology data, characterizing road capacity; and meteorological factors integrate temperature, humidity, and visibility data to reflect the impact of the environment on traffic flow. These features construct a static feature vector through multi-dimensional parameters, covering the spatial distribution, temporal fluctuations, road structure, and environmental factors of traffic flow status.
[0057] Specifically, the average vehicle speed upstream and downstream is calculated by collecting speed data from upstream and downstream monitoring points using roadside sensors, and then calculating the arithmetic mean. The speed variation coefficient is obtained by dividing the standard deviation of the real-time speed series by the mean, resulting in a dimensionless index. The traffic congestion index is normalized based on the ratio of real-time traffic flow to historical peak traffic flow, combined with road segment length and number of lanes. The number of lanes is directly extracted from the lane attributes in the road design data. Meteorological factors are obtained from raw data on temperature, humidity, and visibility obtained from roadside weather stations, and then standardized to form a multi-dimensional vector. These features are extracted simultaneously during the data preprocessing stage, collectively forming a static feature vector, which is then input into the subsequent model for weight calculation and fusion. By synergistically improving the traffic state representation capability through multi-dimensional parameters, the accuracy of accident hazard prediction is enhanced.
[0058] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0059] Static traffic flow characteristics include the average speed of vehicles upstream and downstream of the target road segment, the coefficient of variation of speed, the traffic congestion index, the number of lanes, and meteorological factors. The average speed of vehicles upstream and downstream is collected by roadside radar speed measurement equipment; the coefficient of variation of speed is calculated by dividing the standard deviation of speed by the average speed; the traffic congestion index is based on a comprehensive assessment of vehicle density and average driving speed; the number of lanes is obtained from electronic map data; and meteorological factors, including visibility, precipitation, and wind speed, are collected in real time by weather stations.
[0060] Furthermore, the average speed of upstream and downstream vehicles is the average value within a 5-minute sliding time window, the speed variation coefficient reflects the dispersion of vehicle speed distribution, the traffic congestion index is represented by a standardized value of 0-10, the number of lanes includes the total number of main lanes and auxiliary lanes, the visibility of meteorological factors is in meters, precipitation is in millimeters per hour, and wind speed is in meters per second.
[0061] Therefore, by comprehensively considering these static traffic flow characteristics, the traffic operation status and environmental conditions of the target road segment can be fully reflected, providing important static feature inputs for subsequent accident hazard prediction.
[0062] This application further proposes that the dynamic driving behavior sequence consists of multiple driving behavior vectors, each of which is a six-dimensional vector, defined as follows:
[0063] ,in, This represents the relative time difference between the current action and the previous action. The duration of the current action, Encode the type of the current behavior. The maximum speed during the current action. The maximum acceleration during the current action. This represents the total number of actions up to the current time step.
[0064] Among them, relative time difference The time interval distribution used to characterize adjacent actions; duration dt reflects the duration of the continuous impact of a single action; type encoding. By using numerical mapping, behavior categories such as acceleration, deceleration, and turning are distinguished, and maximum speed is achieved. and maximum acceleration The extreme values of the intensity of quantified behavior, the total number of behaviors. Provides sequence length context. The six-dimensional vector, through multi-dimensional parameter combinations, covers the time, category, intensity, and contextual information of the behavior, forming a complete description of a single driving action. For example, type encoding. When using one-hot encoding, it can be expanded into a multi-dimensional vector containing subcategories such as rapid acceleration, rapid deceleration, and sharp turns, further refining the behavior classification.
[0065] Specifically, the dynamic driving behavior sequence is constructed using a six-dimensional vector, enabling simultaneous recording of the temporal evolution and intensity changes of the behavior. During model processing, the relative time difference... The duration dt provides the basis for calculating the time dimension weights of the attention mechanism, and the type encoding is used. Guided model identifies high-risk behavior categories at maximum speed and maximum acceleration As a quantitative indicator, it complements the mean speed and coefficient of variation in static traffic flow characteristics, jointly assessing behavioral risks. The total number of behaviors, nt, serves as a sequence length parameter, assisting the model in determining the position and weight of the current time step within the overall sequence. Through the fusion of multidimensional parameters from a six-dimensional vector, the model can accurately distinguish between short-term, sharp acceleration and long-term stable driving behaviors. Combined with the adaptive weighting mechanism of the dynamic weight matrix in the preceding claim, it enhances the ability to capture temporal patterns of abnormal driving behaviors, thereby improving the accuracy and robustness of accident hazard prediction.
[0066] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0067] The dynamic driving behavior sequence consists of multiple driving behavior vectors. Each driving behavior vector is a six-dimensional vector, defined as: ,in, The relative time difference between the current action and the previous action, in seconds; The duration of the current action, in seconds; Encode the type of the current behavior using integer encoding, such as 0 for normal driving, 1 for acceleration, 2 for deceleration, and 3 for lane changing; The maximum speed during the current action, expressed in meters per second; The maximum acceleration during the current action, expressed in meters per second². This represents the total number of actions up to the current time step, and is an integer value.
[0068] For example, a 10-second sequence of driving behavior might contain three consecutive behavior vectors: S_1=[0,3,0,15,0.5,1], S_2=[3,4,1,20,1.2,2], S_3=[7,3,2,18,-0.8,3]
[0069] This means: the first action is normal driving for 3 seconds, with a maximum speed of 15 m / s and a maximum acceleration of 0.5 m / s²; the second action is acceleration for 4 seconds, with a maximum speed of 20 m / s and a maximum acceleration of 1.2 m / s²; and the third action is deceleration for 3 seconds, with a maximum speed of 18 m / s and a maximum deceleration of 0.8 m / s².
[0070] This application further proposes that the static risk prediction model is the XGBoost model; the formula for calculating the static feature weights is: ,in, For static feature weights, The static prior probability of an accident is output by the XGBoost model. This represents the average risk probability of a dynamic behavior sequence obtained based on historical data statistics.
[0071] The XGBoost model learns the nonlinear relationship between static traffic flow features and accident hazards through a pre-training process, outputting the static accident prior probability as a quantitative indicator of the importance of static features. The average risk probability of dynamic behavior sequences is calculated from the average risk score of dynamic behavior sequences in historical accident data, reflecting the overall risk level of dynamic behavior. The formula for calculating static feature weights normalizes the static prior probability and the dynamic average risk probability, achieving a dynamic balance between static and dynamic risk information.
[0072] Specifically, when predicting static feature vectors, the XGBoost model utilizes its ensemble learning capability to capture the interaction relationships between multi-dimensional features such as mean vehicle speed and speed variation coefficient, outputting probability values to characterize potential risks in the current static environment. The average risk probability of the dynamic behavior sequence is introduced as a denominator in the calculation. When the average risk of dynamic behavior is high, the weight of static features is suppressed, preventing static features from dominating the fusion process. For example, when frequent rapid acceleration or deceleration occurs in a dynamic behavior sequence, the average risk probability of the dynamic behavior increases, and the weight of static traffic flow features automatically decreases, making the model focus more on the real-time risk of dynamic behavior. Through this formula, the static feature weights can adaptively adjust according to changes in dynamic behavior risk, improving the rationality of multi-modal feature fusion and thus optimizing the accuracy of accident hazard prediction.
[0073] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0074] In the calculation of static feature weights, the static feature vector is first input into a pre-trained XGBoost model. This XGBoost model is trained using historical traffic data and can predict the prior probability of static accidents based on the input static traffic flow features.
[0075] Specifically, the input features of the XGBoost model include the average vehicle speeds upstream and downstream of the target road segment, the coefficient of variation of speed, the traffic congestion index, the number of lanes, and meteorological factors. The model outputs a probability value between 0 and 1, representing the probability of an accident occurring based on the static features.
[0076] Furthermore, the formula for calculating the static feature weights is: ,
[0077] in, For static feature weights, This represents the static prior probability of an accident output by the XGBoost model. This represents the average risk probability of a dynamic behavior sequence obtained based on historical data statistics.
[0078] Therefore, static feature weights The value range is between 0 and 1. When A larger value indicates that static characteristics contribute significantly to accident risk. Increase accordingly; conversely, when When smaller, The corresponding weights are reduced. This adaptive weight allocation mechanism can dynamically adjust the fusion ratio of static features and dynamic behavioral features according to real-time traffic conditions.
[0079] This application further proposes the following formula for calculating dynamic behavior weights: ,in, For the first Dynamic behavior weights at each time step For the first The behavior vector at each time step The risk score is calculated based on the behavior vector. For learnable parameters, This represents the maximum length of the behavior sequence.
[0080] The risk scoring function quantifies the risk level of a single time step by analyzing the time difference, duration, type encoding, maximum speed, maximum acceleration, and total number of behaviors in the behavior vector; the learnable parameters are optimized through backpropagation to adaptively adjust the influence of risk scores at different time steps on the final weight; and the normalization process constrains the weights to the probability distribution range through exponential and summation operations.
[0081] Specifically, after the behavior vector is input, a risk score is first calculated based on its six-dimensional features, reflecting the potential risk level at that time step. Then, learnable parameters are introduced to non-linearly transform the risk score, enhancing the model's ability to distinguish different behavior patterns. Finally, the transformed values are normalized into weights using a softmax function, giving higher weights to high-risk time steps. For example, when a time step contains rapid acceleration, its risk score increases, and the learnable parameters further amplify this score. Ultimately, normalization makes the weight of this time step significantly higher than other time steps. This process allows the model to focus on high-risk driving behavior segments, improving the sensitivity and accuracy of hazard probability prediction.
[0082] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0083] The formula for calculating dynamic behavior weights is: t from 1 to T
[0084] in, For the first Dynamic behavior weights at each time step For the first The behavior vector at each time step The risk score is calculated based on the behavior vector. For learnable parameters, This represents the maximum length of the behavior sequence.
[0085] Specifically, behavior vectors It contains six elements: relative time difference, duration, behavior type encoding, maximum speed, maximum acceleration, and cumulative number of behaviors. Risk score. It is calculated through a pre-trained scoring model that takes the behavior vector as input and outputs a risk score between 0 and 1. It is a learnable attention parameter used to adjust the importance of different time steps. It is usually set to 30, which means considering the behavior sequence of the most recent 30 time steps.
[0086] In practical applications, the input behavior sequence is first encoded to obtain T behavior vectors. Then, each behavior vector is input into the scoring model to obtain the corresponding risk score. Next, the softmax function is used to calculate the weight at each time step, where the exponent term consists of the product of the risk score and the attention parameter. Finally, the T weights are normalized to obtain the final dynamic behavior weight sequence.
[0087] This application further proposes that the accident hazard prediction network is a fully connected neural network, which outputs the probability of accident hazards after being processed by an activation function.
[0088] The fully connected neural network contains multiple hidden layers, with activation functions such as Sigmoid, ReLU, or Tanh. The hidden layers alternately process input features through linear transformations and non-linear activations. The output layer maps the results to the 0-1 range using the Sigmoid function, forming a probability output. The fused feature vector, weighted by a dynamic weight matrix, serves as input and is passed layer by layer through the fully connected layers. The activation functions introduce non-linear expressive power, enhancing the model's ability to fit complex relationships.
[0089] Specifically, after fusing feature vectors into a fully connected neural network, the first hidden unit linearly combines the features and applies ReLU activation to suppress the vanishing gradient problem. Subsequent hidden layers further extract higher-order nonlinear features, and the output layer converts the final score into a probability value using the Sigmoid function. The choice of activation function, in conjunction with network depth, enables the model to effectively learn key risk patterns in the weighted fused features. Simultaneously, the output probability is combined with label smoothing FocalLoss with dynamic sample weights to mitigate training bias caused by sample imbalance.
[0090] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0091] The accident hazard prediction network is a fully connected neural network that outputs the probability of an accident hazard after processing by an activation function. Specifically, this fully connected neural network contains three hidden layers, each containing 64, 32, and 16 neurons respectively. The input layer receives the fused feature vector with a dimension of 128. The hidden layers use the ReLU activation function, and the output layer uses the Sigmoid activation function to map the result to the range of 0 to 1, representing the probability of the accident hazard. The network structure can be represented as: Input(128)-_FC(64)-_ReLU-_FC(32)-_ReLU-_FC(16)-_ReLU-_FC(1)-_Sigmoid. Here, FC represents a fully connected layer. The network parameters are optimized using the backpropagation algorithm with the Adam optimizer and a learning rate of 0.001. To prevent overfitting, a Dropout layer is added after each hidden layer with a dropout rate of 0.5.
[0092] This application further proposes using label-smoothed FocalLoss with dynamic sample weights as the loss function, and its calculation formula is as follows: Where L is the loss value, The total number of samples, For the first The dynamic weights of each sample The model predicts the first The probability of hidden danger in a sample. To focus parameters, These are the actual labels after label smoothing.
[0093] Among them, dynamic sample weights By dynamically adjusting based on real-time traffic conditions and historical risk probabilities, the model assigns differentiated weights to samples with different risk levels during training; label smoothing converts the original binary labels into continuous values. This reduces the interference of noisy labels on model training; the focusing parameter γ reduces the loss contribution of easily classified samples through exponential decay, forcing the model to focus on learning difficult-to-classify samples. These three features are coupled through a product to form a composite loss function.
[0094] Specifically, during the training process, the loss calculation for each sample is divided into three stages: First, dynamic sample weights are generated based on the static feature weights and dynamic behavior weights of the sample. This is used to reflect the importance of the sample in the overall data distribution; secondly, the true labels are smoothed to reflect the original labels. Convert to ,in For smoothing coefficients, To uniformly distribute the noise, thereby mitigating the model's overfitting to the noise labels; finally, through... The term applies a non-linear scaling to the predicted probability, when the sample is correctly classified and As the value approaches 1, this term approaches 0, automatically reducing the loss contribution of that sample. Through the combined effect of these three factors, this loss function can enhance the model's ability to identify high-risk samples under imbalanced conditions, while suppressing overlearning of non-accident samples and improving prediction stability.
[0095] As a preferred embodiment, the solution of this application is specifically implemented as follows:
[0096] During model training, label-smoothed FocalLoss with dynamic sample weights is used as the loss function. The formula for calculating this loss function is:
[0097]
[0098] in, The loss value. The total number of samples, For the first The dynamic weights of each sample The model predicts the first The probability of hidden danger in a sample. To focus parameters, These are the actual labels after label smoothing.
[0099] In practice, dynamic weights are first assigned to each training sample. For positive samples (i.e., samples where an accident occurred), It can be set to 1.5; for negative samples (i.e., samples where no incident occurred). It can be set to 1.0. This weighting method helps to balance the contributions of positive and negative samples.
[0100] Next, label smoothing is performed. The original binary label y (0 indicates no incident, 1 indicates an incident) is converted into a smoothed label. For example, the original label 0 can be converted to 0.01, and the original label 1 can be converted to 0.99. This processing can reduce the model's sensitivity to label noise.
[0101] Next, set the focus parameter γ. In this embodiment, γ can be set to 2.0. This parameter is used to adjust the model's focus on easily classified and difficult-to-classify samples.
[0102] Finally, the loss value L is calculated according to the above formula, and this loss value is used to guide the backpropagation and parameter updates of the model. In each training batch, the average loss of the samples in that batch is calculated, and the model parameters are updated accordingly.
[0103] Please see Figure 2 This application further proposes a traffic flow state accident hazard prediction system based on a dynamic weight matrix, including a data acquisition module 101, a dynamic weight calculation module 102, a fusion prediction module 103, and an early warning output module 104.
[0104] Among them, the data acquisition module 101 captures static traffic flow data and dynamic driving behavior data in real time through roadside sensors and vehicle-mounted equipment. The static traffic flow data includes the average speed of upstream and downstream vehicles, speed variation coefficient, number of lanes and meteorological factors. The dynamic driving behavior data consists of a six-dimensional vector, including time difference, duration, behavior type code, maximum speed, maximum acceleration and total number of behaviors.
[0105] The dynamic weight calculation module 102 incorporates an XGBoost model and an attention mechanism calculation unit. The XGBoost model generates static accident prior probabilities based on static feature vectors to determine static feature weights. The attention mechanism calculation unit performs risk scoring on dynamic behavior sequences through learnable parameters to generate dynamic behavior weights.
[0106] The fusion prediction module 103 includes a Transformer encoder and a fully connected neural network. The Transformer encoder performs temporal encoding on the dynamic behavior sequence, and the fully connected neural network receives the weighted fused feature vector and outputs the probability of potential hazards.
[0107] The warning output module 104 is set with a probability threshold of 0.85. When the probability exceeds the threshold, a warning signal is generated and pushed synchronously to the vehicle terminal via the roadside display screen.
[0108] Specifically, the data acquisition module 101 converts real-time acquired static traffic flow data into static feature vectors, while dynamic driving behavior data is segmented into behavior sequences according to time windows. In the dynamic weight calculation module 102, the XGBoost model processes the static feature vectors and outputs static feature weights, while the attention mechanism calculation unit calculates dynamic weights for the behavior vectors at each time step. The fusion prediction module 103 concatenates the weighted static features with the Transformer-encoded dynamic features to form a fused feature vector, which is then input into the fully connected network. The warning output module 104 monitors the probability value output by the fully connected network in real time, and triggers the warning signal generation logic when the probability value exceeds a preset threshold. This system achieves fully automated processing of data acquisition, weight calculation, feature fusion, and warning output through modular design. The cascaded structure of the dynamic weight calculation module 102 and the fusion prediction module 103 effectively improves the efficiency of multimodal data fusion, while the threshold judgment mechanism of the warning output module 104 ensures the real-time performance and accuracy of the warning signal.
[0109] As a preferred embodiment, the solution of this application is implemented as follows: The data acquisition module 101 collects static parameters such as average vehicle speed, lane occupancy, and traffic congestion index of the target road segment in real time through roadside lidar and on-board OBD equipment. Simultaneously, it acquires dynamic data on vehicle acceleration, deceleration, and sharp turns at a sampling period of 50 milliseconds. The dynamic weight calculation module 102 receives the above data, inputs the static parameters into the trained XGBoost model to generate a static weight coefficient of 0.35, and simultaneously encodes a continuous 20-second driving behavior sequence through a multi-head attention mechanism to generate normalized attention weights for each time step. The fusion prediction module 103 concatenates the weighted static feature vector with the dynamic behavior features encoded through 6 layers of Transformer to form a 768-dimensional fusion vector, which is then input into a fully connected network with 3 hidden layers to generate a hazard probability value of 0.68. The warning output module 104 sends a level-three warning signal to surrounding vehicles via the V2X communication protocol when the hazard probability exceeds the 0.65 threshold.
[0110] This application further proposes that the dynamic weight calculation module 102 deploys an XGBoost model and an attention mechanism calculation unit; the XGBoost model is used to generate static accident prior probabilities based on static traffic flow features to determine static feature weights; the attention mechanism calculation unit is used to process dynamic driving behavior sequences to determine dynamic behavior weights.
[0111] The XGBoost model performs nonlinear mapping on static traffic flow features through pre-training, outputting a priori probability of static accidents. This probability is combined with the average risk probability of dynamic behavior from historical statistics to generate static feature weights. The attention mechanism computation unit uses learnable parameters and a risk scoring function to weight the behavior vector at each time step in the dynamic driving behavior sequence. The dynamic behavior weights are calculated using a normalized exponential function. The Transformer encoder deployed within the fusion prediction module 103 performs temporal modeling of the dynamic driving behavior sequence. The fully connected neural network receives the fused feature vector and outputs the probability of accident hazards through an activation function.
[0112] Specifically, the XGBoost model receives static feature vectors such as the upstream average vehicle speed, speed variation coefficient, and traffic congestion index, calculates the static prior probability of an accident, and then superimposes this probability with the historical average risk of dynamic behavior to generate static feature weights. The attention mechanism computation unit performs risk scoring on each six-dimensional vector in the dynamic driving behavior sequence. The scoring results, combined with learnable parameters, are input into a normalized exponential function to obtain the weight distribution at each time step. The Transformer encoder performs position encoding and multi-head attention processing on the dynamic behavior sequence, extracting temporal dependencies. The weighted dynamic behavior features are concatenated with the weighted static features and input into a fully connected network. The network outputs the hazard probability through multi-layer linear transformations and non-linear activations. Thus, static feature weights and dynamic behavior weights are generated through independent models, achieving adaptive fusion of multimodal data and improving prediction accuracy.
[0113] As a preferred embodiment, the solution of this application is implemented as follows: The dynamic weight calculation module 102 includes an XGBoost model and an attention mechanism calculation unit. The XGBoost model is pre-trained using a historical traffic flow feature dataset. Its input layer receives static feature vectors, and its output layer generates static accident prior probabilities. Specifically, after the static feature vectors are input into the XGBoost model, the model calculates the feature splitting gain layer by layer using the gradient boosting tree algorithm, and finally outputs a probability value representing the static environmental risk. The attention mechanism calculation unit adopts a multi-head attention architecture, where the query vector of each attention head is generated from the hidden state of the dynamic behavior sequence, and the key vector is extracted from the original behavior vector through a linear transformation. When calculating the dynamic behavior weights, the behavior vector at each time step is normalized, and an attention score is generated through a learnable parameter matrix, which is then transformed into a weight distribution through a softmax function. The output results of the XGBoost model and the attention mechanism unit are transmitted to the fusion prediction module 103 through independent data channels.
[0114] This application further proposes that the fusion prediction module 103 is equipped with a Transformer encoder and a fully connected neural network; the Transformer encoder is used to encode the dynamic driving behavior sequence; the fully connected neural network is used to receive the fused feature vector and output the final accident hazard probability.
[0115] The Transformer encoder employs a multi-head attention mechanism to process dynamic driving behavior sequences in parallel. Each attention head focuses on potential correlation patterns between different time steps, and high-order temporal features are extracted step by step by stacking multiple encoding layers. The fully connected neural network contains three hidden layers, with 256, 128, and 64 neurons in each layer, respectively. It uses the ReLU activation function for non-linear transformation, and the output layer maps features to the probability range of 0-1 using the Sigmoid function.
[0116] Specifically, after the dynamic driving behavior sequence is input into the Transformer encoder, the absolute position information of each time step is first injected through a position encoding layer, followed by a self-attention calculation layer to capture the temporal correlation within the sequence. The encoded dynamic behavior features are concatenated with weighted static features to form a fused feature vector with a dimension of 512. The fully connected neural network performs layer-by-layer dimensionality reduction on the fused features, ultimately outputting the probability value of potential hazards. For example, during the encoding process, the behavior vector at each time step undergoes a linear transformation to generate a query vector, a key vector, and a value vector. Attention weights are calculated by scaling the dot product, achieving dynamic enhancement of features at key time steps. During the training phase, the fully connected network employs a random deactivation strategy with a Dropout ratio of 0.5 to prevent overfitting.
[0117] As a preferred embodiment, the solution of this application is implemented as follows: In the fusion prediction module 103, the Transformer encoder adopts a six-layer stacked structure, with each layer containing eight self-attention heads. The dynamic driving behavior sequence is first input to the Transformer encoder, and after being processed by position encoding and multi-head attention mechanism, the encoded dynamic behavior feature vector is output. The fully connected neural network consists of three hidden layers. The first hidden layer contains 256 neurons and uses the ReLU activation function, the second hidden layer contains 128 neurons and uses the LeakyReLU activation function, and the output layer uses the Sigmoid function. The encoded dynamic behavior feature vector is concatenated with the weighted static feature vector and then input to the fully connected neural network, finally outputting an accident hazard probability value in the range of 0 to 1.
[0118] In summary, this invention accurately captures the temporal evolution patterns of abnormal behaviors such as "rapid acceleration and deceleration" through temporal analysis of dynamic driving behavior sequences and a Transformer encoder. Relying on a dynamic weight matrix, it combines an XGBoost model and an attention mechanism to calculate the weights of static features and dynamic behaviors respectively, achieving efficient unified modeling of static traffic environments and dynamic driving behaviors. The use of label-smoothed FocalLoss with dynamic sample weights effectively enhances model training stability and reduces dependence on scarce accident samples. The collaborative operation of all system modules avoids the lag in separate processing of static and dynamic features, significantly improving the accuracy and real-time performance of accident hazard prediction, and providing more reliable technical support for traffic safety management.
[0119] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0120] Although embodiments of the invention have been shown and described, it will be understood by those skilled in the art that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the appended claims and their equivalents.
Claims
1. A method for predicting traffic flow state accident hazards using a dynamic weight matrix, characterized in that, Includes the following steps: S1. Data Acquisition and Feature Extraction: Multimodal traffic data is acquired from roadside sensor data and vehicle trajectory data, and static traffic flow features and dynamic driving behavior sequences are extracted from them; the static traffic flow features constitute a static feature vector, and the dynamic driving behavior sequence is a temporal set of driving behavior events within a preset time window; S2. Constructing a dynamic weight matrix: Based on real-time traffic conditions, construct a dynamic weight matrix for adaptively fusing the static traffic flow features and the dynamic driving behavior sequence. The construction process of the dynamic weight matrix includes: S21. Calculate static feature weights: Input the static feature vector into a pre-trained static risk prediction model to obtain a static accident prior probability, and determine the static feature weights based on the static accident prior probability. S22. Calculate dynamic behavior weights: Use an attention mechanism to process each time step in the dynamic driving behavior sequence and calculate the dynamic behavior weights corresponding to each time step. S3. Multimodal Feature Fusion and Prediction: Based on the dynamic weight matrix, multimodal features are weighted and fused, and the fused features are input into the accident hazard prediction network to output the accident hazard probability. The multimodal feature fusion process includes: S31. The static feature vector is weighted using the static feature weights to obtain weighted static features; S32. The dynamic driving behavior sequence processed by the Transformer encoder is weighted using the dynamic behavior weights to obtain weighted dynamic behavior features. S33. The weighted static features and the weighted dynamic behavioral features are concatenated to form the final fused feature vector, which is then input into the accident hazard prediction network. S4. Model Training and Result Output: The accident hazard prediction network is trained and optimized using a preset loss function, and an early warning judgment is made based on the output accident hazard probability. When the accident hazard probability exceeds a preset threshold, an early warning signal is triggered.
2. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The static traffic flow characteristics in step S1 include: the average speed of vehicles upstream and downstream of the target road segment, the speed variation coefficient, the traffic congestion index, the number of lanes, and meteorological factors.
3. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The dynamic driving behavior sequence in step S1 consists of multiple driving behavior vectors, where each driving behavior vector is a six-dimensional vector, defined as follows: , in, This represents the relative time difference between the current action and the previous action. The duration of the current action, Encode the type of the current behavior. The maximum speed during the current action. The maximum acceleration during the current action. This represents the total number of actions up to the current time step.
4. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The static risk prediction model in step S21 is the XGBoost model; the formula for calculating the static feature weights is: , in, For static feature weights, The static prior probability of the accident is output by the XGBoost model. This represents the average risk probability of a dynamic behavior sequence obtained based on historical data statistics.
5. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The formula for calculating the dynamic behavior weight in step S22 is as follows: , in, For the first Dynamic behavior weights at each time step For the first The behavior vector at each time step The risk score is calculated based on the behavior vector. For learnable parameters, This represents the maximum length of the behavior sequence.
6. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The accident hazard prediction network in step S3 is a fully connected neural network, which outputs the probability of the accident hazard after processing by an activation function.
7. The method for predicting traffic flow state accident hazards using a dynamic weight matrix according to claim 1, characterized in that, The loss function used in step S4 is label-smoothed FocalLoss with dynamic sample weights, and its calculation formula is as follows: , in, The loss value. The total number of samples, For the first The dynamic weights of each sample The model predicts the first The probability of hidden danger in a sample. To focus parameters, These are the actual labels after label smoothing.
8. A traffic flow state accident hazard prediction system based on a dynamic weight matrix, applied to the traffic flow state accident hazard prediction method based on a dynamic weight matrix as described in any one of claims 1-7, characterized in that, include: The data acquisition module (101) is used to acquire real-time static traffic flow data and dynamic driving behavior data from roadside sensors and vehicle-mounted equipment; The dynamic weight calculation module (102) is connected to the data acquisition module (101) and is used to receive the static traffic flow data and dynamic driving behavior data, and to execute step S2 as described in claim 1 to construct a dynamic weight matrix; The fusion prediction module (103) is connected to the dynamic weight calculation module (102) and is used to receive the static traffic flow features, dynamic driving behavior sequence and dynamic weight matrix, and execute step S3 as described in claim 1 to output the probability of accident hazards. The early warning output module (104) is connected to the fusion prediction module (103) and is used to receive the probability of the accident hazard. When the probability exceeds a preset threshold, it generates and outputs early warning information.
9. A traffic flow state accident hazard prediction system based on a dynamic weight matrix according to claim 8, characterized in that, The dynamic weight calculation module (102) deploys an XGBoost model and an attention mechanism calculation unit; the XGBoost model is used to generate static accident prior probabilities based on static traffic flow characteristics in order to determine static feature weights. The attention mechanism calculation unit is used to process dynamic driving behavior sequences to determine dynamic behavior weights.
10. A traffic flow state accident hazard prediction system based on a dynamic weight matrix according to claim 8, characterized in that, The fusion prediction module (103) is equipped with a Transformer encoder and a fully connected neural network. The Transformer encoder is used to encode the dynamic driving behavior sequence. The fully connected neural network is used to receive the fused feature vector and output the final probability of accident hazards.