Traffic flow prediction model training method and device, computer equipment and medium
By constructing the spatiotemporal characteristics of traffic flow data and combining attention mechanisms, the traffic flow prediction model is trained, and the problem of low prediction accuracy of existing models is solved and more efficient traffic flow prediction is achieved.
Patent Information
- Application Number
- CN202411722265.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-28
- Publication Date
- 2025-02-25
AI Technical Summary
Existing traffic flow prediction models are usually based on historical traffic flow data when modeling, and only consider temporal dynamic changes or spatial dependence, resulting in low prediction accuracy.
By obtaining the traffic flow data and traffic state impact data of the sample traffic section during the sample time period, building spatiotemporal characteristics, combining the timing attention gating cycle unit and the spatial attention map convolution network, the traffic flow prediction model is trained to improve prediction accuracy.
By considering the spatiotemporal characteristics of the traffic flow sequence, the trained traffic flow prediction model can significantly improve the prediction accuracy of traffic flow, exceeding the limitations of traditional models.
Smart Images

Figure CN119516786A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of intelligent transportation technology, and in particular to a traffic flow prediction model training method, device, computer equipment, computer-readable storage medium and computer program product. Background Art
[0002] With the development of intelligent transportation technology, a technology for predicting traffic flow has emerged. This technology can collect the historical traffic flow of a road section and then predict the traffic flow in the future time period by building a traffic flow prediction model.
[0003] In traditional technology, traffic flow prediction models are usually constructed by statistical models and machine learning models. Statistical models can include differential autoregressive moving average models and vector autoregressive models, while machine learning models can include long short-term memory network models trained by deep learning methods, gated recurrent unit network models, and graph convolutional network models.
[0004] However, the traffic flow prediction models currently constructed are usually only based on historical traffic flow, and the modeling process only considers the temporal dynamic changes of the traffic flow sequence or only considers the spatial dependency. Therefore, the traffic flow prediction accuracy of the constructed traffic flow prediction models is low. Summary of the invention
[0005] Based on this, it is necessary to provide a traffic flow prediction model training method, device, computer equipment, computer readable storage medium and computer program product that can improve the accuracy of traffic flow prediction in response to the above technical problems.
[0006] In a first aspect, the present application provides a traffic flow prediction model training method, comprising:
[0007] Acquire sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period, and obtain traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data;
[0008] Inputting the traffic flow sequence information into the traffic flow prediction model to be trained, obtaining the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtaining the time and space characteristics corresponding to the traffic flow sequence information in the sample time period according to the time characteristics and spatial characteristics;
[0009] Obtaining predicted traffic flow data of the sample traffic section at a predicted time according to the spatiotemporal characteristics;
[0010] The traffic flow prediction model is trained according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time to obtain a trained traffic flow prediction model.
[0011] In one embodiment, the traffic flow prediction model includes: a temporal attention gated recurrent unit, and a spatial attention graph convolutional network; the traffic flow sequence information is input into the traffic flow prediction model to be trained, and the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period are obtained through the traffic flow prediction model, and the spatiotemporal characteristics corresponding to the traffic flow sequence information in the sample time period are obtained according to the time characteristics and spatial characteristics, including: inputting the traffic flow sequence information into the temporal attention gated recurrent unit to obtain the time characteristics corresponding to the traffic flow sequence information in the sample time period; inputting the traffic flow sequence information and the section connection relationship characteristics corresponding to the sample traffic section into the spatial attention graph convolutional network to obtain the spatial characteristics corresponding to the traffic flow sequence information in the sample time period; and weighting the time characteristics and the spatial characteristics to obtain the spatiotemporal characteristics corresponding to the traffic flow sequence information in the sample time period.
[0012] In one of the embodiments, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different moments within the sample time period; the step of inputting the traffic flow sequence information into the temporal attention gated loop unit to obtain the time feature corresponding to the traffic flow sequence information includes: inputting the traffic flow sequence information into the temporal attention gated loop unit, and obtaining the time attention feature corresponding to the traffic flow sequence information through the time attention mechanism of the temporal attention gated loop unit; obtaining the current sub-traffic sequence information corresponding to the current moment, and the sub-time feature corresponding to the previous moment of the current moment; obtaining the sub-time feature of the current moment by using the current sub-traffic sequence information, the time attention feature and the sub-time feature corresponding to the previous moment; taking the next moment of the current moment as the new current moment, returning to execute the step of obtaining the current sub-traffic sequence information corresponding to the current moment, until the current moment is the last moment in the sample time period, and taking the sub-time feature of the current moment as the time feature corresponding to the traffic flow sequence information in the sample time period.
[0013] In one embodiment, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; the traffic flow sequence information and the section connection relationship characteristics corresponding to the sample traffic section are input into the spatial attention graph convolutional network to obtain the spatial characteristics corresponding to the traffic flow sequence information within the sample time period, including: inputting the traffic flow sequence information and the section connection relationship characteristics into the spatial attention graph convolutional network, and obtaining the spatial attention characteristics corresponding to the traffic flow sequence information through the spatial attention mechanism of the spatial attention graph convolutional network; according to the spatial attention characteristics and the section connection relationship characteristics Relationship features are used to obtain spatial correlation strength features; the current sub-traffic sequence information corresponding to the current moment and the sub-space features corresponding to the previous moment of the current moment are obtained; the sub-space features of the current moment are obtained by using the current sub-traffic sequence information, the spatial attention features, the spatial correlation strength features and the sub-space features corresponding to the previous moment; the next moment after the current moment is taken as the new current moment, and the step of obtaining the current sub-traffic sequence information corresponding to the current moment is returned to, until the current moment is the last moment in the sample time period, and the sub-space features of the current moment are taken as the spatial features corresponding to the traffic flow sequence information in the sample time period.
[0014] In one embodiment, the traffic flow prediction model includes: a multi-head attention mechanism layer; obtaining the predicted traffic flow data of the sample traffic section at the prediction time based on the spatiotemporal characteristics, including: inputting the spatiotemporal characteristics into the multi-head attention mechanism layer to obtain multiple attention weight matrices corresponding to the spatiotemporal characteristics; using the spatiotemporal characteristics and each of the attention weight matrices to obtain multiple attention features corresponding to the spatiotemporal characteristics; based on the multiple attention features, obtaining the traffic flow output features corresponding to the sample time period; using the traffic flow output features to obtain the predicted traffic flow data of the sample traffic section at the prediction time.
[0015] In one embodiment, there are multiple sample time periods, corresponding to multiple time scales respectively; the method of using the traffic flow output characteristics to obtain the predicted traffic flow data of the sample traffic section at the prediction time includes: obtaining the traffic flow output characteristics corresponding to each sample time period, and obtaining the sub-predicted traffic flow data of the sample traffic section at the prediction time corresponding to each sample time period according to each traffic flow output characteristic; the traffic flow output characteristics corresponding to each sample time period are obtained based on the spatiotemporal characteristics of each sample time period; obtaining the time scale weight of each sample time period, and using each time scale weight to perform weighted processing on the sub-predicted traffic flow data corresponding to each sample time period to obtain the predicted traffic flow data of the sample traffic section at the prediction time; the time scale weight of each sample time period is obtained by the time scale corresponding to each sample time period.
[0016] In one of the embodiments, the method of obtaining sample traffic flow data and traffic status impact data of a sample traffic section at different times within a sample time period includes: obtaining original traffic flow data of the sample traffic section within the sample time period, performing data preprocessing on the original traffic flow data to obtain sample traffic flow data at each time within the sample time period; obtaining static geographic information data of the sample traffic section, and dynamic traffic impact factor data of the sample traffic section corresponding to each time within the sample time period; and using the static geographic information data and the dynamic traffic impact factor data at each time as the traffic status impact data at each time within the sample time period.
[0017] In a second aspect, the present application also provides a traffic flow prediction model training device, comprising:
[0018] A sample data acquisition module is used to acquire sample traffic flow data and traffic status impact data of a sample traffic section at different times within a sample time period, and obtain traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data;
[0019] a spatiotemporal feature acquisition module, for inputting the traffic flow sequence information into a traffic flow prediction model to be trained, obtaining the time features and spatial features corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtaining the spatiotemporal features corresponding to the traffic flow sequence information in the sample time period according to the time features and spatial features;
[0020] A predicted traffic flow acquisition module, used to obtain predicted traffic flow data of the sample traffic section at the predicted time according to the spatiotemporal characteristics;
[0021] The prediction model training module is used to train the traffic flow prediction model according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time to obtain a trained traffic flow prediction model.
[0022] In a third aspect, the present application further provides a computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the method described in any one of the embodiments of the first aspect when executing the computer program.
[0023] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.
[0024] In a fifth aspect, the present application further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method described in any one of the embodiments of the first aspect.
[0025] The above-mentioned traffic flow prediction model training method, device, computer equipment, computer-readable storage medium and computer program product obtain sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period, and obtain the traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data; input the traffic flow sequence information into the traffic flow prediction model to be trained, obtain the time characteristics and spatial characteristics corresponding to the traffic flow sequence information within the sample time period through the traffic flow prediction model, and obtain the time and space characteristics corresponding to the traffic flow sequence information within the sample time period based on the time characteristics and spatial characteristics; obtain the predicted traffic flow data of the sample traffic section at the predicted time based on the time and space characteristics; train the traffic flow prediction model based on the difference between the predicted traffic flow data and the actual traffic flow data of the sample traffic section at the predicted time to obtain a trained traffic flow prediction model. The present application obtains sample traffic flow data and traffic status impact data of sample traffic sections at different times in a sample time period when training a traffic flow prediction model. After obtaining the traffic flow sequence information of the sample traffic section in the sample time period, the traffic flow sequence information can be input into the traffic flow prediction model for training, and the traffic flow prediction model obtains the corresponding time characteristics and space characteristics, thereby constructing the time-space characteristics, and further uses the time-space characteristics to obtain the predicted traffic flow data at the predicted time to complete the model training. Compared with the training method of the prior art, in addition to using sample traffic flow data in the modeling process, the present application also adds traffic status impact data, and during training, the traffic flow prediction model is used to obtain the time characteristics and space characteristics respectively, thereby constructing the time-space characteristics to complete the training. Not only the time dynamic changes of the traffic flow sequence are considered, but also the spatial dependence is considered. Therefore, the trained traffic flow prediction model can improve the prediction accuracy of traffic flow. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0027] FIG1 is a schematic diagram of a flow chart of a method for training a traffic flow prediction model in one embodiment;
[0028] FIG2 is a schematic diagram of a process for obtaining the corresponding spatiotemporal features within a sample time period in one embodiment;
[0029] FIG3 is a schematic diagram of a process for obtaining time characteristics corresponding to traffic flow sequence information in one embodiment;
[0030] FIG4 is a schematic diagram of a process for obtaining spatial features corresponding to traffic flow sequence information in one embodiment;
[0031] FIG5 is a schematic diagram of a process for obtaining sample traffic flow and traffic status impact data in one embodiment;
[0032] FIG6 is a flow chart of a traffic flow prediction model training in one embodiment;
[0033] FIG7 is a model framework diagram of a traffic flow prediction model in one embodiment;
[0034] FIG8 is a structural block diagram of a traffic flow prediction model training device in one embodiment;
[0035] FIG. 9 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0036] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0037] In one embodiment, as shown in FIG1 , a traffic flow prediction model training method is provided. This embodiment uses the method applied to a server as an example for illustration. It is understandable that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is implemented through the interaction between the terminal and the server. In this embodiment, the method includes the following steps:
[0038] Step S101, obtaining sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period, and obtaining traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data.
[0039] Among them, the sample traffic flow data refers to the traffic flow data used for training the traffic flow prediction model, the sample traffic section refers to the section corresponding to the sample traffic flow data, for example, it can be the section area where the traffic flow prediction model needs to predict the traffic flow, and the sample time period refers to the historical time period corresponding to the collected sample traffic flow data. For example, the sample traffic flow data used is the traffic flow data corresponding to time period 1 in traffic section A, then traffic section A is used as the sample traffic section, and time period 1 is used as the sample time period, which can be composed of multiple moments. Traffic state influencing data refers to the influencing factor data that affects traffic flow, such as geographical factors and weather factors near the traffic section, etc. Traffic flow sequence information is sequence information composed of sample traffic flow data and traffic state influencing data.
[0040] For example, traffic flow sequence information can be expressed as:
[0041]
[0042] in, It represents the traffic flow sequence information. represents sample traffic flow data, and It is used to represent traffic status impact data.
[0043] Step S102, input the traffic flow sequence information into the traffic flow prediction model to be trained, obtain the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtain the time and space characteristics corresponding to the traffic flow sequence information in the sample time period based on the time characteristics and spatial characteristics.
[0044] The time feature refers to the feature information used to describe the time series dependency, while the space feature refers to the feature information used to describe the space correlation. The time-space feature is the feature information obtained by combining the time feature and the space feature. Specifically, when training the traffic flow prediction model, the server can input the traffic flow sequence information obtained in step S101 into the traffic flow prediction model to be trained, and the traffic flow prediction model outputs the time feature and the space feature of the traffic flow sequence information within the sample time period, thereby using the time feature and the space feature to output the time-space feature corresponding to the traffic flow sequence information within the sample time period.
[0045] Step S103, obtaining predicted traffic flow data of the sample traffic section at the predicted time according to the spatiotemporal characteristics.
[0046] Predicted traffic flow data refers to traffic flow data output by a traffic flow prediction model, which refers to traffic flow data of a sample traffic section at the prediction time, wherein the prediction time may be a certain time after the sample time period, for example, the prediction time may be date A, and the sample time period may be the time period one week before date A, that is, the model may predict the traffic flow data of date A through the traffic flow data of the time period one week before date A and the traffic state impact data. Specifically, after obtaining the spatiotemporal features, the server may process the spatiotemporal features using the traffic flow prediction model to obtain the predicted traffic flow data at the prediction time.
[0047] Step S104, training a traffic flow prediction model according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time, so as to obtain a trained traffic flow prediction model.
[0048] The actual traffic flow data refers to the real traffic flow data of the sample traffic section at the prediction time. After obtaining the predicted traffic flow data of the sample traffic section at the prediction time, the server can also use the actual traffic flow data of the sample traffic section at the prediction time and the difference between the predicted traffic flow data to train the traffic flow prediction model, thereby obtaining a trained traffic flow prediction model.
[0049] For example, the prediction time may be date A, and the sample time period refers to the week before date A. The server may collect sample traffic flow data and traffic status impact data of the sample traffic section on different days in the week before date A to obtain the traffic flow sequence information of the sample traffic section in the week before date A. The traffic flow sequence information may then be input into the traffic flow prediction model to be trained to obtain the spatiotemporal characteristics of the sample traffic section in the week before date A, thereby obtaining the predicted traffic flow data of the sample traffic section on date A using the spatiotemporal characteristics. The traffic flow prediction model may then be trained using the difference between the actual traffic flow data and the predicted traffic flow data of the sample traffic section on date A to obtain a trained traffic flow prediction model.
[0050] In the above-mentioned traffic flow prediction model training method, by obtaining sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period, the traffic flow sequence information of the sample traffic section within the sample time period is obtained according to the sample traffic flow data and the traffic status impact data; the traffic flow sequence information is input into the traffic flow prediction model to be trained, and the time characteristics and spatial characteristics corresponding to the traffic flow sequence information within the sample time period are obtained through the traffic flow prediction model, and the time and space characteristics corresponding to the traffic flow sequence information within the sample time period are obtained according to the time characteristics and the space characteristics; the predicted traffic flow data of the sample traffic section at the predicted time is obtained according to the time and space characteristics; the traffic flow prediction model is trained according to the difference between the predicted traffic flow data and the actual traffic flow data of the sample traffic section at the predicted time to obtain a trained traffic flow prediction model. The present application obtains sample traffic flow data and traffic status impact data of sample traffic sections at different times in a sample time period when training a traffic flow prediction model. After obtaining the traffic flow sequence information of the sample traffic section in the sample time period, the traffic flow sequence information can be input into the traffic flow prediction model for training, and the traffic flow prediction model obtains the corresponding time characteristics and space characteristics, thereby constructing the time-space characteristics, and further uses the time-space characteristics to obtain the predicted traffic flow data at the predicted time to complete the model training. Compared with the training method of the prior art, in addition to using sample traffic flow data in the modeling process, the present application also adds traffic status impact data, and during training, the traffic flow prediction model is used to obtain the time characteristics and space characteristics respectively, thereby constructing the time-space characteristics to complete the training. Not only the time dynamic changes of the traffic flow sequence are considered, but also the spatial dependence is considered. Therefore, the trained traffic flow prediction model can improve the prediction accuracy of traffic flow.
[0051] In one embodiment, the traffic flow prediction model includes: a temporal attention gated recurrent unit, and a spatial attention graph convolutional network; as shown in FIG2 , step S102 may further include:
[0052] Step S201, inputting the traffic flow sequence information into the temporal attention gated recurrent unit to obtain the time features corresponding to the traffic flow sequence information in the sample time period;
[0053] Step S202, input the traffic flow sequence information and the section connection relationship features corresponding to the sample traffic sections into the spatial attention graph convolutional network to obtain the spatial features corresponding to the traffic flow sequence information in the sample time period.
[0054] In this embodiment, the traffic flow prediction model may include a temporal attention gated recurrent unit, namely TAGRU, and a spatial attention graph convolutional network, namely SAGCN, wherein the temporal attention gated recurrent unit TAGRU is mainly used to output temporal features, while the spatial attention graph convolutional network SAGCN is mainly used to output spatial features.
[0055] Specifically, the server can input the traffic flow sequence information into the temporal attention gated recurrent unit, and the temporal attention gated recurrent unit outputs the time characteristics corresponding to the traffic flow sequence information in the sample time period.
[0056] The road section connection relationship feature refers to the road section connection relationship information of the sample traffic section, which can characterize the traffic node connection relationship of the sample traffic section. Similar to the time feature, the server can also input the traffic flow sequence information and the road section connection relationship features corresponding to the sample traffic section into the spatial attention graph convolutional network, so as to obtain the spatial features corresponding to the traffic flow sequence information in the sample time period through the output of the spatial attention graph convolutional network.
[0057] Step S203, weighting the time features and the space features to obtain the time and space features corresponding to the traffic flow sequence information within the sample time period.
[0058] After obtaining the time features and the space features, they can be weighted, wherein the weighting method can be implemented through an s-type activation function, which can be used to normalize the feature values.
[0059] For example, the spatiotemporal features can be calculated using the following formula:
[0060]
[0061] in, refers to the spatiotemporal characteristics, refers to the time characteristic, while Refers to the spatial characteristics, is a sigmoid activation function.
[0062] In this embodiment, the temporal features can be obtained through the temporal attention gated recurrent unit, the spatial features can be obtained through the spatial attention graph convolutional network, and the spatiotemporal features can be obtained through a weighted method. In this way, the temporal features and the spatial features can be effectively integrated to further improve the prediction accuracy of the traffic flow prediction model.
[0063] Furthermore, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; as shown in FIG3 , step S201 may further include:
[0064] Step S301, input the traffic flow sequence information into the temporal attention gated recurrent unit, and obtain the temporal attention features corresponding to the traffic flow sequence information through the temporal attention mechanism of the temporal attention gated recurrent unit.
[0065] The temporal attention feature may refer to the temporal attention matrix. In this embodiment, the temporal attention gated recurrent unit may carry a temporal attention mechanism. The server may input the traffic flow sequence information into the temporal attention gated recurrent unit, thereby obtaining the temporal attention feature corresponding to the traffic flow sequence information through the temporal attention mechanism of the temporal attention gated recurrent unit.
[0066] For example, the temporal attention feature can be calculated by the following formula:
[0067]
[0068]
[0069] Among them, among them, , , , are the parameters to be trained, Represents the attention matrix It represents the time correlation value between time i and time j, through Function is used to obtain the time correlation of traffic flow series and normalize it. Represents temporal attention features.
[0070] Step S302, obtaining the current sub-traffic sequence information corresponding to the current moment, and the sub-time feature corresponding to the previous moment of the current moment;
[0071] Step S303, using the current sub-traffic sequence information, the time attention feature and the sub-time feature corresponding to the previous moment, obtain the sub-time feature of the current moment.
[0072] The current moment refers to any one of the different moments within the sample time period, and the current sub-traffic sequence information refers to the sub-traffic sequence information corresponding to the current moment. In this embodiment, the traffic flow sequence information within the sample time period can be composed of sub-traffic sequence information of multiple moments. For example, the traffic flow sequence information one week before date A can be composed of sub-traffic flow sequence information of each day in the week before date A, and the sub-time feature refers to the time feature corresponding to each moment.
[0073] Specifically, the server can obtain the current sub-traffic sequence information corresponding to the current moment and the sub-time features of the previous moment, and then use the gated recurrent unit to take the current sub-traffic sequence information, the temporal attention features and the sub-time features output at the previous moment as input to obtain the sub-time features output at the current moment.
[0074] For example, the output sub-time features are If , then the sub-time feature output at the current moment can be calculated by the following formula:
[0075]
[0076] in, Refers to the sub-time feature output at the current moment, refers to the sub-time feature output at the previous moment corresponding to the current moment, and It is the feature information calculated by the current sub-traffic sequence information and the time attention feature.
[0077] Step S304, taking the next moment of the current moment as the new current moment, returning to execute step S302, until the current moment is the last moment in the sample time period, taking the sub-time feature of the current moment as the time feature corresponding to the traffic flow sequence information in the sample time period.
[0078] After obtaining the sub-time feature of the current moment, the next moment of the current moment can be used as the new current moment, and the execution of step S302 is returned to obtain the sub-time feature of the next moment. In this way, the sub-time feature of each moment can be obtained until the current moment is the last moment in the sample time period. At this time, the sub-time feature of the current moment can be used as the time feature corresponding to the traffic flow sequence information in the sample time period.
[0079] For example, in getting After that, t+1 can be used as the new current time, and the sub-time feature of the new current time can be calculated by the above formula, that is, , if t+1 is the last moment in the sample time period, the server can use the sub-time feature of the current moment, that is, As the time characteristics of traffic flow sequence information corresponding to the sample time period .
[0080] In this embodiment, the temporal attention mechanism in the temporal attention gated recurrent unit can also be used to obtain the temporal attention feature, thereby combining the current sub-traffic sequence information corresponding to the current moment, the temporal attention feature and the sub-time feature corresponding to the previous moment to output the sub-time feature of the current moment. If the current moment is the last moment in the sample time period, the sub-time feature can be used as the corresponding time feature in the sample time period. In this way, the temporal attention gated recurrent unit can be used to mine context information, further improving the accuracy of the temporal feature output.
[0081] In addition, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; as shown in FIG4 , step S202 may further include:
[0082] Step S401, input the traffic flow sequence information and the road section connection relationship characteristics into the spatial attention graph convolutional network, and obtain the spatial attention features corresponding to the traffic flow sequence information through the spatial attention mechanism of the spatial attention graph convolutional network.
[0083] The spatial attention feature may refer to the spatial attention matrix. In this embodiment, the spatial attention graph convolutional network may carry a spatial attention mechanism. The server may input the traffic flow sequence information and the road section connection relationship features into the spatial attention graph convolutional network, thereby calculating the spatial attention feature corresponding to the traffic flow sequence information through the spatial attention mechanism of the spatial attention graph convolutional network.
[0084] For example, the spatial attention feature can be calculated by the following formula:
[0085]
[0086]
[0087] in, , , , , are the parameters to be trained, represents traffic flow sequence information, Indicates the correlation strength between node i and node j, through Function to obtain the spatial correlation between nodes and normalize them, and Represents spatial attention features.
[0088] Step S402, obtaining a spatial correlation strength feature based on the spatial attention feature and the road segment connection relationship feature.
[0089] The spatial correlation strength feature is a feature matrix obtained by the spatial attention feature and the road segment connection relationship feature. For example, the road segment connection relationship feature can be an adjacency matrix, and the spatial correlation strength feature can be calculated based on the spatial attention matrix and the adjacency matrix.
[0090] For example, the spatial correlation strength feature can be calculated by the following formula:
[0091]
[0092] in, is the spatial correlation intensity feature, is the link connection feature, and Represents spatial attention features.
[0093] Step S403, obtaining the current sub-traffic sequence information corresponding to the current moment, and the sub-space features corresponding to the previous moment of the current moment;
[0094] Step S404, using the current sub-traffic sequence information, spatial attention features, spatial correlation strength features and the sub-space features corresponding to the previous moment, obtain the sub-space features of the current moment.
[0095] Similar to calculating the sub-time features of the current moment, in this embodiment, the traffic flow sequence information within the sample time period may be composed of sub-traffic sequence information of multiple moments, and the sub-space features refer to the space features corresponding to each moment.
[0096] Specifically, the server can obtain the current sub-traffic sequence information corresponding to the current moment, as well as the sub-space features of the previous moment, and then use the graph convolutional network to take the current sub-traffic sequence information, spatial attention features, spatial correlation intensity features, and the sub-time features output at the previous moment as input. After obtaining the output, the output of the graph convolutional network and the spatial attention features are used to calculate the sub-space features output at the current moment.
[0097] For example, the output subspace features are , then the subspace features output at the current moment can be calculated by the following formula:
[0098]
[0099] in, Refers to the subspace features output at the current moment, refers to the subspace feature output at the previous moment corresponding to the current moment, and It is the feature information calculated by the current sub-traffic sequence information and spatial attention features.
[0100] In addition, the graph convolution modeling process can be expressed as:
[0101]
[0102] in, is the degree matrix, is an adjacency matrix with a self-connection structure, i.e., the spatial correlation strength feature, is the weight matrix of the lth layer.
[0103] Step S405, taking the next moment after the current moment as the new current moment, returning to execute step S403, until the current moment is the last moment in the sample time period, taking the subspace feature of the current moment as the spatial feature corresponding to the traffic flow sequence information in the sample time period.
[0104] After obtaining the sub-control features of the current moment, the next moment after the current moment can be used as the new current moment, and the execution of step S403 is returned to obtain the subspace features of the next moment. In this way, the subspace features of each moment can be obtained until the current moment is the last moment in the sample time period. At this time, the subspace features of the current moment can be used as the spatial features corresponding to the traffic flow sequence information in the sample time period.
[0105] For example, in getting After that, t+1 can be used as the new current time, and the subspace features of the new current time can be calculated by the above formula, that is, , if t+1 is the last moment in the sample time period, the server can use the subspace features of the current moment, that is, As the spatial characteristics of traffic flow sequence information in the sample time period .
[0106] In this embodiment, the spatial attention mechanism in the temporal attention gated recurrent unit can also be used to obtain the spatial attention feature, and the spatial attention feature can be used to obtain the spatial correlation strength feature corresponding to the road section connection relationship feature, so as to combine the current sub-traffic sequence information, spatial attention feature, spatial correlation strength feature and subspace feature corresponding to the previous moment to output the subspace feature of the current moment. If the current moment is the last moment in the sample time period, the subspace feature can be used as the corresponding spatial feature in the sample time period. In this way, the spatial attention graph convolution network can be used to capture spatial features, thereby further improving the accuracy of spatial feature output.
[0107] In one embodiment, the traffic flow prediction model includes: a multi-head attention mechanism layer; step S103 may further include: inputting the spatiotemporal features into the multi-head attention mechanism layer to obtain multiple attention weight matrices corresponding to the spatiotemporal features; using the spatiotemporal features and each attention weight matrix to obtain multiple attention features corresponding to the spatiotemporal features; based on the multiple attention features, obtaining the traffic flow output features corresponding to the sample time period; using the traffic flow output features to obtain the predicted traffic flow data of the sample traffic section at the prediction time.
[0108] In this embodiment, the traffic flow prediction model also includes a multi-head attention mechanism layer, which can be used to aggregate local and global information and more effectively capture traffic flow information of adjacent roads, and multiple attention weight matrices are weight matrices corresponding to multiple attention mechanisms. For example, the multi-head attention mechanism layer can contain multiple heads, and each head corresponds to an attention weight matrix. After that, the spatiotemporal features and each attention weight matrix can be used to calculate the attention features respectively, so as to obtain multiple attention features as the output of each head, and then the multiple attention features can be spliced to obtain the final traffic flow output features corresponding to the sample time period, and then the traffic flow output features can be used to obtain the predicted traffic flow data of the sample traffic section at the predicted time.
[0109] In this embodiment, it is also possible to obtain predicted traffic flow data by adding a multi-head attention mechanism layer, which can aggregate local and global traffic information and more effectively capture traffic flow information of adjacent roads, thereby improving the output accuracy of predicted traffic flow data.
[0110] Furthermore, there are multiple sample time periods, corresponding to multiple time scales respectively; using the traffic flow output characteristics to obtain the predicted traffic flow data of the sample traffic section at the prediction time can further include: obtaining the traffic flow output characteristics corresponding to each sample time period, and obtaining the sub-predicted traffic flow data of the sample traffic section at the prediction time corresponding to each sample time period according to each traffic flow output characteristic; the traffic flow output characteristics corresponding to each sample time period are obtained based on the spatiotemporal characteristics of each sample time period; obtaining the time scale weight of each sample time period, and using each time scale weight, weighted processing is performed on the sub-predicted traffic flow data corresponding to each sample time period to obtain the predicted traffic flow data of the sample traffic section at the prediction time; the time scale weight of each sample time period is obtained by the time scale corresponding to each sample time period.
[0111] In this embodiment, the number of sample time periods can be multiple, corresponding to different time scales, so the sample traffic flow data and traffic status impact data can also be multiple corresponding to different time scales. For example, the time scale can include one day, one week or one hour, then the sample traffic flow data can include the traffic flow data of the day before date A, the traffic flow data of the week before date A, and the traffic flow data of one hour before date A. Similarly, the traffic status impact data can also correspond to multiple different time scales, so the output traffic flow output features can also correspond to different sample time periods, corresponding to different time scales.
[0112] Specifically, the server can use the sample traffic flow data and traffic status impact data of the sample traffic section within a certain sample time period, for example, use the traffic flow data of the day before date A and the traffic status impact data of the day before date A to obtain the spatiotemporal characteristics of the day before date A, and then calculate the traffic flow output characteristics of the day before date A. Similarly, the traffic flow data of the week before date A and the traffic status impact data of the week before date A can be used to obtain the spatiotemporal characteristics of the week before date A, and then calculate the traffic flow output characteristics of the week before date A. In this way, the traffic flow output characteristics corresponding to each sample time period can be obtained, and then the traffic flow output characteristics of different sample time periods can be used to predict the sub-predicted traffic flow data of the sample traffic section at the prediction time, that is, the traffic flow output characteristics of the day before date A are used to obtain sub-predicted traffic flow data 1, and the traffic flow output characteristics of the week before date A are used to obtain sub-predicted traffic flow data 2, and so on.
[0113] The time scale weight is the time scale weight corresponding to different sample time periods. The weight can be obtained based on the time scale corresponding to the sample time period. That is, corresponding to the time scale of one day, the time scale weight can be set to weight 1, and corresponding to the time scale of one week, the time scale weight can be set to weight 2, and so on. After that, the sub-predicted traffic flow data corresponding to each sample time period can be weighted using the time scale weights to obtain the predicted traffic flow data of the sample traffic section at the predicted time.
[0114] For example, multiple time scales can be one hour, one day, and one week, respectively. Then the predicted traffic flow data of the sample traffic section at the predicted time can be calculated by the following formula:
[0115]
[0116] in, is the Hadamard product, , , are the weight parameters that need to be learned at different time scales, namely, the time scale weights corresponding to one hour, one day, and one week, respectively. , , It is the sub-prediction traffic flow data of sample time periods at different time scales.
[0117] In this embodiment, the sub-prediction traffic flow data of different time scales can also be integrated to obtain the final predicted traffic flow data. Therefore, the prediction results of different time scales can be combined to obtain the final prediction result, thereby improving the accuracy of the prediction result.
[0118] In one embodiment, as shown in FIG5 , step S101 may further include:
[0119] Step S501, obtaining the original traffic flow data of the sample traffic section within the sample time period, performing data preprocessing on the original traffic flow data, and obtaining the sample traffic flow data at each moment within the sample time period.
[0120] The original traffic flow data refers to the unprocessed traffic flow data. In this embodiment, the sample traffic flow data used for training the traffic flow prediction model can be obtained by preprocessing the original traffic flow data. For example, the original traffic flow data of the sample traffic section within the sample time period can be first filled with missing values and outliers using a linear interpolation method, and then the traffic flow data with missing values and outliers filled is time-sliced in a sliding window manner, and finally the traffic flow data is normalized using a linear function (Min-Max Scaling) method.
[0121] Step S502, obtaining static geographic information data of the sample traffic section and dynamic traffic influencing factor data of the sample traffic section at each moment in the sample time period;
[0122] Step S503: Using the static geographic information data and the dynamic traffic influencing factor data at each moment as the traffic status influencing data at each moment in the sample time period.
[0123] Traffic status influencing data can include two types, namely static geographic information data and dynamic traffic influencing factor data. Static geographic information data refers to static geographic information that does not change over time but still has an impact on traffic status, such as catering, transportation and accommodation facilities, etc. Dynamic factors are mainly uncontrollable external factors that affect traffic, such as weather conditions and holidays, which can also directly affect traffic status.
[0124] Specifically, the server can also collect static geographic information data of the sample traffic sections, as well as dynamic traffic influencing factor data of the sample traffic sections at each moment within the sample time period, and then use the above static geographic information data and dynamic traffic influencing factor data at each moment as traffic status influencing data at each moment within the sample time period.
[0125] For example, the final model input can be represented as:
[0126]
[0127] in, represents the model input data at time t within the sample time period, represents the sample traffic flow data at time t within the sample time period, Represents static geographic information data, while It represents the dynamic traffic influencing factor data corresponding to time t within the sample time period. The dynamic traffic influencing factor data may be composed of the dynamic traffic influencing attributes of q times before time t.
[0128] In this embodiment, the collected original traffic flow data can also be preprocessed to obtain sample traffic flow data, and static factors and dynamic phonemes can be combined as traffic status influencing data, thereby improving the integrity of the model input and further improving the prediction accuracy of the traffic flow prediction model.
[0129] In one embodiment, a multi-scale traffic flow prediction method based on a spatiotemporal graph convolutional network is also provided. The prediction model regards external factors as the attribute information of road sections in the road network, integrates attribute information and traffic characteristics to enhance the model's perception of external information, and is composed of a graph convolution layer in the spatial dimension and a standard convolution in the temporal dimension. It is combined with a multi-head attention mechanism to capture dependencies in the spatial and temporal dimensions and predict at multiple time scales at the same time. Traffic flow input information integrates external influence information, spatiotemporal graph convolution learns the dynamic spatiotemporal correlation of traffic flow sequences, mines the contextual dependency of traffic flow sequences, and enhances correlation information. The multi-head attention mechanism aggregates information from different subspaces, captures the global temporal dependency in the sequence, and improves the accuracy of traffic flow prediction.
[0130] The specific implementation includes the following processes:
[0131] 1. Traffic flow data preprocessing:
[0132] (1) Extract traffic flow data of corresponding stations according to the geographical location of the traffic section;
[0133] (2) Use linear interpolation to fill missing values and outliers;
[0134] (3) Time-slicing the traffic flow data using a sliding window approach;
[0135] (4) Use the linear function (Min-Max Scaling) method to normalize the traffic flow data.
[0136] 2. Construct an enhancement matrix:
[0137] Static factors mainly refer to static geographic information that does not change over time but still has an impact on traffic conditions. For example, catering, transportation and accommodation facilities. Dynamic factors are mainly uncontrollable external factors that affect traffic, such as weather conditions and holidays, which can also directly affect traffic conditions.
[0138] By static feature matrix The augmentation matrix can be constructed as follows:
[0139]
[0140] in, yes A collection of different static factors, Input representing traffic information at three different time scales.
[0141] Dynamic feature attributes In Properties Conditions, time period The expression inside is as follows:
[0142]
[0143] in, represents the time span window, Represents dynamic attributes, yes The temporal attention mechanism GRU and the spatial attention mechanism GCN are used to capture the spatiotemporal dependencies of traffic flow sequences.
[0144] The enhanced matrix constructed by adding dynamic attributes based on static features can be expressed as:
[0145]
[0146] 3. Use the temporal attention mechanism GRU and the spatial attention mechanism GCN to capture the spatiotemporal dependencies of traffic flow sequences.
[0147] Spatial Attention Mechanism GCN:
[0148] (1) Spatial Attention Mechanism:
[0149] This embodiment uses a spatial attention mechanism to capture the dynamic spatial correlation between adjacent nodes as follows:
[0150]
[0151] in, , , , , are the parameters to be trained, Indicates The output of the space-time block, Representation Node With Node The strength of the correlation is Function to obtain the spatial correlation between nodes and normalize them. It is The time scale of the layer, It is The number of attribute features of the layer. The attention machine increases the importance of important information at different time nodes and is applicable to longer-term prediction problems. Adjacency matrix of graph convolution The adjacency matrix With the spatial attention matrix Combination to dynamically change the spatial correlation strength between nodes.
[0152] (2) Constructing spatial attention mechanism graph convolution:
[0153] The graph convolution modeling process can be expressed as:
[0154]
[0155] in, is the degree matrix, where is an adjacency matrix with a self-connection structure. It is The weight matrix of the layer.
[0156]
[0157] in, yes The output of the moment, yes The output of the moment, yes The final output at the moment.
[0158] Temporal Attention Mechanism GRU:
[0159] (1) Temporal Attention Mechanism:
[0160] This embodiment uses an attention mechanism to capture the dynamic spatial correlation between nodes as follows:
[0161]
[0162]
[0163] in, , , , are the parameters to be trained, represents the attention matrix, Indicates time With the moment The time correlation value of Function to obtain the time correlation of traffic flow series and normalize it. Input By feature matrix With the time attention matrix Combination composition.
[0164] (2) Constructing a spatial attention mechanism gated recurrent unit:
[0165] The output at each moment can be expressed as:
[0166]
[0167] in, yes Input at the moment, yes The output of the moment, yes The final output at the moment.
[0168] The GRU process can be expressed as:
[0169]
[0170]
[0171]
[0172]
[0173] in, for Input at the moment, is the output at the previous moment, , , is the weight parameter of each gate, , , is the bias parameter for each gate, , , , They represent the update gate, reset gate, current saved information and final output respectively.
[0174] Each moment input passes through the GRU network to learn the changes in time value weights and time trends over a period of time, thereby learning time features from a more fine-grained perspective.
[0175] 4. Space-time combined output:
[0176] The process of integrating time and space features of the present invention is expressed as:
[0177]
[0178] Among them, σ is an s-type activation function, which can be used to normalize the eigenvalues to avoid gradient explosion during the fusion process.
[0179] 5. Multiple attention:
[0180] This embodiment uses a multi-head attention mechanism to aggregate information from different subspaces and improve the representation of model-captured features. The multi-head attention mechanism can be expressed as:
[0181]
[0182] in, Represents the query key, On behalf of Keyjian, Represents Value Health, Representative Node The output matrix at Represents the dimension size of the key, , , is the projection parameter matrix that needs to be learned.
[0183] 6. Fusion of forecasts at different time scales:
[0184] In this embodiment, the model is applied in different time periods, and the fusion process of prediction results at different time scales is as follows:
[0185]
[0186] in, is the Hadamard product, , , It is the weight parameter that needs to be learned in different time periods.
[0187] The multi-scale traffic flow prediction method based on the spatiotemporal graph convolutional network proposed in this embodiment can be applied to the prediction of traffic flow in smart transportation. The flow chart and framework diagram of the model are shown in Figures 6 and 7 respectively.
[0188] The specific implementation steps of the multi-scale traffic flow prediction framework based on spatiotemporal graph convolutional network are as follows:
[0189] (1) Extract traffic flow data from the roads in the area to be predicted for preprocessing.
[0190] (2) Determine the degree of association of each node based on the connectivity of the roads and construct an adjacency matrix.
[0191] (3) An enhancement matrix is constructed based on external dynamic factors and static factors, and the traffic flow information sequences of three different scales (recent, daily, and weekly) combined with the adjacency matrix and the enhancement matrix are used as model input.
[0192] (4) The temporal attention mechanism GRU and the spatial attention mechanism GCNU model are combined and output as a spatiotemporal block, and a two-layer spatiotemporal convolution block is built, and then the final multi-head attention mechanism transform layer is built. The spatiotemporal convolution block captures the time series dependency through the temporal attention mechanism GRU, and the spatial correlation through the spatial attention mechanism GCNU. The multi-head attention mechanism is normalized to prevent overfitting and effectively aggregate the traffic flow information of different adjacent roads. The outputs of different scales are combined and output as the final multi-period prediction result.
[0193] (5) Model training, saving and updating the optimal model:
[0194] The error function of multi-scale traffic flow prediction based on spatiotemporal graph convolutional network is expressed as:
[0195]
[0196] in, Represents the vector norm, is the difference between the actual value and the predicted value Norm term, regularization term Prevent overfitting of the model and improve the predictive performance of the model.
[0197] In this embodiment, 70% of the data set is used for training, 20% of the data set is used for testing, and 10% of the data set is used for validation. The optimization function is the Adam function, and the trained model is saved.
[0198] (6) Using the optimal model for prediction:
[0199] The multi-scale traffic flow prediction method based on spatiotemporal graph convolutional network not only considers the impact of facilities around the road in terms of traffic information input, but also adds the interference information of dynamic factors, and designs a combined spatiotemporal graph convolution block of temporal attention GRU and spatial attention GRU to obtain the spatial correlation information between roads and the temporal dependence of traffic flow information. At the same time, a multi-head attention mechanism is added to further effectively aggregate local and global spatiotemporal characteristics of traffic flow, improve prediction accuracy, and realize traffic flow prediction tasks at different time scales.
[0200] Through this embodiment, a new spatiotemporal graph convolution multi-scale prediction model is proposed, which integrates the external dynamic and static factors of the road, and takes into account the temporal periodicity, spatiotemporal multi-scale features and parameter fusion. A new spatiotemporal attention convolution block is designed, which uses the temporal attention GRU to mine contextual information for sequence data with complex topology and time dependency, uses the spatial attention graph convolution to capture spatial features, and fuses the output spatiotemporal features. The output network is constructed by integrating the multi-head attention mechanism, aggregating local and global traffic information, and more effectively capturing the traffic flow information of adjacent roads.
[0201] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0202] Based on the same inventive concept, the embodiment of the present application also provides a traffic flow prediction model training device for implementing the above-mentioned traffic flow prediction model training method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above-mentioned method, so the specific limitations in one or more traffic flow prediction model training device embodiments provided below can refer to the limitations of the traffic flow prediction model training method above, and will not be repeated here.
[0203] In one embodiment, as shown in FIG8 , a traffic flow prediction model training device is provided, including: a sample data acquisition module 801, a spatiotemporal feature acquisition module 802, a predicted flow acquisition module 803 and a prediction model training module 804, wherein:
[0204] The sample data acquisition module 801 is used to acquire the sample traffic flow data and traffic state impact data of the sample traffic section at different times in the sample time period, and obtain the traffic flow sequence information of the sample traffic section in the sample time period according to the sample traffic flow data and traffic state impact data;
[0205] The spatiotemporal feature acquisition module 802 is used to input the traffic flow sequence information into the traffic flow prediction model to be trained, obtain the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtain the spatiotemporal characteristics corresponding to the traffic flow sequence information in the sample time period according to the time characteristics and spatial characteristics;
[0206] The predicted traffic flow acquisition module 803 is used to obtain the predicted traffic flow data of the sample traffic section at the predicted time according to the spatiotemporal characteristics;
[0207] The prediction model training module 804 is used to train the traffic flow prediction model according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time, so as to obtain a trained traffic flow prediction model.
[0208] In one embodiment, the traffic flow prediction model includes: a temporal attention gated recurrent unit, and a spatial attention graph convolutional network; a spatiotemporal feature acquisition module 802, further used to input the traffic flow sequence information into the temporal attention gated recurrent unit to obtain the temporal features corresponding to the traffic flow sequence information within the sample time period; input the traffic flow sequence information and the section connection relationship features corresponding to the sample traffic section into the spatial attention graph convolutional network to obtain the spatial features corresponding to the traffic flow sequence information within the sample time period; and perform weighted processing on the temporal features and the spatial features to obtain the spatiotemporal features corresponding to the traffic flow sequence information within the sample time period.
[0209] In one embodiment, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different moments within the sample time period; the spatiotemporal feature acquisition module 802 is further used to input the traffic flow sequence information into the temporal attention gated loop unit, and obtain the temporal attention feature corresponding to the traffic flow sequence information through the temporal attention mechanism of the temporal attention gated loop unit; obtain the current sub-traffic sequence information corresponding to the current moment, and the sub-time feature corresponding to the previous moment of the current moment; use the current sub-traffic sequence information, the temporal attention feature and the sub-time feature corresponding to the previous moment to obtain the sub-time feature of the current moment; take the next moment of the current moment as the new current moment, return to execute the step of obtaining the current sub-traffic sequence information corresponding to the current moment, until the current moment is the last moment in the sample time period, and take the sub-time feature of the current moment as the time feature corresponding to the traffic flow sequence information in the sample time period.
[0210] In one embodiment, the traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; the spatiotemporal feature acquisition module 802 is further used to input the traffic flow sequence information and the road segment connection relationship features into the spatial attention graph convolution network, and obtain the spatial attention features corresponding to the traffic flow sequence information through the spatial attention mechanism of the spatial attention graph convolution network; obtain the spatial correlation strength features according to the spatial attention features and the road segment connection relationship features; obtain the current sub-traffic sequence information corresponding to the current moment, and the sub-space features corresponding to the previous moment of the current moment; use the current sub-traffic sequence information, the spatial attention features, the spatial correlation strength features and the sub-space features corresponding to the previous moment to obtain the sub-space features of the current moment; take the next moment of the current moment as the new current moment, return to execute the step of obtaining the current sub-traffic sequence information corresponding to the current moment, until the current moment is the last moment in the sample time period, and take the sub-space features of the current moment as the spatial features corresponding to the traffic flow sequence information in the sample time period.
[0211] In one embodiment, the traffic flow prediction model includes: a multi-head attention mechanism layer; a predicted traffic acquisition module 803, which is further used to input spatiotemporal features into the multi-head attention mechanism layer to obtain multiple attention weight matrices corresponding to the spatiotemporal features; using the spatiotemporal features and each attention weight matrix to obtain multiple attention features corresponding to the spatiotemporal features; based on the multiple attention features, obtaining the traffic flow output features corresponding to the sample time period; using the traffic flow output features to obtain the predicted traffic flow data of the sample traffic section at the prediction time.
[0212] In one embodiment, there are multiple sample time periods, corresponding to multiple time scales respectively; the predicted traffic acquisition module 803 is further used to obtain the traffic flow output characteristics corresponding to each sample time period, and obtain the sub-predicted traffic flow data of the sample traffic section at the prediction time corresponding to each sample time period according to each traffic flow output characteristic; the traffic flow output characteristics corresponding to each sample time period are obtained based on the spatiotemporal characteristics of each sample time period; the time scale weight of each sample time period is obtained, and the sub-predicted traffic flow data corresponding to each sample time period is weightedly processed using each time scale weight to obtain the predicted traffic flow data of the sample traffic section at the prediction time; the time scale weight of each sample time period is obtained by the time scale corresponding to each sample time period.
[0213] In one embodiment, the sample data acquisition module 801 is further used to obtain the original traffic flow data of the sample traffic section within the sample time period, perform data preprocessing on the original traffic flow data, and obtain the sample traffic flow data at each moment within the sample time period; obtain the static geographic information data of the sample traffic section, and the dynamic traffic influencing factor data of the sample traffic section corresponding to each moment within the sample time period; use the static geographic information data and the dynamic traffic influencing factor data at each moment as the traffic status influencing data at each moment within the sample time period.
[0214] Each module in the above-mentioned traffic flow prediction model training device can be implemented in whole or in part by software, hardware and their combination. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the corresponding operations of each of the above modules.
[0215] In an exemplary embodiment, a computer device is provided, which may be a server, and its internal structure diagram may be shown in FIG9. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface is connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store sample traffic flow data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a traffic flow prediction model training method is implemented.
[0216] Those skilled in the art will understand that the structure shown in FIG. 9 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0217] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0218] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0219] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0220] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0221] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in this application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0222] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0223] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A traffic flow prediction model training method, characterized in that: The method comprises: Acquire sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period, and obtain traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data; Inputting the traffic flow sequence information into the traffic flow prediction model to be trained, obtaining the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtaining the time and space characteristics corresponding to the traffic flow sequence information in the sample time period according to the time characteristics and spatial characteristics; Obtaining predicted traffic flow data of the sample traffic section at a predicted time according to the spatiotemporal characteristics; The traffic flow prediction model is trained according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time to obtain a trained traffic flow prediction model.
2. The method according to claim 1, characterized in that The traffic flow prediction model includes: a temporal attention gated recurrent unit and a spatial attention graph convolutional network; the traffic flow sequence information is input into the traffic flow prediction model to be trained, and the time characteristics and spatial characteristics corresponding to the traffic flow sequence information in the sample time period are obtained through the traffic flow prediction model, and the spatiotemporal characteristics corresponding to the traffic flow sequence information in the sample time period are obtained according to the time characteristics and spatial characteristics, including: Inputting the traffic flow sequence information into the temporal attention gated recurrent unit to obtain the time features corresponding to the traffic flow sequence information in the sample time period; Inputting the traffic flow sequence information and the road section connection relationship features corresponding to the sample traffic section into the spatial attention graph convolution network to obtain the spatial features corresponding to the traffic flow sequence information in the sample time period; The time feature and the space feature are weighted to obtain the time and space features corresponding to the traffic flow sequence information in the sample time period.
3. The method according to claim 2, characterized in that The traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; The step of inputting the traffic flow sequence information into the temporal attention gated recurrent unit to obtain the time features corresponding to the traffic flow sequence information includes: Inputting the traffic flow sequence information into the temporal attention gated recurrent unit, and obtaining the temporal attention features corresponding to the traffic flow sequence information through the temporal attention mechanism of the temporal attention gated recurrent unit; Obtaining the current sub-traffic sequence information corresponding to the current moment, and the sub-time feature corresponding to the previous moment of the current moment; Using the current sub-traffic sequence information, the temporal attention feature, and the sub-temporal feature corresponding to the previous moment, the sub-temporal feature of the current moment is obtained; The next moment after the current moment is taken as the new current moment, and the step of obtaining the current sub-traffic sequence information corresponding to the current moment is returned to execute until the current moment is the last moment in the sample time period, and the sub-time feature of the current moment is taken as the time feature corresponding to the traffic flow sequence information in the sample time period.
4. The method according to claim 2, characterized in that: The traffic flow sequence information within the sample time period includes sub-traffic sequence information at different times within the sample time period; The step of inputting the traffic flow sequence information and the road section connection relationship features corresponding to the sample traffic sections into the spatial attention graph convolution network to obtain the spatial features corresponding to the traffic flow sequence information in the sample time period includes: Inputting the traffic flow sequence information and the road section connection relationship features into the spatial attention graph convolution network, and obtaining the spatial attention features corresponding to the traffic flow sequence information through the spatial attention mechanism of the spatial attention graph convolution network; Obtaining a spatial correlation strength feature according to the spatial attention feature and the road section connection relationship feature; Obtaining current sub-traffic sequence information corresponding to the current moment, and sub-space features corresponding to the previous moment before the current moment; Obtaining the subspace feature of the current moment by using the current sub-traffic sequence information, the spatial attention feature, the spatial correlation strength feature, and the subspace feature corresponding to the previous moment; The next moment after the current moment is taken as the new current moment, and the step of obtaining the current sub-traffic sequence information corresponding to the current moment is returned to execute until the current moment is the last moment in the sample time period, and the sub-space feature of the current moment is taken as the spatial feature corresponding to the traffic flow sequence information in the sample time period.
5. The method according to any one of claims 1 to 4, characterized in that: The traffic flow prediction model includes: a multi-head attention mechanism layer; the predicted traffic flow data of the sample traffic section at the predicted time is obtained according to the spatiotemporal characteristics, including: Inputting the spatiotemporal features into the multi-head attention mechanism layer to obtain multiple attention weight matrices corresponding to the spatiotemporal features; Using the spatiotemporal features and each of the attention weight matrices, a plurality of attention features corresponding to the spatiotemporal features are obtained; Based on the multiple attention features, obtaining a traffic flow output feature corresponding to the sample time period; The traffic flow output characteristics are used to obtain the predicted traffic flow data of the sample traffic section at the predicted time.
6. The method according to claim 5, characterized in that The number of the sample time periods is multiple, corresponding to multiple time scales respectively; the predicted traffic flow data of the sample traffic section at the predicted time is obtained by using the traffic flow output characteristics, including: Obtaining the traffic flow output features corresponding to each sample time period, and obtaining the sub-prediction traffic flow data of the sample traffic section at the prediction time corresponding to each sample time period according to each traffic flow output feature; the traffic flow output features corresponding to each sample time period are obtained based on the spatiotemporal features of each sample time period; The time scale weight of each sample time period is obtained, and the sub-prediction traffic flow data corresponding to each sample time period is weighted by using the time scale weight to obtain the predicted traffic flow data of the sample traffic section at the predicted time; the time scale weight of each sample time period is obtained from the time scale corresponding to each sample time period.
7. The method according to claim 1, characterized in that The method of obtaining sample traffic flow data and traffic status impact data of the sample traffic section at different times within the sample time period includes: Acquire the original traffic flow data of the sample traffic section in the sample time period, perform data preprocessing on the original traffic flow data, and obtain the sample traffic flow data at each moment in the sample time period; Obtaining static geographic information data of the sample traffic section and dynamic traffic influencing factor data of the sample traffic section corresponding to each moment in the sample time period; The static geographic information data and the dynamic traffic influencing factor data at each of the moments are used as the traffic status influencing data at each of the moments in the sample time period.
8. A traffic flow prediction model training device, characterized in that: The device comprises: A sample data acquisition module is used to acquire sample traffic flow data and traffic status impact data of a sample traffic section at different times within a sample time period, and obtain traffic flow sequence information of the sample traffic section within the sample time period based on the sample traffic flow data and traffic status impact data; a spatiotemporal feature acquisition module, for inputting the traffic flow sequence information into a traffic flow prediction model to be trained, obtaining the time features and spatial features corresponding to the traffic flow sequence information in the sample time period through the traffic flow prediction model, and obtaining the spatiotemporal features corresponding to the traffic flow sequence information in the sample time period according to the time features and spatial features; A predicted traffic flow acquisition module, used to obtain predicted traffic flow data of the sample traffic section at the predicted time according to the spatiotemporal characteristics; The prediction model training module is used to train the traffic flow prediction model according to the predicted traffic flow data and the difference between the actual traffic flow data of the sample traffic section at the prediction time to obtain a trained traffic flow prediction model.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Traffic flow prediction method and device based on attention mechanism, equipment and medium
CN119741834A
Traffic Flow Prediction Method, Device, Equipment and Medium Based on Attention Mechanism
CN119741834B