Disclosure of Invention
Aiming at the defects of the prior art, the invention provides a graph node sequence embedding model based on the graph similarity searching method of nerve subgraph matching, which is used for judging whether subgraph isomorphism exists between a query graph and a partition by the phase position of the query graph and the sequence embedded in a high-dimensional space generated by the partition, thereby not only avoiding the traditional subgraph isomorphism test, but also generating partition embedding in an off-line stage, realizing quick judgment of isomorphism only by comparing the relative positions of the query graph and each partition embedded in the high-dimensional space during query, and greatly shortening the deducing time of the model.
The method for searching the graph similarity based on the neural subgraph matching comprises the following specific steps:
S1, dividing a data graph into a plurality of mutually exclusive half graphs, embedding a sub graph as a key, constructing an inverted index by taking a data graph set containing the sub graph as a value, constructing a coordinate index based on the size information of the data graph, and realizing hierarchical filtering by utilizing the mapping relation between the two layers of indexes.
S2, processing half by adopting a self-loop or loop-free strategy, and designing a sequential embedding model so that the embedding of two graphs with sub-graph isomorphic relations also has the same partial sequence position in a high-dimensional space.
And S3, inputting a query graph, screening a preliminary candidate set through a coordinate index, further screening the candidate set through an inverted index, accurately calculating the graph editing distance between the query graph and the candidate graph, and obtaining a final result set.
The specific steps of S1 include:
S11, mapping any data graph g into a two-dimensional coordinate system in a coordinate (|V g|,|Eg |), namely a vertex-side based mode, wherein an x coordinate and a y coordinate respectively represent the number of the vertices and the number of the sides of the graph g.
For graph database G, a set of points (|v g|,|Eg |) G e G can be obtained, and these points can form a rectangular area a= [ x min,xmax]×[ymin,ymax ], where x min/xmax and y min/ymax are the minimum and maximum numbers of nodes and edges, respectively. Given a query graph q and a threshold T, a query rectangle Aq is defined as a rectangle composed of a set of points (x, y): x-V q||+|y-|Eq |tau;
s13, giving a graph g which is divided into (tau+k) half graphs, wherein tau is a threshold value and k (k is equal to or larger than 1) is an integer parameter, and the set of the half graphs is P (g). For a given query graph q, if GED (g, q). Ltoreq.τ, there are at least k half graphs in the half graph set P (g): P i1,pi2,...,pik ε P (g), satisfy For any data graph G e G, its sub-graph set is P (G) = { P 1,p2,...,pτ+k }. If it isThen p i is referred to as the matching subgraph, otherwise it is referred to as the unmatched subgraph. If the number of matching subgraphs in the subgraph set P is less than k, then the graph edit distance GED (g, q) must be greater than τ.
And S14, dividing all the data graphs, and constructing an inverted index I (p) taking a division sub-graph as a key, and taking a data graph set containing the sub-graph as a value. For a given query graph q, ifAll data graphs containing partitions p can be quickly found in graph database G.
The specific steps of S2 include:
And S21, connecting the far ends and the near end nodes of all the halves in the half graph, reforming the halves into self-loops, and in the process of message transmission, not transmitting the message to the nodes connected by the self-loops reformed by the halves, and only embedding the degree information of the halves.
And S22, processing the node characteristics through linear transformation to obtain hidden layer representation. The model employs k layers of graph volumes to aggregate local neighborhood information and iteratively update node representations.
And S23, adding leachable jump connections between different convolution layers, wherein the connections are represented by a parameter matrix S epsilon R L×L, and L is the network layer number. During the training process, the parameter matrix is used to determine the optimal contribution of each layer of output to the final node representation.
S24, after the k-layer convolution, the node representations are aggregated by a global pooling operation to generate a fixed-size graph insert.
S25 given a target graph instance G T=(VT,ET) and a query graph instance G Q=(VQ,EQ), where V T is the target graph node set, E T is the target graph edge set, V Q is the query graph node set, and E Q is the query graph edge set. The level embedding Z Q of level embedding Z T,GQ of G T can be obtained by a sequential embedding model, and if G Q is a isomorphic subgraph of G T, then the position of Z Q in the embedding space should be in the "lower left corner" of Z T according to the sequential embedding theory.
S26, training and generating an embedded GNN model by using the maximum marginal loss.
The specific steps of S3 include:
s31, given a query graph q and a query threshold tau, calculating a query region, and taking the divided subgraphs corresponding to all graphs in the query region as the subgraphs to be searched of the inverted index through the mapping relation between the divided subgraphs and the data graph.
And S32, before the inverted index is queried, firstly creating a score array S for recording the number of matched partitions existing between the current query graph and each data graph. And inputting the query graph into a neural subgraph matching model to obtain query graph embedding, and for each to-be-searched partition, sequentially comparing the position relation of the query graph embedding and the partition embedding in an embedding space, wherein if Z (p) is less than or equal to Z (q), p is an isomorphic subgraph of the query graph q, the score S [ g ] +1 of all the data graphs comprising the partition is the candidate set when the score in the score group S is greater than or equal to k until all the to-be-searched partitions are completely compared.
And S33, verifying the candidate set by using an accurate GED verification algorithm to obtain a final query result.
Compared with the prior art, the method has the advantages that on all data sets, the similarity search is performed by using the method without losing any real result, and compared with other learning-based methods, the accuracy is greatly improved. Secondly, in order to improve the efficiency of searching the similar graphs, an index mapping strategy is designed, a quick index is generated by using the statistical information of the data graphs, and the hierarchical filtering of the similar graphs is realized by maintaining the mapping relation between the quick index and the partition index.
Detailed Description
The present invention is further illustrated in the following drawings and detailed description, which are to be understood as being merely illustrative of the invention and not limiting the scope of the invention.
In the embodiment, as shown in fig. 1, in the real graph database, the information and the scale of the graphs often have large differences, and the graph pairs with small differences in similarity aiming at the graph similarity query problem exist, so that a large number of false positive samples which are easy to distinguish exist in the database. Therefore, a label index based on graph statistical information is established, and hierarchical filtering is realized by using the mapping relation between the two layers of indexes. For any data graph g, it is mapped in a two-dimensional coordinate system in coordinates (|vg|, |eg|), that is, in a vertex-side based manner, where x-and y-coordinates represent the number of vertices and the number of sides of the graph g, respectively. Thus, for graph database G, a set of points (|V g|,|Eg |) G ε G can be obtained, and these points can make up a rectangular area A= [ x min,xmax]×[ymin,ymax ], where x min/xmax and y min/ymax are the minimum and maximum numbers of nodes and edges, respectively. Given a query graph q and a threshold τ, a query rectangle A q is defined as a rectangle consisting of a set of points (x, y): x- |V q||+|y-|Eq ||τ.
The coordinate mapping is focused on the size of the graph, and a boundary condition is considered, so that the undesirable graphs are eliminated from the graph scale, and the method is a coarse-granularity filtering means to reduce the time cost of subsequent fine filtering. Therefore, after the coarse granularity filtering of the coordinate mapping layer, the number of data graphs which need to participate in the fine granularity filtering of the subsequent multiple graph division is obviously reduced, and the index construction time of the subsequent fine granularity filtering method can be obviously shortened.
S13. theorem 1 given a graph g, the graph is divided into (τ+k) half-graphs, the set of half-graphs is P (g), where T is a threshold value and k (k≥1) is an integer parameter. For a given query graph q, if GED (g, q). Ltoreq.τ, there are at least k half graphs in the half graph set P (g): P i1,pi2,...,pik ε P (g), satisfyFor any data graph G e G, its partition set is P (G) = { P 1,p2,...,pτ+k }. If it isThen p i is referred to as the matching partition, otherwise it is referred to as the unmatched partition.
S14, if the number of matched partitions in the partition set P is smaller than k according to theorem 1, the graph editing distance GED (g, q) is necessarily larger than tau, so that g can be judged to be a false positive graph, and the time cost is greatly saved by adopting the deducing mode. An inverted index I (p) is constructed from a partition p of graph g. For a given query graph qAll data graphs containing partitions p can be quickly found in graph database G. Thus, after the necessary half sub-graph isomorphism calculation of the partition p is performed, all the data graphs containing the partition p can be found through the inverted index, so that a large amount of calculation is reduced. A random partitioning strategy is adopted, namely, nodes of (tau+k) seeds are randomly selected as a starting partition in the graph g, and then the partition is expanded in a region growing mode until all the nodes in the graph g are incorporated into the partition.
The graph partitioning strategy partitions each data graph into several mutually exclusive half graphs, which are different from the normal graph in that the existence of half is not directly encoded by GNN. For the processing of the half-edge graphs, the traditional isomorphism testing method generally adopts a mode of adding virtual nodes, adds a virtual node for each half-edge graph, connects the far ends of all the half-edges with the virtual node, and can be matched with any node. Then, when the sub-graph isomorphism test is performed, the half sides can be effectively matched.
However, in GNN, if a policy of joining virtual nodes is still adopted, distortion of original graph data may be caused. This is because GNN cannot identify virtual nodes as in the conventional algorithm, and cannot match any virtual node with any node, and it only treats it as a normal node, so that the structure and node information of the original half graph are changed, and thus, deviation and even erroneous information are learned.
A self-loop strategy is provided to realize lossless embedding of the half graph, and the far ends and the near ends of all half in the half graph are connected, so that the half becomes a self-loop, and virtual nodes are not needed to be introduced, and half can be described. However, in the message passing process of GNN, since the self-loop is equivalent to passing the message to itself, the effect of the current node information in the current node embedded representation is enhanced, which is not consistent with the real result. Therefore, in the process of message passing, we do not pass messages to the node connected by the self-ring formed by half reconstruction, so that only half degree information is included in the GNN, and for the node with the self-ring, the message passing update formula is as follows:
where N (v) represents the set of neighbor nodes of node v, σ is the activation function, W is the weight matrix, and b is the bias.
A SkipConGNN model was trained to implement sequential embedding. The model integrates leap connection which can be learned, so that the convolution operation of each layer not only depends on the output of the last layer, but also can directly use the output of all the previous layers. This mechanism is very important in deep neural networks, helping to alleviate the gradient vanishing problem and improve the performance of the model.
Specifically, the SkipConGNN model realizes a more flexible and expressive feature propagation mechanism by introducing a leachable jump connection, and can integrate information across multiple network layers. SKIPLASTGNN architecture can be divided into the following key components:
S22, the input layer is responsible for processing the initial node characteristics. Let node feature matrix be X ε R N×F, where N represents the number of nodes and F represents the feature dimension. Firstly, processing node characteristics through linear transformation to obtain hidden layer representation:
H(0)=XW0
Where W 0∈RF×H is the linearly transformed weight matrix and H is the hidden layer dimension. If feature preprocessing is enabled, additional preprocessing steps are applied to enhance the original input features. The model employs k layers of graph volumes to aggregate local neighborhood information and iteratively update node representations. Aggregation of node neighborhood information is achieved herein using a GRAPHSAGE convolution, the propagation rules of which can be expressed as:
where H (1) is the node representation of the first layer, W l is the weight matrix of the first layer, N (v) is the set of neighbor nodes of node v, and σ is the activation function.
S23 a leachable jump connection is added between the different convolutional layers SkipConGNN, which is represented by a parameter matrix S e R L×L, where L is the number of network layers. During the training process, the parameter matrix is used to determine the optimal contribution of each layer of output to the final node representation.
Assuming that H (0),H(1),...,H(l) is a node representation of the previous l layers, the output of the jump connection is represented as:
Wherein S l,i is a leap connection weight that can be learned. The introduction of a jump connection effectively alleviates the gradient vanishing problem, enabling the model to capture information from different network depths. σ is an activation function for scaling the weight of the jump connection to limit it to the (0, 1) range. The weight of such a jump connection will control the extent to which each input feature is affected in the current layer.
S24, after the k-layer convolution, the node representations are aggregated by a global pooling operation to generate a fixed-size graph insert.
Z=Pool(H(L))
Wherein H (L) is a node representation of the final layer L, Z is a global representation of the graph, pool is a global pooling function, and different pooling modes can be selected according to specific requirements.
S25 given a target graph instance G T=(VT,ET) and a query graph instance G Q=(VQ,EQ), where V T is the target graph node set, E T is the target graph edge set, V Q is the query graph node set, and E Q is the query graph edge set. The level embedding Z Q of level embedding Z T,GQ of G T can be obtained by a sequential embedding model, and if G Q is a isomorphic subgraph of G T, then the position of Z Q in the embedding space should be in the "lower left corner" of Z T, according to the sequential embedding theory:
Where D is the embedding dimension. We can measure how well ZQ and Z T satisfy order embedding theory with E (ZQ, Z T),
S26-thus, the maximum marginal loss is used to train the generation of embedded GNNs:
Where P is the positive sample set, N is the negative sample set, and α is the hyper-parameter. When Z Q[i]>ZT [ i ] is in any dimension i, the sub-graph constraint is violated. E (Z Q,ZT) represents the amplitude thereof. For positive example P, E (Z Q,ZT) is minimized when all elements of the query node embedded in the ZQ are smaller than the corresponding elements of the target node embedded in Z T. For the negative pair (Z Q,ZT), the amount of violation E (Z Q,ZT) should be at least α to obtain zero loss.
And S3, after all preparation works of constructing the index, sequentially embedding and mapping the index are completed, searching the similar map, firstly constructing the coordinate index based on the size information of the data map, secondly dividing the data map, inputting divided partitions into a nerve subgraph embedded model to obtain partition embedded representation, and finally constructing the inverted index by taking the embedded representation of the partition as a key and taking the ids of all the data maps comprising the partition as values, and simultaneously maintaining the mapping relation between the data map and the partitions divided by the map. When inquiring, firstly, calculating an inquiry area through an inquiry diagram q and an inquiry threshold tau, and taking the partitions corresponding to all diagrams in the inquiry area as the partitions to be checked of the inverted index through the mapping relation between the partitions and the data diagram. Secondly, before the inverted index is queried, a score array S is firstly created and is used for recording the number of matching partitions existing between the current query graph and each data graph. And inputting the query graph into a neural subgraph matching model to obtain query graph embedding, and for each partition to be searched, comparing the position relations of the query graph embedding and the partition embedding in an embedding space in sequence, wherein if Z (p) is less than or equal to Z (q), p is an isomorphic subgraph of the query graph q, and then the score Sg+1 of all the data graphs of the partition is included until all the partitions to be searched are completely compared. And according to theorem 1, the score in the score array S is greater than or equal to k and is the candidate set. And finally, verifying the candidate set by using an accurate GED verification algorithm to obtain a final query result.
It should be noted that the foregoing merely illustrates the technical idea of the present invention and is not intended to limit the scope of the present invention, and that a person skilled in the art may make several improvements and modifications without departing from the principles of the present invention, which fall within the scope of the claims of the present invention.