+

CN117894168A - A traffic flow anomaly detection method based on graph contrastive learning network - Google Patents

A traffic flow anomaly detection method based on graph contrastive learning network Download PDF

Info

Publication number
CN117894168A
CN117894168A CN202311663789.4A CN202311663789A CN117894168A CN 117894168 A CN117894168 A CN 117894168A CN 202311663789 A CN202311663789 A CN 202311663789A CN 117894168 A CN117894168 A CN 117894168A
Authority
CN
China
Prior art keywords
time
graph
space
traffic flow
layer
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311663789.4A
Other languages
Chinese (zh)
Inventor
马佳曼
吴宜正
罗喜伶
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beihang University
Zhejiang Scientific Research Institute of Transport
Original Assignee
Beihang University
Zhejiang Scientific Research Institute of Transport
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beihang University, Zhejiang Scientific Research Institute of Transport filed Critical Beihang University
Priority to CN202311663789.4A priority Critical patent/CN117894168A/en
Publication of CN117894168A publication Critical patent/CN117894168A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G08SIGNALLING
    • G08GTRAFFIC CONTROL SYSTEMS
    • G08G1/00Traffic control systems for road vehicles
    • G08G1/01Detecting movement of traffic to be counted or controlled
    • G08G1/0104Measuring and analyzing of parameters relative to traffic conditions
    • G08G1/0125Traffic data processing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/21Design or setup of recognition systems or techniques; Extraction of features in feature space; Blind source separation
    • G06F18/213Feature extraction, e.g. by transforming the feature space; Summarisation; Mappings, e.g. subspace methods
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/24Classification techniques
    • G06F18/243Classification techniques relating to the number of classes
    • G06F18/2433Single-class perspective, e.g. one-against-all classification; Novelty detection; Outlier detection
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/29Graphical models, e.g. Bayesian networks
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • G06N3/045Combinations of networks
    • G06N3/0455Auto-encoder networks; Encoder-decoder networks
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • G06N3/0895Weakly supervised learning, e.g. semi-supervised or self-supervised learning
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F2123/00Data types
    • G06F2123/02Data types in the time domain, e.g. time-series data
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02TCLIMATE CHANGE MITIGATION TECHNOLOGIES RELATED TO TRANSPORTATION
    • Y02T10/00Road transport of goods or passengers
    • Y02T10/10Internal combustion engine [ICE] based vehicles
    • Y02T10/40Engine management systems

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • Artificial Intelligence (AREA)
  • General Engineering & Computer Science (AREA)
  • Evolutionary Computation (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Evolutionary Biology (AREA)
  • Biophysics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Software Systems (AREA)
  • Molecular Biology (AREA)
  • General Health & Medical Sciences (AREA)
  • Computational Linguistics (AREA)
  • Biomedical Technology (AREA)
  • Health & Medical Sciences (AREA)
  • Chemical & Material Sciences (AREA)
  • Analytical Chemistry (AREA)
  • Traffic Control Systems (AREA)

Abstract

The invention discloses a traffic flow anomaly detection method based on a graph comparison learning network, and belongs to the technical field of traffic flow monitoring. The invention takes the occupancy rate, speed and flow information of the urban road network structure and traffic flow as road section characteristics, designs an area clustering algorithm to form urban area representation, and constructs an urban road section map structure and an urban area map structure; based on two urban traffic map structures, a space-time encoder-decoder network with shared parameters is designed, the network is composed of a space-time attention module consisting of a map coiler layer and a time self-attention layer and a designed flow change extraction and comparison learning layer, and traffic jams and abnormal road sections are efficiently detected under different time and dynamic environments. The invention can efficiently model traffic conditions in different time and dynamic environments, and is helpful for better understanding the space-time characteristics of urban traffic; the real-time and dynamic changes of urban traffic can be processed, and the effectiveness of traffic management is improved.

Description

一种基于图对比学习网络的交通流异常检测方法A traffic flow anomaly detection method based on graph contrastive learning network

技术领域Technical Field

本发明属于交通流量监测技术领域,具体涉及一种基于图对比学习网络的交通流异常检测方法。The present invention belongs to the technical field of traffic flow monitoring, and in particular relates to a traffic flow anomaly detection method based on a graph contrast learning network.

背景技术Background technique

随着城市人口的持续增长,城市交通拥堵问题已经成为严重挑战,不仅对城市居民的日常生活产生影响,还对城市的经济、环境和社会可持续性产生深远影响。但目前的相关工作在检测拥堵的过程中还存在缺陷。As the urban population continues to grow, urban traffic congestion has become a serious challenge, which not only affects the daily lives of urban residents, but also has a profound impact on the economic, environmental and social sustainability of cities. However, current related work still has shortcomings in the process of detecting congestion.

首先,城市交通网络是一个动态且复杂的系统,交通拥堵在不同时间和地点变化,传统的拥堵检测方法主要关注静态路段信息,如道路拓扑和历史交通数据,难以获取动态的时空交通特征和关联。因此,需要更精确的方法来捕捉时空变化和异常情况。First, the urban traffic network is a dynamic and complex system. Traffic congestion changes at different times and locations. Traditional congestion detection methods mainly focus on static road segment information, such as road topology and historical traffic data, and it is difficult to obtain dynamic spatiotemporal traffic characteristics and associations. Therefore, more accurate methods are needed to capture spatiotemporal changes and anomalies.

其次,定义交通拥堵异常是复杂的,因为异常可以具有多种形式,如临时的道路封闭、大规模交通事故或气象因素导致的交通拥堵。需要明确的异常定义和标定方法,以便进行检测。Second, defining traffic congestion anomalies is complex because anomalies can take many forms, such as temporary road closures, large-scale traffic accidents, or traffic congestion caused by meteorological factors. Clear anomaly definitions and calibration methods are needed to facilitate detection.

发明内容Summary of the invention

为解决现有技术中的问题,本发明提出了一种基于图对比学习网络的交通流异常检测方法。In order to solve the problems in the prior art, the present invention proposes a traffic flow anomaly detection method based on a graph contrast learning network.

本发明的技术方案如下:The technical solution of the present invention is as follows:

本发明提供了一种基于图对比学习网络的交通流异常检测方法,其包括如下步骤:The present invention provides a traffic flow anomaly detection method based on a graph contrast learning network, which comprises the following steps:

S1:将城市交通网络当作图结构,图结构中每个节点表示城市的一个路段,将路段的特征嵌入到图结构中,同时构建邻接矩阵表示路段之间是否有连接,最终得到城市路段图结构;S1: The urban traffic network is regarded as a graph structure. Each node in the graph structure represents a road section in the city. The characteristics of the road section are embedded into the graph structure. At the same time, an adjacency matrix is constructed to indicate whether there is a connection between the road sections. Finally, the urban road section graph structure is obtained.

S2:为S1得到的城市路段图结构的每个节点设置一个分配向量,所述分配向量用于表示该路段属于哪个区域;所有的分配向量构成了分配矩阵Z;采用聚类方法优化分配矩阵使每个区域内的路段具有高度相似的特征且不同区域之间的特征差异性最大化,从而得到城市区域图结构;S2: Set an allocation vector for each node of the urban road segment graph structure obtained in S1, and the allocation vector is used to indicate which region the road segment belongs to; all allocation vectors constitute an allocation matrix Z; use a clustering method to optimize the allocation matrix so that the road segments in each region have highly similar features and the feature differences between different regions are maximized, thereby obtaining an urban region graph structure;

S3:构建时空编码器-解码器网络,所述时空编码器-解码器网络包括两个相同结构的时空编码器和一个时空解码器,第一时空编码器和第二时空编码器分别以城市路段图结构和城市区域图结构中的信息为输入,并分别提取城市路段图结构和城市区域图结构的特征;两个时空编码器的输出结果拼接后输入时空解码器,时空解码器捕捉输入特征中的时空关系,生成交通流在当前时刻的类别概率以区分正常和异常交通流数据;S3: construct a spatiotemporal encoder-decoder network, which includes two spatiotemporal encoders with the same structure and one spatiotemporal decoder. The first spatiotemporal encoder and the second spatiotemporal encoder take the information in the urban road segment graph structure and the urban area graph structure as input respectively, and extract the features of the urban road segment graph structure and the urban area graph structure respectively; the output results of the two spatiotemporal encoders are spliced and input into the spatiotemporal decoder, and the spatiotemporal decoder captures the spatiotemporal relationship in the input features and generates the category probability of the traffic flow at the current moment to distinguish between normal and abnormal traffic flow data;

S4:采用历史交通流数据对时空编码器一解码器网络进行训练;利用训练好的时空编码器和时空解码器进行交通流异常检测。S4: Use historical traffic flow data to train the spatiotemporal encoder-decoder network; use the trained spatiotemporal encoder and spatiotemporal decoder to detect traffic flow anomalies.

根据本发明的优选方案,所述S1具体为:According to a preferred solution of the present invention, S1 specifically comprises:

将城市交通网络当作图结构G=(V,E),每个节点表示城市的一个路段;其中,V表示节点集合,E表示边的集合;对于每个节点vi,在每个时间片段t中,定义以下路段特征:车流速度、路段占有率、路段流量,将路段特征嵌入到图结构中,图结构中的边为交通拓扑结构,同时构建邻接矩阵A,其中A[i][j]表示路段i和路段j之间是否有连接,A[i][j]=1表示路段i和路段j之间有连接,A[i][j]=0表示没有连接;最终,城市路段图结构表示为Gs=(Vs,Es,A)。The urban traffic network is regarded as a graph structure G = (V, E), where each node represents a road section in the city; V represents a node set and E represents an edge set; for each node vi , in each time segment t, the following road section characteristics are defined: traffic speed, road section occupancy rate, and road section flow rate. The road section characteristics are embedded in the graph structure. The edges in the graph structure are the traffic topology structure. At the same time, an adjacency matrix A is constructed, where A[i][j] indicates whether there is a connection between road section i and road section j, A[i][j] = 1 indicates that there is a connection between road section i and road section j, and A[i][j] = 0 indicates that there is no connection; finally, the urban road section graph structure is represented as Gs = ( Vs , Es , A).

根据本发明的优选方案,所述S2具体为:According to a preferred embodiment of the present invention, S2 is specifically:

为S1得到的城市路段图结构中的每个节点生成一个分配向量zi,表示该路段属于哪个区域;这些向量构成了分配矩阵Z=(z1,...,zn)∈RN*M,其中N表示路段数量,M表示区域数量;采用K-means聚类方法优化分配矩阵使每个区域内的路段具有高度相似的特征且不同区域之间的特征差异性最大化,优化的目标函数定义为其中,zm,n表示路段n被分配到区域m的概率;根据区域之间的距离构建邻接矩阵Ar,最终,得到城市区域图结构表示为Gr=(Vr,Er,Ar)。Generate an assignment vector z i for each node in the urban road segment graph structure obtained by S1, indicating which region the road segment belongs to; these vectors constitute the assignment matrix Z = (z 1 , ..., z n ) ∈ RN*M , where N represents the number of road segments and M represents the number of regions; use the K-means clustering method to optimize the assignment matrix so that the road segments in each region have highly similar features and the feature differences between different regions are maximized. The optimization objective function is defined as Wherein, z m,n represents the probability of road segment n being assigned to region m; an adjacency matrix A r is constructed according to the distances between regions, and finally, the urban region graph structure is obtained, which is represented as Gr = (V r , Er , A r ).

根据本发明的优选方案,所述S3中,两个所述时空编码器均包括第一图卷积层、时间自注意力层和第二图卷积层;According to a preferred embodiment of the present invention, in S3, the two spatiotemporal encoders each include a first graph convolution layer, a temporal self-attention layer, and a second graph convolution layer;

第一时空编码器的第一图卷积层对城市路段的节点级别的空间特征进行图卷积操作;其时间自注意力层整合节点级别的时间特征,获取历史交通流信息的时间依赖;其第二图卷积层进一步提高特征的抽象表示;The first graph convolution layer of the first spatiotemporal encoder performs graph convolution operations on the node-level spatial features of urban road sections; its temporal self-attention layer integrates the node-level temporal features to obtain the temporal dependency of historical traffic flow information; its second graph convolution layer further improves the abstract representation of features;

第二时空编码器的第一图卷积层对城市路段的区域级别的空间特征进行图卷积操作;其时间自注意力层整合区域级别的时间特征,获取历史交通流信息的时间依赖;其第二图卷积层进一步提高特征的抽象表示。The first graph convolution layer of the second spatiotemporal encoder performs graph convolution operations on the regional-level spatial features of urban road sections; its temporal self-attention layer integrates the regional-level temporal features to obtain the temporal dependency of historical traffic flow information; and its second graph convolution layer further improves the abstract representation of features.

根据本发明的优选方案,时空编码器-解码器网络还包括一个对比学习层,所述对比学习层获取两个时空编码器的输出,采用自监督学习方法,将正样本和负样本区分开,以提高交通流异常的检测准确度;According to a preferred embodiment of the present invention, the spatiotemporal encoder-decoder network further comprises a contrastive learning layer, which obtains the outputs of the two spatiotemporal encoders and uses a self-supervised learning method to distinguish positive samples from negative samples to improve the detection accuracy of traffic flow anomalies;

对比学习层的对比损失函数定义如下:The contrastive loss function of the contrastive learning layer is defined as follows:

其中,Ui为使用K-means聚类算法后的区域级别中每一簇中的中心节点特征,Pi是簇内样本,Ni是簇外样本,sim是嵌入向量之间的相似度度量。Among them, Ui is the central node feature in each cluster at the regional level after using the K-means clustering algorithm, Pi is the in-cluster sample, Ni is the out-cluster sample, and sim is the similarity measure between embedded vectors.

根据本发明的优选方案,所述S4中,训练时空编码器-解码器网络采用的数据为:交通网络G和历史数据X,其中X∈RT*N*V表示所有节点V在T个时间切片上的交通动态,训练的目标是使时空编码器-解码器网络在时间T+1识别哪些节点是异常的;According to a preferred solution of the present invention, in S4, the data used to train the spatiotemporal encoder-decoder network are: traffic network G and historical data X, where X∈R T*N*V represents the traffic dynamics of all nodes V in T time slices, and the training goal is to enable the spatiotemporal encoder-decoder network to identify which nodes are abnormal at time T+1;

所述利用训练好的时空编码器和时空解码器进行交通流异常检测为:输入当前时刻的城市路段图结构和城市区域图结构的信息,利用训练好的时空编码器和时空解码器预测下一时刻的交通流异常情况。The method of using the trained spatiotemporal encoder and spatiotemporal decoder to detect traffic flow anomalies is as follows: inputting information on the urban road segment graph structure and the urban area graph structure at the current moment, and using the trained spatiotemporal encoder and spatiotemporal decoder to predict the traffic flow anomaly at the next moment.

本发明的有益效果包括:The beneficial effects of the present invention include:

本发明设计两层级的图表示,包括区域级别和节点级别,用于高效获取全局和地区内的交通规律。The present invention designs a two-level graph representation, including a regional level and a node level, for efficiently acquiring global and regional traffic rules.

本发明以城市路网结构和交通流的占有率、速度和流量信息为路段特征,设计区域聚类算法形成城市区域表示,构建城市路段图结构和城市区域图结构;基于两个城市交通图结构,设计参数共享的时空编码器-解码器网络,网络由图卷机层和时间自注意力层组成的时空注意力模块,和设计的流量变化提取对比学习层组成,在不同时间和动态环境下高效检测交通拥堵和异常路段。The present invention takes the urban road network structure and the occupancy rate, speed and flow information of traffic flow as the road section characteristics, designs a regional clustering algorithm to form the urban area representation, and constructs the urban road section graph structure and the urban area graph structure; based on the two urban traffic graph structures, a parameter-sharing spatiotemporal encoder-decoder network is designed. The network consists of a spatiotemporal attention module composed of a graph convolution layer and a temporal self-attention layer, and a designed flow change extraction contrast learning layer, which can efficiently detect traffic congestion and abnormal sections under different time and dynamic environments.

附图说明BRIEF DESCRIPTION OF THE DRAWINGS

图1是本发明基于图对比学习网络的交通流异常检测方法的流程图。FIG1 is a flow chart of a method for detecting anomalies in traffic flow based on a graph contrast learning network according to the present invention.

具体实施方式Detailed ways

下面结合具体实施方式对本发明做进一步阐述和说明。所述实施例仅是本公开内容的示范且不圈定限制范围。本发明中各个实施方式的技术特征在没有相互冲突的前提下,均可进行相应组合。The present invention is further described and illustrated below in conjunction with specific embodiments. The embodiments are merely exemplary of the present disclosure and do not define the scope of limitation. The technical features of each embodiment of the present invention may be combined accordingly without conflicting with each other.

如图1所示,本发明的基于图对比学习网络的交通流异常检测方法包括如下步骤:As shown in FIG1 , the traffic flow anomaly detection method based on graph contrast learning network of the present invention comprises the following steps:

S1:将城市交通网络当作图结构,图结构中每个节点表示城市的一个路段,将路段的特征嵌入到图结构中,同时构建邻接矩阵表示路段之间是否有连接,最终得到城市路段图结构;S1: The urban traffic network is regarded as a graph structure. Each node in the graph structure represents a road section in the city. The characteristics of the road section are embedded into the graph structure. At the same time, an adjacency matrix is constructed to indicate whether there is a connection between the road sections. Finally, the urban road section graph structure is obtained.

S2:为S1得到的城市路段图结构的每个节点设置一个分配向量,所述分配向量用于表示该路段属于哪个区域;所有的分配向量构成了分配矩阵Z;采用聚类方法优化分配矩阵使每个区域内的路段具有高度相似的特征且不同区域之间的特征差异性最大化,从而得到城市区域图结构;S2: Set an allocation vector for each node of the urban road segment graph structure obtained in S1, and the allocation vector is used to indicate which region the road segment belongs to; all allocation vectors constitute an allocation matrix Z; use a clustering method to optimize the allocation matrix so that the road segments in each region have highly similar features and the feature differences between different regions are maximized, thereby obtaining an urban region graph structure;

S3:构建时空编码器-解码器网络,所述时空编码器-解码器网络包括两个相同结构的时空编码器和一个时空解码器,两个时空编码器分别以城市路段图结构和城市区域图结构中的信息为输入,并分别提取城市路段图结构和城市区域图结构的特征;两个时空编码器的输出结果拼接后输入时空解码器,时空解码器捕捉输入特征中的时空关系,生成交通流在当前时刻的类别概率以区分正常和异常交通流数据;S3: construct a spatiotemporal encoder-decoder network, which includes two spatiotemporal encoders with the same structure and one spatiotemporal decoder. The two spatiotemporal encoders take the information in the urban road segment graph structure and the urban area graph structure as input respectively, and extract the features of the urban road segment graph structure and the urban area graph structure respectively; the output results of the two spatiotemporal encoders are spliced and input into the spatiotemporal decoder. The spatiotemporal decoder captures the spatiotemporal relationship in the input features and generates the category probability of the traffic flow at the current moment to distinguish between normal and abnormal traffic flow data;

S4:采用历史交通流数据对时空编码器-解码器网络进行训练;利用训练好的时空编码器和时空解码器进行交通流异常检测。S4: Use historical traffic flow data to train the spatiotemporal encoder-decoder network; use the trained spatiotemporal encoder and spatiotemporal decoder to detect traffic flow anomalies.

具体的,在本发明中,采用了两层级的图结构表示方法,分别处理了城市路段的区域级别和节点级别特征。这两层级的表示方法不仅有助于提取高维度的交通数据特征,还能够充分捕捉城市交通在不同空间尺度下的规律。Specifically, in the present invention, a two-level graph structure representation method is adopted to process the regional level and node level features of urban road sections respectively. This two-level representation method not only helps to extract high-dimensional traffic data features, but also can fully capture the laws of urban traffic at different spatial scales.

在本发明的一个具体实施例中,所述S1为:本发明将城市交通网络当作图结构G=(V,E),每个节点表示城市的一个路段。其中,V表示节点集合,E表示边的集合。对于每个节点vi,在每个时间片段t中,定义以下特征:车流速度(sp),路段占有率(op),路段流量(fl),将路段的特征嵌入到图结构中,图中的边为交通拓扑结构,同时构建邻接矩阵(AdjacencyMatrix),表示为一个邻接矩阵A,其中A[i][j]表示路段i和路段j之间是否有连接。这通常是一个二进制矩阵,其中A[i][j]=1表示路段i和路段j之间有连接,A[i][j]=0表示没有连接。最终,城市路段图结构表示为Gs=(Vs,Es,A)。In a specific embodiment of the present invention, S1 is: the present invention regards the urban traffic network as a graph structure G = (V, E), and each node represents a road section in the city. Wherein, V represents a node set, and E represents a set of edges. For each node vi , in each time segment t, the following features are defined: traffic speed (sp), road section occupancy (op), road section flow (fl), and the features of the road section are embedded in the graph structure. The edges in the graph are traffic topological structures, and an adjacency matrix (AdjacencyMatrix) is constructed at the same time, which is represented as an adjacency matrix A, where A[i][j] indicates whether there is a connection between road section i and road section j. This is usually a binary matrix, where A[i][j] = 1 indicates that there is a connection between road section i and road section j, and A[i][j] = 0 indicates that there is no connection. Finally, the urban road section graph structure is represented as Gs = ( Vs , Es , A).

在本发明的一个具体实施例中,所述S2为:由于城市中的路段有主干道、支路等差别,结合城市不同地段功能不同,会形成一个个功能区域,交通流量和速度很受道路功能和城市功能影响。因此,本发明为每个路段(节点)生成一个分配向量zi,表示该路段属于哪个区域。这些向量构成了分配矩阵Z=(z1,...,zn)∈RN*M,其中N表示路段数量,M表示区域数量。为了更好的表示城市区域且确定区域数量M,本发明以最优的聚类分配矩阵Z确保了每个区域内的路段在类内相似度最高,同时不同区域之间的差异性最大为原则,生成最优的聚类分配矩阵。优化的目标函数可以定义为最大化类内相似度和最小化类间差异性的组合,本发明通过迭代更新聚类分配矩阵Z的元素来实现。其中,目标函数的定义为:In a specific embodiment of the present invention, S2 is: Since the road sections in the city are different, such as main roads and branch roads, combined with the different functions of different sections in the city, functional areas will be formed, and the traffic flow and speed are greatly affected by the road function and the city function. Therefore, the present invention generates an allocation vector z i for each road section (node), indicating which area the road section belongs to. These vectors constitute the allocation matrix Z = (z 1 , ..., z n ) ∈ RN*M , where N represents the number of road sections and M represents the number of areas. In order to better represent the urban area and determine the number of areas M, the present invention uses the optimal cluster allocation matrix Z to ensure that the road sections in each area have the highest similarity within the class and the maximum difference between different areas as the principle, and generates the optimal cluster allocation matrix. The optimization objective function can be defined as a combination of maximizing the similarity within the class and minimizing the difference between classes. The present invention is achieved by iteratively updating the elements of the cluster allocation matrix Z. Among them, the objective function is defined as:

其中zn,k表示聚类分配矩阵Z的元素。根据区域之间的距离构建邻接矩阵Ar,最终,城市区域图结构表示为Gr=(Vr,Er,Ar)。Where zn, k represents the elements of the cluster assignment matrix Z. The adjacency matrix A r is constructed according to the distances between regions. Finally, the urban region graph structure is represented as G r =(V r , E r , A r ).

在城市中,丰富的交通流规律,例如早晚高峰、周末出行、节假日变化等,特征信息需要在时空上进行融合,以便在不同时间和动态环境下高效检测交通拥堵和异常路段。为了实现时空融合和更准确的异常检测,本发明设计了适合检测交通流异常的时空编码器-解码器网络。In cities, there are many traffic flow patterns, such as morning and evening rush hours, weekend travel, holiday changes, etc. The feature information needs to be fused in time and space to efficiently detect traffic congestion and abnormal sections in different time and dynamic environments. In order to achieve time and space fusion and more accurate anomaly detection, the present invention designs a time and space encoder-decoder network suitable for detecting traffic flow anomalies.

本发明的时空编码器由两层图卷积(GCN)、时间自注意力层的三明治结构组成,对于城市区域图结构和城市路段图结构的编码器结构相同。首先,编码器的第一步是对城市路段的区域级别和节点级别的空间特征分别进行图卷积操作。The spatiotemporal encoder of the present invention is composed of a sandwich structure of two layers of graph convolution (GCN) and a temporal self-attention layer, and the encoder structure for the urban area graph structure and the urban road section graph structure is the same. First, the first step of the encoder is to perform graph convolution operations on the spatial features of the area level and node level of the urban road section respectively.

这是通过应用GCN来实现的。This is achieved by applying GCN.

其中,Hl是第一图卷积层操作后的特征表示,σ(·)是激活函数,A是输入的相应图结构的邻接矩阵,D是度矩阵,W1是第一图卷积层的权重矩阵,下标i表示第i个时间步,X为输入的相应图结构的节点特征信息。Among them, Hl is the feature representation after the first graph convolutional layer operation, σ(·) is the activation function, A is the adjacency matrix of the corresponding graph structure of the input, D is the degree matrix, W1 is the weight matrix of the first graph convolutional layer, the subscript i represents the i-th time step, and X is the node feature information of the corresponding graph structure of the input.

接下来是一层时间自注意力层:时空编码器的关键组成部分是时间自注意力层。这个层负责分别整合区域和节点级别的时间特征,获取历史交通流信息的时间依赖。通过引入时间注意力机制,该模块能够捕捉不同路段在获取空间信息后的时间相关性,考虑城市交通在不同时间和动态环境下的变化。时间自注意力层是交通流异常检测中用于捕捉不同时间步之间的依赖关系的重要组件。在这里,本实施例将详细描述时间自注意力层,特别关注时间突变部分。时间自注意力层的表示如下:Next is a temporal self-attention layer: The key component of the spatiotemporal encoder is the temporal self-attention layer. This layer is responsible for integrating the temporal features at the regional and node levels respectively, and obtaining the temporal dependency of historical traffic flow information. By introducing the temporal attention mechanism, this module is able to capture the temporal correlation of different road sections after obtaining spatial information, considering the changes of urban traffic in different time and dynamic environments. The temporal self-attention layer is an important component for traffic flow anomaly detection to capture the dependencies between different time steps. Here, this embodiment will describe the temporal self-attention layer in detail, with special attention to the temporal mutation part. The representation of the temporal self-attention layer is as follows:

其中,查询(Q)、键(K)和值(V)的计算公式如下:The calculation formulas for query (Q), key (K), and value (V) are as follows:

Q=HlWQ,K=HlWk,V=HlWv Q=H l W Q ,K=H l W k ,V=H l W v

Hl表示第一图卷机层的输出,为时间自注意力层的输入,WQ、WK和WV分别是查询、键和值的线性变换权重矩阵。H l represents the output of the first graph convolution layer and the input of the temporal self-attention layer. W Q , W K and W V are the linear transformation weight matrices of query, key and value, respectively.

利用注意力权重Attentionij(Q,K,V)对邻居节点的值向量进行加权求和,得到聚合特征 Use the attention weight Attention ij (Q, K, V) to perform weighted summation on the value vectors of neighboring nodes to obtain the aggregated features

结合聚合特征和节点自身的特征,通过一个非线性变换来更新节点的特征:Combined aggregation features And the characteristics of the node itself, update the characteristics of the node through a nonlinear transformation:

其中,Wl是学习的权重矩阵;是更新后的特征,即时间自注意力层的输出。Among them, W l is the learned weight matrix; is the updated feature, i.e., the output of the temporal self-attention layer.

在时间注意力层之后,本发明进行了第二层的图卷积操作,以进一步提高特征的抽象表示。After the temporal attention layer, the present invention performs a second layer of graph convolution operation to further improve the abstract representation of features.

所述第二图卷积层操作为:The second graph convolutional layer operates as follows:

其中,表示时间自注意力层的输出与邻接矩阵相乘,W2是第二图卷积层的权重矩阵。这一层的输出/>包含了更高级的区域级特征。in, represents the output of the temporal self-attention layer multiplied by the adjacency matrix, and W 2 is the weight matrix of the second graph convolutional layer. The output of this layer/> Includes more advanced regional level features.

进一步的,本发明还通过时间自注意力机制的突变掩码对时间上的突变获取额外关注。之后,本发明设计对比学习层来提高交通流异常的检测准确度。对比学习是一种强大的自监督学习方法,主要思想是学习如何将正样本(相似的数据点)与负样本(不相似的数据点)区分开来。在交通流异常检测中,异常应该在节点属性角度上不同于周围环境。从空间角度中,节点和周围相似度高为正样本的数据点。选择远离时间步的数据点,或者选择来自不同区域的数据点作为负样本来学习,因为这些数据点更可能是不相似的。对比学习的目标是让模型将正样本和负样本区分开。本发明通过构建一个对比损失函数来实现,其定义如下:Furthermore, the present invention also obtains additional attention to the mutations in time through the mutation mask of the temporal self-attention mechanism. Afterwards, the present invention designs a contrastive learning layer to improve the detection accuracy of traffic flow anomalies. Contrastive learning is a powerful self-supervised learning method. The main idea is to learn how to distinguish positive samples (similar data points) from negative samples (dissimilar data points). In traffic flow anomaly detection, the anomaly should be different from the surrounding environment from the perspective of node attributes. From a spatial perspective, the data points with high similarity between the node and the surrounding are positive samples. Data points far away from the time step, or data points from different areas are selected as negative samples for learning, because these data points are more likely to be dissimilar. The goal of contrastive learning is to allow the model to distinguish positive samples from negative samples. The present invention is achieved by constructing a contrast loss function, which is defined as follows:

其中,Ui为使用K-means聚类算法后的区域级别中每一簇中的中心节点特征,Pi是簇内样本,Nj是簇外样本,sim是嵌入向量之间的相似度度量。Among them, Ui is the central node feature in each cluster at the regional level after using the K-means clustering algorithm, Pi is the in-cluster sample, Nj is the out-cluster sample, and sim is the similarity measure between embedded vectors.

本发明的目标是还原或生成原始的交通流数据。为了实现这一目标,本发明将两层级城市交通图网络的高维度表示拼接,再使用一层GCN(图卷积网络)和一层MLP(多层感知器)的时空解码器结构来重构常规交通环境中的原始交通流。其中GCN用于捕捉时空关系,而MLP用于进一步处理和生成输出。在交通流异常检测中,本发明的目标为检测交通流在当前时刻的类别概率,以区分正常和异常交通流数据。此处本发明采用交叉熵损失,其中模型的输出是概率分布,将交通流异常检测任务被视为一个二分类问题(正常和异常),损失函数定义如下:The goal of the present invention is to restore or generate the original traffic flow data. In order to achieve this goal, the present invention splices the high-dimensional representation of the two-level urban traffic graph network, and then uses a spatiotemporal decoder structure of a layer of GCN (graph convolutional network) and a layer of MLP (multi-layer perceptron) to reconstruct the original traffic flow in a regular traffic environment. GCN is used to capture spatiotemporal relationships, while MLP is used for further processing and generating outputs. In traffic flow anomaly detection, the goal of the present invention is to detect the category probability of traffic flow at the current moment to distinguish between normal and abnormal traffic flow data. Here, the present invention adopts cross entropy loss, in which the output of the model is a probability distribution, and the traffic flow anomaly detection task is regarded as a binary classification problem (normal and abnormal), and the loss function is defined as follows:

其中,N表示城市路段的数量,yi是实际的类别标签(0和1,正常和异常),是模型预测的该路段交通流异常的概率。Where N represents the number of urban road segments, yi is the actual category label (0 and 1, normal and abnormal), is the probability of abnormal traffic flow on this road section predicted by the model.

训练时空编码器-解码器网络采用的数据为:交通网络G和历史数据X,其中X∈RT *N*V表示所有节点V在T个时间切片上的交通动态,训练的目标是使时空编码器-解码器网络在时间T+l识别哪些节点是异常的。时空编码器-解码器网络训练好后,输入当前时刻的城市路段图结构和城市区域图结构的信息,利用训练好的时空编码器和时空解码器预测下一时刻的交通流异常情况,从而实现交通流异常检测。本发明通过考虑城市路网结构和多种交通流特征,该发明可以在不同时间和动态环境下高效地对交通情况进行建模,有助于更好地理解城市交通的时空特征;能够处理城市交通的实时和动态变化,有助于在不同情境下实时识别拥堵和异常情况,提高了交通管理的实效性。The data used to train the spatiotemporal encoder-decoder network are: traffic network G and historical data X, where X∈R T *N*V represents the traffic dynamics of all nodes V in T time slices, and the training goal is to enable the spatiotemporal encoder-decoder network to identify which nodes are abnormal at time T+l. After the spatiotemporal encoder-decoder network is trained, the information of the urban road segment graph structure and the urban area graph structure at the current moment is input, and the trained spatiotemporal encoder and spatiotemporal decoder are used to predict the traffic flow abnormality at the next moment, thereby realizing traffic flow abnormality detection. By considering the urban road network structure and various traffic flow characteristics, the present invention can efficiently model traffic conditions in different time and dynamic environments, which helps to better understand the spatiotemporal characteristics of urban traffic; it can handle the real-time and dynamic changes of urban traffic, which helps to identify congestion and abnormal conditions in real time under different scenarios, and improves the effectiveness of traffic management.

以上所述实施例仅表达了本发明的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对本发明专利范围的限制。对于本领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干变形和改进,这些都属于本发明的保护范围。The above-mentioned embodiments only express several implementation methods of the present invention, and the description is relatively specific and detailed, but it cannot be understood as limiting the scope of the present invention. For ordinary technicians in this field, several modifications and improvements can be made without departing from the concept of the present invention, which all belong to the protection scope of the present invention.

Claims (10)

1. The traffic flow anomaly detection method based on the graph comparison learning network is characterized by comprising the following steps of:
s1: taking the urban traffic network as a drawing structure, wherein each node in the drawing structure represents one road section of a city, embedding the characteristics of the road section into the drawing structure, and constructing an adjacent matrix to represent whether the road sections are connected or not, so as to finally obtain the drawing structure of the urban road section;
s2: setting an allocation vector for each node of the urban road section graph structure obtained in the step S1, wherein the allocation vector is used for indicating which region the road section belongs to; all allocation vectors form an allocation matrix Z; optimizing the distribution matrix by adopting a clustering method to ensure that road sections in each region have highly similar characteristics and the characteristic difference between different regions is maximized, so as to obtain a city region diagram structure;
s3: constructing a space-time encoder-decoder network, wherein the space-time encoder-decoder network comprises two space-time encoders with the same structure and a space-time decoder, and the first space-time encoder and the second space-time encoder respectively take information in a city road map structure and a city area map structure as input and respectively extract the characteristics of the city road map structure and the city area map structure; the output results of the two space-time encoders are spliced and then input into a space-time decoder, the space-time decoder captures the space-time relationship in the input characteristics, and the class probability of the traffic flow at the current moment is generated to distinguish normal traffic flow data from abnormal traffic flow data;
s4: training a space-time encoder-decoder network using historical traffic stream data; and detecting abnormal traffic flow by using the trained space-time encoder and the trained space-time decoder.
2. The traffic flow anomaly detection method based on graph comparison learning network as claimed in claim 1, wherein the step S1 specifically comprises:
taking the urban traffic network as a mapping structure G= (V, E), wherein each node represents one road section of a city; wherein V represents a node set and E represents a set of edges; for each node v i In each time segment t, the following road segment characteristics are defined: the traffic flow speed, the road section occupancy and the road section flow are embedded into a graph structure, the edges in the graph structure are traffic topological structures, and an adjacency matrix A is constructed at the same time, wherein A [ i ]][j]Indicating whether there is a connection between road section i and road section j, ai][j]=1 indicates that there is a connection between the road section i and the road section j, a [ i ]][j]=0 indicates no connection; finally, the city road map structure is denoted as G s =(V s ,E s ,A)。
3. The traffic flow anomaly detection method based on graph comparison learning network as claimed in claim 1, wherein the step S2 is specifically:
generating an allocation vector z for each node in the city road graph structure obtained in S1 i Indicating which region the road section belongs to; these vectors form an allocation matrix z= (Z) 1 ,...,z n )∈R N*M Where N represents the number of road segments and M represents the number of areas; optimizing distribution by adopting K-means clustering methodThe matrix maximizes the feature differences between the different regions with highly similar features for road segments within each region, and the optimized objective function is defined asWherein z is m,n Representing the probability that road segment n is assigned to region m; constructing an adjacency matrix A based on the distance between regions r Finally, the resulting urban area map structure is denoted as G r =(V r ,E r ,A r )。
4. The traffic flow anomaly detection method based on graph contrast learning network of claim 1, wherein in S3, both the space-time encoders comprise a first graph convolutional layer, a temporal self-attention layer, and a second graph convolutional layer;
a first graph convolution layer of a first space-time encoder performs graph convolution operation on the spatial characteristics of the node level of the urban road section; the time self-attention layer integrates the time characteristics of the node level, and the time dependence of the historical traffic flow information is obtained; the second graph convolution layer further improves abstract representation of the features;
the first graph convolution layer of the second space-time encoder performs graph convolution operation on the spatial characteristics of the regional level of the urban road section; the time self-attention layer integrates the time characteristics of the regional level, and the time dependence of the historical traffic flow information is obtained; its second graph convolution layer further improves the abstract representation of the feature.
5. The traffic flow anomaly detection method based on graph comparison learning network of claim 4, wherein in S3, the first graph convolution layer and the second graph convolution layer are implemented by GCN;
the first graph convolution layer operates to:
wherein H is l Is the firstThe feature representation after the operation of a graph convolution layer, σ (·) is the activation function, a is the adjacency matrix of the corresponding graph structure of the input, D is the degree matrix, W 1 Is the weight matrix of the first graph convolution layer, the subscript i represents the ith time step, and X is the node characteristic information of the corresponding graph structure.
6. The traffic flow anomaly detection method based on graph comparison learning network of claim 4, wherein in S3, the temporal self-attention layer is represented as follows:
wherein d k Is the dimension of the query and key; the calculation formula for query Q, key K and value V is as follows:
Q=H l W Q ,K=H l W k ,V=H l W v
H l representing the output of the first coiler layer, being the input of the temporal self-attention layer, W Q 、W K And W is V A linear transformation weight matrix of query, key and value, respectively;
attention weighting ij (Q, K, V) weighting and summing the value vectors of the neighbor nodes to obtain an aggregate characteristic
Incorporating polymeric featuresAnd the characteristics of the node itself, updating the characteristics of the node by a nonlinear transformation:
wherein W is l Is a learned weight matrix;is an updated feature, i.e., the output of the immediate self-attention layer.
7. The traffic flow anomaly detection method based on graph-contrast learning network of claim 4, wherein the second graph convolution layer operates to:
wherein,the output representing the temporal self-attention layer is multiplied by the adjacency matrix, W 2 Is the weight matrix of the second graph convolutional layer.
8. The traffic flow anomaly detection method based on the graph contrast learning network of claim 4, wherein the space-time encoder-decoder network further comprises a contrast learning layer, the contrast learning layer obtains the outputs of the two space-time encoders, and a self-supervision learning method is adopted to distinguish positive samples from negative samples so as to improve the detection accuracy of traffic flow anomalies;
the contrast loss function of the contrast learning layer is defined as follows:
wherein U is i To use the central node feature in each cluster in the region level after the K-means clustering algorithm, P i Is an intra-cluster sample, N j Is an out-of-cluster sample and sim is a similarity measure between embedded vectors.
9. The traffic flow anomaly detection method based on graph contrast learning network of claim 1, wherein the space-time decoder in S3 comprises a layer of graph convolution network and a layer of multi-layer perceptron; the graph convolution network is used for capturing the space-time relationship, and the multi-layer perceptron is used for further processing and generating output;
the output of the space-time decoder is a probability distribution, the traffic flow anomaly detection task is regarded as a classification problem that distinguishes between normal and anomaly, and the loss function of the space-time decoder is defined as follows:
wherein N represents the number of city segments, y i Is the actual class label, i.e., 0 and 1, normal and abnormal,is the probability of the model predicted traffic flow anomaly for that road segment.
10. The traffic flow anomaly detection method based on graph-contrast learning network of claim 1, wherein in S4, the training space-time encoder-decoder network adopts the following data: traffic network G and history data X, where X ε R T*N*V Representing traffic dynamics of all nodes V over T time slices, the goal of training is to have the space-time encoder-decoder network identify which nodes are abnormal at time t+1;
the traffic flow anomaly detection by using the trained space-time encoder and the trained space-time decoder is as follows: and inputting the information of the urban road map structure and the urban area map structure at the current moment, and predicting the abnormal condition of the traffic flow at the next moment by using the trained space-time encoder and the trained space-time decoder.
CN202311663789.4A 2023-12-06 2023-12-06 A traffic flow anomaly detection method based on graph contrastive learning network Pending CN117894168A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311663789.4A CN117894168A (en) 2023-12-06 2023-12-06 A traffic flow anomaly detection method based on graph contrastive learning network

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311663789.4A CN117894168A (en) 2023-12-06 2023-12-06 A traffic flow anomaly detection method based on graph contrastive learning network

Publications (1)

Publication Number Publication Date
CN117894168A true CN117894168A (en) 2024-04-16

Family

ID=90643648

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311663789.4A Pending CN117894168A (en) 2023-12-06 2023-12-06 A traffic flow anomaly detection method based on graph contrastive learning network

Country Status (1)

Country Link
CN (1) CN117894168A (en)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118587898A (en) * 2024-08-07 2024-09-03 电子科技大学长三角研究院(衢州) A cross-city traffic flow prediction method based on pre-training model
CN119007436A (en) * 2024-07-31 2024-11-22 北京交通发展研究院 Long-term traffic abnormality detection method based on double-branch space-time contrast learning
CN119228245A (en) * 2024-12-02 2024-12-31 福建理工大学 Dynamic processing system of sorting data of IoT distribution terminal based on cloud computing
CN120412286A (en) * 2025-07-01 2025-08-01 江西师范大学 Abnormal traffic flow detection method and system based on dynamic graph

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN119007436A (en) * 2024-07-31 2024-11-22 北京交通发展研究院 Long-term traffic abnormality detection method based on double-branch space-time contrast learning
CN119007436B (en) * 2024-07-31 2025-04-18 北京交通发展研究院 A long-term traffic anomaly detection method based on dual-branch spatiotemporal contrastive learning
CN118587898A (en) * 2024-08-07 2024-09-03 电子科技大学长三角研究院(衢州) A cross-city traffic flow prediction method based on pre-training model
CN119228245A (en) * 2024-12-02 2024-12-31 福建理工大学 Dynamic processing system of sorting data of IoT distribution terminal based on cloud computing
CN120412286A (en) * 2025-07-01 2025-08-01 江西师范大学 Abnormal traffic flow detection method and system based on dynamic graph

Similar Documents

Publication Publication Date Title
Zheng et al. Gman: A graph multi-attention network for traffic prediction
Wang et al. Modeling inter-station relationships with attentive temporal graph convolutional network for air quality prediction
CN109492830B (en) A method for predicting emission concentration of mobile pollution sources based on spatiotemporal deep learning
CN117894168A (en) A traffic flow anomaly detection method based on graph contrastive learning network
CN114944053B (en) Traffic flow prediction method based on space-time hypergraph neural network
Sun et al. DxNAT—Deep neural networks for explaining non-recurring traffic congestion
CN105493109B (en) Inferred using the air quality of multiple data sources
Yuan et al. Spatio-temporal graph convolutional networks for road network inundation status prediction during urban flooding
CN115376317B (en) A Traffic Flow Prediction Method Based on Dynamic Graph Convolution and Temporal Convolutional Network
CN112767682A (en) Multi-scale traffic flow prediction method based on graph convolution neural network
CN114287023B (en) Multi-sensor learning system for traffic prediction
CN111179592B (en) Urban traffic prediction method and system based on spatio-temporal data flow fusion analysis
CN118072873B (en) A method for predicting air quality
CN108986453A (en) A kind of traffic movement prediction method based on contextual information, system and device
CN118521170B (en) Time-space-aware building equipment operation risk identification model training method and device
CN115860286B (en) Air quality prediction method and system based on time sequence gate mechanism
Jiang et al. Bi‐GRCN: A Spatio‐Temporal Traffic Flow Prediction Model Based on Graph Neural Network
CN106935034A (en) Towards the regional traffic flow forecasting system and method for car networking
CN115175192A (en) Vehicle networking intrusion detection method based on graph neural network
CN113345236A (en) Time-space traffic state prediction method based on Transformer network
CN116612645A (en) Expressway service area vehicle flow prediction method
CN119229651A (en) A method, device and readable storage medium for predicting urban traffic flow based on big data of geographic information
CN115456238B (en) A method for urban travel demand prediction based on dynamic multi-view coupled graph convolution
CN111815075A (en) A forecasting method of traffic travel demand under major public health events
Rasaizadi et al. Short‐Term Prediction of Traffic State for a Rural Road Applying Ensemble Learning Process

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载