Sub-graph editing distance calculation method based on graph neural network
By using a unified graph isomorphic encoder and an adaptive masking mechanism, representations of nodes and edges are generated and graph size differences are balanced, solving the problems of low computational efficiency and insufficient accuracy in existing technologies, and realizing efficient and accurate subgraph editing distance calculation.
Patent Information
- Application Number
- CN202511224679.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2026-01-30
AI Technical Summary
Existing technologies suffer from low computational efficiency, insufficient accuracy, and inadequate handling of asymmetry when calculating subgraph edit distances on large-scale graph data. Furthermore, existing GNN methods struggle to dynamically adapt to changes in graph structure.
A unified graph isomorphic encoder and an adaptive masking mechanism are adopted. Node and edge representations are generated through a multilayer perceptron and a graph isomorphic network. Masking scores are generated by combining a gated attention mechanism to dynamically balance graph scale differences. Multiple candidate substructures are generated through multi-head masking. Finally, the edit distance is calculated by a multi-view SED Predictor.
It improves the accuracy and efficiency of subgraph editing distance calculation, can dynamically adapt to changes in graph structure under large-scale graph data, and enhances the stability and generalization ability of the calculation.
Smart Images

Figure CN121436034A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of graph computing and artificial intelligence, and particularly to a subgraph edit distance calculation method based on a graph neural network. BACKGROUND
[0002] In the fields of drug discovery, social network analysis, recommendation system, etc., subgraph similarity calculation is a basic task. Subgraph edit distance (SED) is a commonly used index to measure the similarity of subgraphs, which is defined as the minimum editing operation cost to transform a query graph into a certain subgraph of a target graph. The accurate calculation of SED is an NP-hard problem, and although traditional heuristic algorithms can approximately calculate SED, they are inefficient in large-scale graph data. In recent years, graph neural networks (GNN) have been used to approximately calculate graph edit distance (GED) or subgraph edit distance (SED), but the existing methods have the following shortcomings: Asymmetry problem: SED does not satisfy symmetry, and existing GNNs have difficulty in dynamically balancing the distance of graphs of different sizes in the representation space.
[0003] Limitations of node-centric propagation: node-level message passing cannot fully capture the impact of edge-specific editing operations on graph structure.
[0004] Inflexible substructure positioning: existing methods rely on pre-defined parameters when positioning the most similar substructure in the target graph to the query graph, and lack dynamic adaptability.
[0005] Therefore, a new method is needed that can accurately approximate SED and efficiently run in large-scale scenarios. SUMMARY
[0006] The purpose of the present application is to provide a subgraph edit distance approximation calculation method based on a unified graph isomorphism encoder and an adaptive mask mechanism, to solve the problems of insufficient calculation accuracy, low calculation efficiency, and insufficient handling of asymmetry in the prior art.
[0007] To achieve the above purpose, the present application provides the following technical solution: a subgraph edit distance approximation calculation method based on a unified graph isomorphism encoder and an adaptive mask mechanism, comprising the following steps: (1) obtaining a query graph and a target graph ; (2) generating node-level and edge-level representations for the query graph and the target graph respectively through a unified graph isomorphism encoder to capture the impact of node and edge-specific editing operations on graph topology; (3) Target image The input adaptive graph masking module combines the query graph with a gated attention mechanism. It represents the mask score for generating nodes and edges, masking irrelevant parts and dynamically balancing graph size differences; (4) Target image based on mask score Perform multi-head masking to generate multiple candidate substructures, and then re-encode them using a mask graph neural network; (5) Use the multi-view SED Predictor to fuse the graph-level representation of node view, edge view and re-encoded view, and output an approximate value of the subgraph edit distance.
[0008] Furthermore, the unified graph isomorphic encoder execution process includes: generating initial representations of nodes and edges using a multilayer perceptron (MLP). and The graph isomorphic network (GIN) of node representations is used to iteratively update node representations; the dual hypergraph transformation (DHT) of the original graph structure is performed to iteratively update edge representations.
[0009] Furthermore, the update rule for graph isomorphic networks is: in the first... In the layer update, the representation of node i is updated based on the aggregation result of its own representation and the representations of its neighboring nodes, specifically as follows:
[0010] in, It is a node No. Layer representation, Represents nodes The set of adjacent nodes, It is a nonlinear transformation function. These are learnable parameters; after L layers of iterative updates, the node representations from each layer are concatenated to obtain the final node-level representation, specifically:
[0011] in, Indicates splicing, It is a two-layer fully connected layer used to compress spliced information.
[0012] Furthermore, the update rule for the hypergraph transformation is as follows: map each edge in the original graph to a node in the hypergraph, and map each node in the original graph to a hyperedge in the hypergraph; on the hypergraph, for each hyperedge... The hyperedge message is generated by aggregating node features based on its set of nodes and fusing the hyperedge's own features. ; for each dual-hypergraph node , update the node representation according to the hyperedge message connected thereto, to obtain
[0013] wherein, represents a hyperedge set containing node ; after L-layer iterative update, the node representations of each layer are spliced and mapped to the edge-level representation of the original graph , as the output of the edge-level isomorphic encoding, specifically:
[0014] Further, the mask score calculation step includes: a cross-graph interaction step: inputting the node representation of the target graph and the global representation of the query graph into a gated attention network to obtain initial node mask scores; an edge association step: generating initial edge mask scores based on the edge relationship between the nodes in the target graph and combining the corresponding node mask scores; a score correction step: normalizing and nonlinearly transforming the initial node mask scores and edge mask scores to ensure that the mask scores are in the [0, 1] interval; a scale balancing step: weighting and correcting the normalized mask scores according to the size difference between the target graph and the query graph, so that graphs of different sizes can be calculated in a unified scale; an output step: outputting the corrected node mask scores and edge mask scores for subsequent multi-head mask processing steps.
[0015] Further, the multi-head mask processing includes: multi-head distribution, for inputting the node mask scores and edge mask scores into multiple mask channels according to a preset number of multi-heads; in each mask channel, the target graph is selected and extracted for substructure according to the corresponding mask score, forming multiple candidate substructures; the candidate substructures are input into a mask graph neural network for re-encoding to obtain graph-level representations of the candidate substructures; and the re-encoded representations of the multiple candidate substructures are output for subsequent multi-view SED predictor use.
[0016] Further, the number of multi-heads is 3 to 6, each head independently generates a set of candidate substructures, and each is re-encoded.
[0017] Further, the execution steps of the multi-view predictor include: using the node-level representation to weight and aggregate the graph to obtain a graph-level vector of the node view; using the edge-level representation to weight and aggregate the graph to obtain a graph-level vector of the edge view; using the re-encoded results of the candidate substructures after multi-head mask processing to obtain a graph-level vector of the re-encoded view; splicing or weighted fusion of the graph-level vectors of the node view, the edge view and the re-encoded view to obtain a comprehensive multi-view representation; and outputting the query graph based on the comprehensive multi-view representation through a fully connected layer and target graph between subgraph edit distance approximation. Further, the unified graph isomorphism encoder is a graph isomorphism network (GIN), a graph attention network (GAT), or a graph sampling aggregation network (GraphSAGE).
[0018] The application provides a subgraph edit distance calculation method based on a graph neural network, which has the following beneficial effects: the application extracts node-level and edge-level representations through a unified graph isomorphism encoder, and combines an adaptive graph mask and a multi-head mask mechanism to effectively reduce the search space, thereby significantly improving the calculation speed while maintaining high accuracy; the adaptive graph mask module dynamically shields the part irrelevant to the query graph by using a gated attention mechanism, and automatically balances the differences between graphs of different sizes, thereby avoiding the failure problem of traditional methods when the graph sizes do not match; the multi-head mask mechanism provides diversified candidate substructure perspectives, thereby improving the stability and generalization ability in complex graph data; and the multi-perspective predictor fuses node perspectives, edge perspectives, and re-encoding perspectives, so that the graph-level representation is more comprehensive and robust. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 is a schematic diagram of calculating a subgraph edit distance; Figure 2 is a flowchart of the subgraph edit distance calculation method and system based on the graph neural network provided by the embodiment of the application; Figure 3 is a schematic diagram of a dual hypergraph transformation; Figure 4 is a schematic diagram of cross-graph matching of gated attention. DETAILED DESCRIPTION
[0020] The embodiments of the application will be further described in detail below with reference to the embodiments. The following embodiments are used to illustrate the application, but cannot be used to limit the scope of the application.
[0021] A subgraph edit distance calculation method based on a graph neural network includes the following steps: Data preparation stage: Data collection: a large amount of graph data pairs are collected from public graph databases and actual application scenarios, each pair of data containing a query graph and a target graph , to ensure that the collected data covers graphs of different sizes, different topologies, and different label types, so as to ensure the generalization ability of the model.
[0022] Data preprocessing: the original data is parsed into a graph structure , wherein is an edge set, and These are the sets of labels for nodes and edges, respectively. and It is a label mapping function.
[0023] Dataset partitioning: The preprocessed dataset is divided into training, validation, and test sets in a ratio of 8:1:1. The training set is used to train the model parameters, the validation set is used to monitor the training process, adjust hyperparameters, and implement early stopping, and the test set is used to finally evaluate the model's performance.
[0024] The core of this invention is the Masked Graph Distance Network (MGDN) model, whose overall architecture is as follows: Figure 1 As shown, it contains four main modules: The Unified Graph Isomorphism Encoder is designed to capture fine-grained information about nodes and edges separately. It includes a Node-Level Isomorphism Encoder and an Edge-Level Isomorphism Encoder.
[0025] Node-level isomorphic encoder construction: An encoder based on the edge-extended graph isomorphic network (EGIN) is built using a deep learning framework (such as PyTorch Geometric); for each node in the graph... The one-hot label vector is processed through a two-layer MLP. Mapping to initial node embedding For a network with L=5 layers, each layer Perform the following operations on each node: Aggregate its neighbor nodes The upper layer represents and connecting edge The upper layer represents The information is processed through a learnable update function. Updating its own representation Represent all nodes across all 5 layers. The splicing is performed and connected through a two-layer fully connected network. Compression yields the final node-level representation. .
[0026] Edge-level isomorphic encoder construction: from the original graph Transforming it into its dual hypergraph H, specifically implemented as follows: each edge of the original graph... A node in the corresponding hypergraph Each node of the original graph a hyperedge in the corresponding hypergraph , edge labels of the original graph are changed to labels of hypergraph nodes , node labels of the original graph are changed to labels of hypergraph hyperedges .
[0027] Hypergraph Isomorphic Network (HGIN) construction: the nodes in H (corresponding to the edges of G) are initialized as the edge embeddings of ; the hyperedges in H (corresponding to the nodes of G) are initialized as the node embeddings of ; HGIN updates the node state by aggregating the information of all nodes within the hyperedge and the representation of the hyperedge itself; the node representations of all 5 layers of HGIN are spliced and compressed to obtain the edge-level representation of the original graph . Adaptive Graph Masking Module construction: this module aims to solve the asymmetric problem of SED, and dynamically generates mask scores for the nodes and edges in Gt. Gated Attention-based Cross-Graph Matching: first, an overall representation of the target graph Gt is calculated; then, the relevance (attention weight) between each node of the query graph Gq and the overall representation of the target graph is calculated, and the intermediate representation of the query graph is obtained by weighted summation; next, through a gating mechanism, the overall representation of the target graph and the intermediate representation of the query graph are fused to obtain a final intermediate representation that reflects the information of both graphs; finally, using this final intermediate representation, the initial mask scores of each node and each edge in Gt are calculated, which reflect their preliminary similarity to the query graph. Since the existence of an edge depends on its two endpoints, the initial mask score of each edge is adjusted according to the calculated node mask scores, so that its final score does not exceed that of its two endpoints, ensuring logical consistency; if a node is connected to at least one edge, it is not isolated, so the mask score of the node is adjusted according to the mask scores of its adjacent edges to reduce the interference of isolated nodes on similarity calculation.
[0028]
[0029]
[0030]
[0031] The Target Graph Re-Encoder module utilizes mask scores to identify and re-encode multiple most similar candidate substructures in Gt, repeatedly executing the adaptive graph masking module. Next, T different mask scores are generated to identify T different candidate substructures; for the k-th candidate substructure, The initial node and edge embeddings are multiplied by their corresponding mask scores to obtain a "soft-selected" initial state. A masked GNN (EGIN in this implementation, with Lr=8 layers) is used to pass Lr layers of messages to these "soft-selected" initial states, allowing the masking effect to propagate in the graph. The node representations of each layer after recoding are concatenated, and then summed and pooled and a fully connected network are used to obtain the graph-level representation of the k-th candidate substructure.
[0032] Multi-View SED Predictor Construction: This module integrates multiple types of information to predict SED from multiple perspectives.
[0033] For the k-th candidate substructure, generate its multi-view representation: Node-induced representation: Based on the node mask score, ... The node-level representations are weighted and summed; edge-induced representation: first, the edge-level representations are weighted and aggregated in the neighborhood of each node according to the edge mask score, and then the aggregation results of all nodes are summed; recoded representation: the representation obtained in the previous step is used directly.
[0034] The three representations above are concatenated and fused using a multilayer perceptron to obtain the final representation. .
[0035] Compute the query graph in the same way as the target graph (using the same network structure, but without masking). T represents For each pair The differences between the predicted values are calculated and mapped to a distance prediction value using a nonlinear function. Finally, the average of the T predicted values is taken to obtain the final SED prediction value. .
[0036] The embodiments of the present invention are given for illustrative and descriptive purposes only, and are not intended to be exhaustive or to limit the invention to the forms disclosed. Many modifications and variations will be apparent to those skilled in the art. The embodiments were chosen and described in order to better illustrate the principles and practical application of the invention, and to enable those skilled in the art to understand the invention and to design various embodiments with various modifications suitable for a particular purpose.
Claims
1. A method for computing subgraph edit distance based on graph neural network, characterized in that, Comprising the following steps: (1) Obtain query graph and target graph ; (2) Query graph and target graph generate node-level and edge-level isomorphic encoding representations respectively through unified graph isomorphic encoder to capture the impact of node and edge specific editing operations on graph topology; (3) the target graph Gt is input into the adaptive graph mask module The adaptive graph mask module combines the query graph Gq and the target graph Gt through a gated attention mechanism The mask score represents the generation of nodes and edges, which screens out irrelevant parts and dynamically balances the size difference of the graph (4) target map based on mask score Multi-head mask processing is performed to generate multiple candidate substructures, and a mask graph neural network is used for re-encoding; (5) The multi-view SED Predictor fuses the node view, edge view and re-encoded view of the graph-level representation, and outputs an approximate value of the subgraph edit distance.
2. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, The unified graph isomorphism encoder execution process comprises: (1) Initialization representation: use two multi-layer perceptrons to generate the initial representation of nodes and edges, respectively and ; (2) Node-level isomorphism encoding: the representation of the node is expanded through the edge expansion graph isomorphism network as the basic GNN model, and the node representation is iteratively updated; (3) Edge-level isomorphism encoding: the original graph structure is converted into its dual hypergraph through a dual hypergraph transformation, which is used to iteratively update the edge representation.
3. The graph neural network-based subgraph edit distance calculation method according to claim 2, wherein the initialization step comprises: The update rule of the graph isomorphism network is: (1) For the query graph and target map Each node in Tag it Transform a one-hot vector ; (2) mapping as initial node embeddings by a two-layer MLP mapping as initial node embeddings ; (3) For each edge in the graph convert its label to a one-hot vector and map it to an initial edge embedding through another two-layer MLP .
4. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, (2) After L-layer iterative update, the node representations of each layer are spliced to obtain the final representation of the node level, specifically: (1) For the first layer, the node updates its representation according to the aggregation of its own representation and the representations of the neighbor nodes, in particular: in, It is a node No. Layer representation, Represents nodes The set of adjacent nodes, It is a nonlinear transformation function. These are learnable parameters; The update rule of the dual hypergraph transformation is: wherein, denotes concatenation, is a two-layer fully connected layer to compress the concatenated information.
5. The subgraph edit distance calculation method based on a graph neural network according to claim 2, characterized in that, The mask score calculation step comprises: (1) Each edge in the original graph Nodes mapped to a dual hypergraph Each node in the original graph Mapped to the hyperedge of a bi-hypergraph The hyperedge contains all elements related to... The super-body node corresponding to the connected edges; (2) running a hypergraph isomorphism network (HGIN) on the dual hypergraph: for each hyperedge , aggregate node features according to its contained node set and fuse hyperedge itself features to generate a hyperedge message ; (3) For each dual hypergraph node update the node representation according to the hyperedge messages connected to it, resulting in wherein, represents a hyperedge set containing nodes ; (4) After updating by L-layer iteration, the node representations of each layer are spliced and mapped to the edge-level representation of the original graph As the output of edge-level isomorphism encoding, specifically: 。 6. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, (3) Score correction step: normalize and nonlinearly transform the initial node mask score and edge mask score to ensure that the mask score is in the [0, 1] interval; (1) Cross-graph interaction step: input the node representation of the target graph and the global representation of the query graph to a gated attention network to obtain initial node mask scores; (2) Edge association step: according to the target graph The initial mask score of the edge is generated according to the edge relationship between the two nodes and the mask score of the corresponding node. (5) Output step: output the corrected node mask score and edge mask score for subsequent multi-head mask processing steps. (4) Scale balancing step: according to the target graph and the scale difference of the query graph , the normalized mask scores are weighted and corrected so that graphs of different scales can be calculated in a unified scale. The multi-head mask processing comprises:
7. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, (1) Multi-head mask generation, which is used to input the node mask score and edge mask score into multiple mask channels according to the preset number of multi-heads; (2) In each mask channel, the target graph is selected and extracted according to the corresponding mask score to form multiple candidate substructures; (3) The candidate substructures are input into the mask graph neural network for re-encoding to obtain the graph-level representation of the candidate substructures; (4) Output the re-encoded representation of the multiple candidate substructures for subsequent multi-view SED Predictor. The number of heads of the multi-head mask processing is 3 to 6, each head independently generates a group of candidate substructures, and each head is re-encoded.
8. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, The mask graph neural network is a graph convolution network, a graph attention network or a graph sampling aggregation network.
9. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, The execution steps of the multi-view predictor comprise:
10. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that, (1) Using the node-level representation to weight and converge the graph to obtain a graph-level vector of the node view; (2) Using the edge-level representation to weight and converge the graph to obtain a graph-level vector of the edge view; (3) Using the re-encoded results of the candidate substructures after multi-head mask processing to obtain a graph-level vector of the re-encoded view; (4) Splicing or weighted fusion of the graph-level vectors of the node view, edge view and re-encoded view to obtain a comprehensive multi-view representation; The mask graph neural network supports the input of labeled graphs and unlabeled graphs, and dynamically adjusts the graph structure input according to the mask score. (5) Based on the integrated multi-view representation, output the subgraph edit distance approximation between the query graph and the target graph through a fully connected layer. and target graph 11. The subgraph edit distance calculation method based on a graph neural network according to claim 1, characterized in that,