Sub-graph counting method based on graph neural network
By applying graph neural networks in subgraph counting, using node embedding models and self-attention models, feature extraction is improved, and the problems of high calculation cost and low accuracy in subgraph counting in large-scale or complex graphs in the prior art are solved, achieving more efficient and accurate subgraph counting.
Patent Information
- Application Number
- CN202510195162.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-21
- Publication Date
- 2025-06-10
AI Technical Summary
The existing subgraph counting methods are cost-effective in large-scale or complex graphs, have low accuracy, and poor scalability, which cannot effectively solve the NP-hard subgraph matching problem.
The subgraph counting method based on graph neural network is adopted, and the features of query graph and data graph are extracted through pre-trained node embedding models and self-attention models, and the node domination and substructure domination relationship are used to improve the accuracy of feature extraction, thereby improving the accuracy of subgraph counting.
It improves the accuracy and efficiency of sub-graph counting, and can perform sub-graph counting more accurately, suitable for large-scale or complex graphs.
Smart Images

Figure CN120124679A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and particularly relates to a subgraph counting method based on a graph neural network. Background Art
[0002] In recent years, with the rapid development of the Internet and information technology and their extensive application in various fields, not only has the user scale and daily traffic increased sharply, but the accompanying user data volume has also been continuously expanding. The rapid expansion of the network leads to a huge amount of associated data being generated every day in daily life. In this context, the graph, a non-linear data structure that can represent the structural relationship between nodes, has received extensive attention from researchers. A graph is composed of nodes and edges connecting the nodes, and can well represent the attributes of things and the connections between them, and has been widely used in many fields such as computer vision and pattern recognition.
[0003] The subgraph matching problem is to find all subgraphs in the data graph G that are isomorphic to the query graph q. As a fundamental problem in graph query problems, it has been widely applied in fields such as information retrieval, computer vision, natural language processing, chemoinformatics, and bioinformatics. However, the subgraph matching problem has been proven to be an NP-hard problem, that is, it cannot be solved within polynomial time.
[0004] Existing subgraph counting methods can be divided into exact subgraph counting methods and approximate subgraph counting methods. The exact subgraph counting method can accurately calculate the number of isomorphic subgraphs. The exact subgraph counting method is mainly divided into an enumeration method and an analysis method. The exact subgraph counting algorithm based on enumeration finds subgraphs isomorphic to the query graph by enumerating all possible subgraph combinations, thereby calculating the number of isomorphic subgraphs. Although this method ensures accurate counting, it usually requires traversing a large search space and has a high computational cost. Therefore, the algorithm based on enumeration is more suitable for small-scale or simple-structured graphs. The exact subgraph matching algorithm based on analysis utilizes the mathematical characteristics and theoretical analysis of the graph to calculate the number of matching subgraphs by analyzing the structural characteristics of the data and the query graph. This method is applicable to graphs with complex structures or large scales, but it also takes a certain amount of time to provide accurate results.
[0005] The main purpose of approximate subgraph counting is to quickly estimate the number of subgraphs in the data graph that are isomorphic to the query graph. In large-scale or complex graphs, exact subgraph counting may be impractical due to high computational costs. Approximate subgraph counting provides a more practical solution by providing results close to the accurate ones within a reasonable time frame and resource usage. Traditional approximate counting algorithm methods are divided into five categories: random enumeration, enumeration generalization, path sampling, random walk, and color coding. However, these algorithms have low accuracy and poor scalability on large-scale graphs.
[0006] In recent years, with the rapid development of graph neural networks, researchers have proposed some deep learning-based approximate subgraph counting methods. The core idea of these methods is to regard the subgraph counting problem as a regression problem, use graph neural networks to extract the features of the data graph and the query graph, and then predict the subgraph count based on these features. However, the features extracted by these methods are the structural features of nodes and cannot accurately represent the matching relationship between the query graph and the data graph. Summary of the Invention
[0007] Aiming at the deficiencies of the existing technology, this application proposes a subgraph counting method based on graph neural networks, a subgraph counting algorithm based on node domination and substructure domination, and improves the accuracy of subgraph counting by improving the accuracy of feature extraction.
[0008] This application proposes a subgraph counting method based on graph neural networks, including:
[0009] Obtain a query graph and a data graph to be counted;
[0010] Input the query graph and the data graph to be counted into a pre-trained node embedding model to extract features, obtaining the embedding space of the query graph and the embedding space of the data graph. The pre-trained node embedding model is trained based on the domination relationship between the query graph and the data graph node embeddings of predefined training samples.
[0011] Split the embedding space of the query graph into substructures of the query graph;
[0012] Input the substructures of the query graph and the embedding space of the data graph into a pre-trained self-attention model to obtain the subgraph counting result. The pre-trained self-attention model is trained based on the domination relationship between the substructures of the query graph and the data graph of predefined training samples.
[0013] The query graph to be counted has the same number of nodes as the query graph of the training samples, and the data graph to be counted has the same number of nodes as the data graph of the training samples.
[0014] The pre-trained node embedding model is trained based on the domination relationship between the query graph and the data graph node embeddings of predefined training samples. The training process includes:
[0015] Obtain a data set and divide the data set into a training set and a validation set. The data set includes a query graph and a data graph, and the data in the training set are training samples;
[0016] Define the domination relationship between the query graph and the data graph node embeddings of the training samples;
[0017] Construct a node embedding model according to the domination relationship between the query graph and the data graph node embeddings of the training samples;
[0018] Train a node embedding model using a training set, and use the stochastic gradient descent method to update the parameters of the node embedding model according to the first loss function until the first loss function is less than the first preset threshold, then stop training to obtain a pre-trained node embedding model.
[0019] The pre-trained node embedding model includes:
[0020] A graph convolutional neural network model for extracting the features of a query graph;
[0021] A graph attention network model for extracting the features of a data graph.
[0022] Defining the dominance relationship between the query graph and the data graph node embeddings of the training samples includes:
[0023] In the training samples, given a data graph G and a query graph q, if the node v in the data graph G j matches the node u in the query graph q i then the embedding vectors of the nodes u i and v i obtained through the node dominance embedding network are respectively and then the embedding vector must dominate the embedding vector
[0024] The calculation formula of the graph convolutional neural network model is as follows:
[0025]
[0026] where, H (l+1) is the node representation of the (l + 1)-th layer of the graph convolutional neural network model, is the normalized adjacency matrix, is the diagonal matrix, H (l) is the node representation of the l-th layer of the graph convolutional neural network model, w (l) is the weight of the l-th layer, and σ′ is the first activation function.
[0027] The calculation formula of the graph attention network model is as follows:
[0028]
[0029] where, is the feature representation of the i-th node of the graph attention network model at the t-th layer, σ is the second activation function, N i is the neighbor node of node i, is the feature representation of the i-th node of the graph attention network model at the (t - 1)-th layer, is the feature representation of neighbor node j of the i-th node in the graph attention network model at the (t - 1)-th layer, and W t-1 represents the weight at the (t - 1)-th layer.
[0030] The pre-trained self-attention model is trained by defining the dominance relationship between the query graph and the sub-structures of the data graph of the predefined training samples. The training process is as follows:
[0031] Define the dominance relationship between the query graph and the sub-structures of the data graph of the training samples;
[0032] Split the query graph of the training samples into sub-structures;
[0033] Use the training set to train the self-attention model to obtain the influence degree of each sub-structure on the sub-graph counting result;
[0034] Use the stochastic gradient descent method to update the parameters of the self-attention model according to the second loss function until the second loss function is less than the second preset threshold, stop training, and obtain the pre-trained self-attention model.
[0035] The definition of the dominance relationship between the query graph and the sub-structures of the data graph of the training samples includes:
[0036] In the training samples, if the nodes v x , v y , v z in the data graph G are respectively in a matching relationship with the nodes u i , u j , u k in the query graph q, then the embedding vector of the sub-structure composed of v x , v y , v z in the data graph G must dominate the embedding vector of the sub-structure composed of u i , u j , u k in the query graph q.
[0037] The splitting of the query graph of the training samples into sub-structures includes:
[0038] Perform a one-hop breadth-first traversal on each node in the query graph of the training samples to form sub-structures with the same number of nodes as the query graph nodes of the training samples.
[0039] Beneficial effects:
[0040] This application proposes a subgraph counting method based on graph neural networks. Subgraph counting is performed through graph neural networks. When calculating the number of subgraph matches, the concepts of vertex domination and path domination are introduced. First, a node embedding network model is designed, which can discover the matching relationships existing between the nodes of the query graph and the data graph. Then, the query graph is split into substructures, and the attention mechanism is used to determine the influence degree of each substructure on subgraph counting, so as to discover the matching relationships existing between the structure of the query graph and the structure of the data graph. The counting method of this application can make the feature extraction more accurate, so as to perform subgraph counting more precisely. Description of the Drawings
[0041] Figure 1 Flowchart of a subgraph counting method based on graph neural networks according to an embodiment of this application;
[0042] Figure 2 Schematic diagram of the flow of a subgraph counting method based on graph neural networks according to an embodiment of this application;
[0043] Figure 3 Schematic diagram of the structure of the node embedding model according to an embodiment of this application;
[0044] Figure 4 Schematic diagram of splitting the query graph into substructures according to an embodiment of this application. Detailed Embodiment
[0045] The following combines the drawings and embodiments to further describe the detailed embodiments of this application.
[0046] Embodiment:
[0047] This application proposes a subgraph counting method based on graph neural networks, as Figure 1 、 Figure 2 shown, including:
[0048] Step S1: Obtain the query graph and the data graph to be counted;
[0049] In this embodiment, it should be noted that: the number of nodes of the query graph to be counted is the same as that of the query graph of the training sample, and the number of nodes of the data graph to be counted is the same as that of the data graph of the training sample.
[0050] Step S2: Respectively input the query graph and the data graph to be counted into the pre-trained node embedding model to extract features, obtain the embedding space of the query graph and the embedding space of the data graph. The pre-trained node embedding model is trained by predefining the domination relationship between the query graph and the data graph node embeddings of the training samples;
[0051] In this embodiment, the pre-trained node embedding model is trained by predefined dominance relationships between query graph and data graph node embeddings, and the training process includes:
[0052] Step S2.1: Obtain a data set and divide the data set into a training set and a validation set. The data set includes: query graphs and data graphs, and the data in the training set are training samples;
[0053] In this embodiment, an open and general data set is searched for and screened to determine the data set used in this embodiment. By reading relevant literature, real data sets such as dblp, youtube, and hprd are used as the data sets in this embodiment. The main reasons for choosing them are twofold: these data sets are widely used in subgraph matching-related research and have high authority.
[0054] Step S2.2: Define the dominance relationship between the query graph and data graph node embeddings of the training samples;
[0055] (1) In this embodiment, the dominance relationship between the query graph and data graph node embeddings is defined.
[0056] Vector dominance: Given two vectors A = (a 1 , a 2 , …, a n ) and B = (b 1 , b 2 , …, b n ), where a i is the i-th element in vector A and b j is the j-th element in vector B. If A is considered to be dominated by B, the following conditions must be met:
[0057] (1) a i ≤ < b i .
[0058] (2) a j < b j .
[0059] Based on the definition of vector dominance, we provide the definition of node dominance.
[0060] Node dominance: Given a data graph G and a query graph q, if the node v j in the data graph G matches the node u i in the query graph q, then the embedding vectors of the nodes u i and v j obtained through the node dominance embedding network are respectively and then the vector Must dominate the vector
[0061] The node embedding model proposed in this embodiment is expected to satisfy the node domination relationship, so that the matching relationship between nodes can be represented by the embeddings of the nodes.
[0062] Step S2.3: Construct a node embedding model according to the domination relationship between the query graph and the data graph node embeddings of the training samples;
[0063] In this embodiment, the pre-trained node embedding model includes: a graph convolutional neural network model for extracting the features of the query graph; a graph attention network model for extracting the features of the data graph.
[0064] Construct a node embedding model based on the graph neural network to obtain the embedding representations of the query graph and data graph nodes.
[0065] The node embedding model uses GCN (Graph Convolutional Networks) to extract the features of the query graph and GAT (Graph Attention Networks) to extract the features of the data graph. The structural diagram of the node embedding model is as Figure 3 shown.
[0066] Since the query Figure 1 generally has only 4 - 24 nodes and the structure is relatively simple, only a simple graph convolutional neural network GCN is used to extract the node representations of the query graph. The calculation formula of the GCN network is as follows:
[0067]
[0068] where, H (l+1) is the node representation of the l + 1-th layer of the graph convolutional neural network model, is the normalized adjacency matrix, is the diagonal matrix, H (l) is the node representation of the i-th layer of the graph convolutional neural network model, w (l) is the weight of the i-th layer, and σ′ is the first activation function.
[0069] Since the data graph is relatively complex, we use the graph attention neural network GAT to extract the node representations of the data graph. The calculation formula of the GAT network is as follows:
[0070]
[0071] where, is the feature representation of the i-th node of the graph attention network model at the t-th layer, σ is the second activation function, N iis a neighbor node of node i, is the feature representation of the i-th point of the graph attention network model at the (t - 1)-th layer, is the feature representation of the neighbor node j of the i-th node of the graph attention network model at the (t - 1)-th layer, W t-1 represents the weight at the (t - 1)-th layer.
[0072] Step S2.4: Train the node embedding model using the training set, and update the parameters of the point embedding model according to the first loss function using the stochastic gradient descent method until the first loss function is less than the first preset threshold, then stop training to obtain the pre-trained node embedding model.
[0073] In a specific implementation, the effect of the model can be verified on the validation set. The first loss function is calculated as follows:
[0074]
[0075] where Loss 1 is the first loss function, e(v j ) is the embedding of node v j , e(u i ) is the embedding of node u i , and ||·|| 2 is the L2 norm. In this embodiment, the first loss function is used to ensure the dominance relationship between the query graph and the data graph node embeddings.
[0076] Step S3: Split the embedding space of the query graph into substructures of the query graph;
[0077] Step S4: Input the substructures of the query graph and the embedding space of the data graph into the pre-trained self-attention model to obtain the subgraph counting result. The pre-trained self-attention model is trained through the dominance relationship between the query graph and the data graph substructures of the predefined training samples.
[0078] The training process of the pre-trained self-attention model is as follows:
[0079] Step S4.1: Split the query graph of the training sample into substructures, including:
[0080] Perform a one-hop breadth-first traversal on each node in the query graph of the training sample to form substructures with the same number of nodes as the query graph of the training sample. As Figure 4 shown, the embedding representation of each node is obtained by the node embedding model.
[0081] Step S4.2: Train the self-attention model using the training set to obtain the influence degree of each substructure on the subgraph counting result;
[0082] In this embodiment, the self-attention mechanism is adopted to learn the influence degree of each sub-structure on the sub-graph counting result. The self-attention mechanism is a technology widely used in deep learning models, especially when dealing with sequence data (such as natural language processing tasks). The self-attention mechanism can capture the relationships between elements at different positions in the sequence without relying on the distance between elements.
[0083] Suppose the input sequence is represented as x, and the query vector Q, key vector K, and value vector V are calculated by the following formulas respectively:
[0084] Q = XW Q K = XW k V = XW v
[0085] where, W Q W k and W v are parameter matrices to be learned.
[0086] In this embodiment, the input sequence X is each sub-structure. The attention weights (i.e., correlations) are calculated using the query vector and the key vector. Usually, dot-product attention is used to obtain the attention coefficients of each sub-structure:
[0087]
[0088] where, Attention() is the attention coefficient, and d k is the dimension of the key.
[0089] The value vector is weighted and summed using the calculated attention weights to obtain a new representation of each sub-structure:
[0090] Output = Attention(Q, K, V) * X
[0091] where, output is the output of the self-attention model, and λ is the attention weight.
[0092] Step S4.3: Use the stochastic gradient descent method to update the parameters of the self-attention model according to the second loss function until the second loss function is less than the second preset threshold, then stop training to obtain the pre-trained self-attention model.
[0093] In this embodiment, the training set is used to train the self-attention model, the model parameters are updated according to the loss function using the stochastic gradient descent method, and the model effect is verified on the validation set. Then, the new embeddings of the sub-structures of each query graph are concatenated and then input into the fully connected layer.
[0094] The second loss function is calculated as follows:
[0095]
[0096] Among them, Loss 2 is the second loss function, m is the number of query graphs, and y i is the true value of subgraph counting, and is the predicted value of subgraph counting.
[0097] Compared with the prior art, the counting method in this embodiment can fully consider the matching relationship between the nodes of the query graph and the data graph, as well as the matching relationship between the substructures, so as to more accurately extract the node features of the query graph and the data graph, and thus perform subgraph counting more precisely.
[0098] The various embodiments in this application are all described in a progressive manner. For the same or similar parts between the various embodiments, reference can be made to each other. The key points of each embodiment are the differences from other embodiments.
[0099] The protection scope of this application is not limited to the above embodiments. Obviously, those skilled in the art can make various changes and deformations to the present disclosure without departing from the scope and spirit of the present disclosure. If these changes and deformations belong to the scope of the claims of the present disclosure and their equivalent technologies, the intention of the present disclosure also includes these changes and deformations.
Claims
1. A subgraph counting method based on graph neural network, characterized in that: include: Obtain the query graph and data graph to be counted; Inputting the query graph and data graph to be counted into a pre-trained node embedding model to extract features respectively, and obtaining an embedding space of the query graph and an embedding space of the data graph, wherein the pre-trained node embedding model is trained by pre-defining the dominant relationship between the query graph and the data graph node embedding of the training sample; Split the embedding space of the query graph into substructures of the query graph; The substructure of the query graph and the embedding space of the data graph are input into a pre-trained self-attention model to obtain a subgraph counting result. The pre-trained self-attention model is trained by pre-defining the dominant relationship between the query graph and the data graph substructure of the training sample.
2. According to the subgraph counting method based on graph neural network in claim 1, it is characterized in that: The pre-trained node embedding model is obtained by training the dominant relationship between the query graph and the data graph node embedding of the pre-defined training samples. The training process includes: Obtain a data set, and divide the data set into a training set and a validation set, the data set includes: a query graph and a data graph, and the data in the training set are training samples; Define the dominance relationship between the query graph and data graph node embeddings of the training samples; Construct a node embedding model based on the dominance relationship between the query graph and data graph node embedding of the training samples; The node embedding model is trained using the training set, and the parameters of the point embedding model are updated using the stochastic gradient descent method according to the first loss function until the first loss function is less than a first preset threshold, and the training is stopped to obtain a pre-trained node embedding model.
3. According to the subgraph counting method based on graph neural network in claim 1, it is characterized in that: The pre-trained node embedding model includes: Graph convolutional neural network model, used to extract features of query graph; Graph Attention Network model, used to extract features of data graphs.
4. According to the subgraph counting method based on graph neural network in claim 1, it is characterized in that: The definition of the dominant relationship between the query graph of the training sample and the data graph node embedding includes: In the training sample, given a data graph G and a query graph q, if the node v in the data graph G i and node u in the query graph q i Match, then the node u obtained by the node dominance embedding network i and v j The embedding vectors are and Then the embedding vector must dominate the embedding vector 5. According to the subgraph counting method based on graph neural network in claim 3, it is characterized in that: The graph convolutional neural network model is calculated as follows: Among them, H (1+1) is the node representation of the l+1th layer of the graph convolutional neural network model, is the normalized adjacency matrix, is the diagonal matrix, H (l) is the node representation of the lth layer of the graph convolutional neural network model, w (l) is the weight of the Ith layer, and σ′ is the first activation function.
6. The subgraph counting method based on graph neural network according to claim 3 is characterized in that: The graph attention network model is calculated as follows: in, is the feature representation of the i-th node in the t-th layer of the graph attention network model, σ is the second activation function, N i is the neighbor node of node i, is the feature representation of the i-th point in the t-1 layer of the graph attention network model, is the feature representation of the neighbor node j of the i-th node in the graph attention network model at the t-1 layer, W t-1 represents the weight of the t-1 layer.
7. The subgraph counting method based on graph neural network according to claim 1 is characterized in that: The pre-trained self-attention model is trained by pre-defining the dominant relationship between the query graph and the data graph substructure of the training sample. The training process is as follows: Define the dominance relationship between the query graph and the substructure of the data graph of the training samples; Split the query graph of training samples into substructures; The self-attention model is trained using the training set to obtain the influence of each substructure on the subgraph counting result; The stochastic gradient descent method is used to update the parameters of the self-attention model according to the second loss function until the second loss function is less than a second preset threshold, and the training is stopped to obtain a pre-trained self-attention model.
8. The subgraph counting method based on graph neural network according to claim 7 is characterized in that: The dominant relationship between the query graph and the substructure of the data graph that define the training samples includes: In the training sample, if the node v in the data graph G x ,v y ,v z Respectively with the node u in the query graph q i ,u j ,u k There is a matching relationship, then in the data graph G, v x ,v y ,v z The embedding vector of the substructure composed of must dominate the query graph q composed of u i ,u j ,u k The embedding vectors of the substructures.
9. The subgraph counting method based on graph neural network according to claim 7, characterized in that: The step of splitting the query graph of the training sample into substructures includes: A one-hop breadth-first traversal is performed on each node in the query graph of the training sample to form a substructure with the same number of nodes as the query graph of the training sample.