D ETECTING S MALL Q UERY G RAPHS IN A L ARGE G RAPH VIA N EURAL S UBGRAPH S EARCH
Anonymous authors
Paper under double-blind review
A BSTRACT
Recent advances have shown the success of using reinforcement learning and search to solve NP-hard graph-related tasks, such as Traveling Salesman Optimization, Graph Edit Distance computation, etc.
However, it remains unclear how one can efficiently and accurately detect the occurrences of a small query graph in a large target graph, which is a core operation in graph database search, biomedical analysis, social group finding, etc.
This task is called Subgraph Matching which essentially performs subgraph isomorphism check between a query graph and a large target graph.
One promising approach to this classical problem is the “learning-to-search” paradigm, where a reinforcement learning (RL) agent is designed with a learned policy to guide a search algorithm to quickly find the solution without any solved instances for supervision.
However, for the specific task of
Subgraph Matching, though the query graph is usually small given by the user as input, the target graph is often orders-of-magnitude larger.
It poses challenges to the neural network design and can lead to solution and reward sparsity.
In this paper, we propose NS UB S with two innovations to tackle the challenges: (1) A novel encoder-decoder neural network architecture to dynamically compute the matching information between the query and the target graphs at each search state; (2) A novel look-ahead loss function for training the policy network.
Experiments on six large real-world target graphs show that NS UB S can significantly improve the subgraph matching performance.
I NTRODUCTION
With the growing amount of graph data that naturally arises in many domains, solving graph-related tasks via machine learning has gained increasing attention.
Many NP hard tasks, e.g. Traveling
Salesman Optimization (Xing & Tu, 2020), Graph Edit Distance computation (Wang et al., 2021),
Maximum Common Subgraph detection (Bai et al., 2021), have recently been tackled via learningbased methods.
These works on the one hand rely on search to enumerate the large solution space, and on the other hand use reinforcement learning (RL) to learn a good search policy from training data, thus obviating the need for hand-crafted heuristics adopted by traditional solvers.
Such learning-tosearch paradigm (Bai et al., 2021) also allows the training the RL agent without any solved instances for supervision.
However, how to design a neural network architecture under the RL-guided search framework remains unclear for the task of Subgraph Matching, which requires the detection of all occurrences of a small query graph in an orders-of-magnitude larger target graph.
Subgraph Matching has wide applications in graph database search (Lee et al., 2012), knowledge graph query (Kim et al., 2015), biomedical analysis (Zhang et al., 2009), social group finding (Ma et al., 2018), quantum circuit design (Jiang et al., 2021), etc.
As a concrete example, Subgraph Matching is used for protein complex search in a protein-protein interaction network to test whether the interactions within a protein complex in a species are also present in other species (Bonnici et al., 2013).
Due to its NP-hard nature, the state-of-the-art Subgraph Matching algorithms rely on backtracking search with various techniques proposed to reduce the large search space (Sun & Luo, 2020; Kim et al., 2021; Wang et al., 2022).
However, these techniques are mostly driven by heuristics, and as a result, we observe that such solvers often fail to find any solution on large target graphs under a reasonable time limit, although they tend to work well on small graph pairs.
We denote this phenomenon as solution sparsity .
Such solution sparsity requires the designed model to not only have enough capacity but also to run efficiently under limited computational budget.
Another consequence of solution sparsity is that, there can be little-to-no reward signals for the RL agent under an RL training framework (Silver et al., 2017), which we denote as reward sparsity .
In this paper, we propose NS UB S with two means to address the aforementioned challenges.
First, we propose a novel graph encoder-decoder neural network to dynamically match the query graph with the target graph and perform aggregation operation only on the query graph to reduce information loss.
The novel encoder decouples the intra-graph message passing module (the “propagation” module) that yields state-independent node embeddings, and the inter-graph message passing module (the “matching” module) that refines the node embeddings via subgraph-to-graph matching.
Thus, the intra-graph embeddings can be computed only once at the beginning of search for efficient inference.
We further advance the inter-graph message passing by propagating only between nodes that either are already matched or can be matched in future by running a local candidate search space computation algorithm at each search state.
Such algorithm leverages the key requirement of Subgraph Matching that every node and edge in the query graph must be matched to the target graph, and therefore reduces the amount of candidates from all the nodes in the target graph to a much smaller amount.
Compared with a Graph Matching Network (Li et al., 2019) which computes all the pairwise node-to-node message passing between two input graphs, our matching module is able to focus on only the node pairs that can contribute to the solution, and thus is both more effective and more efficient.
In addition, we propose the use of sampling of subgraphs to obtain ground-truth subgraph-to-graph node-node mappings to alleviate the reward sparsity issue during training.
We design a novel look-ahead loss function where the positive node-node pairs are augmented with positive node-node pairs in future states to boost the amount of training signals at each search state.
Experiments on synthetic and real graph datasets demonstrate that NS UB S outperforms baseline solvers in terms of effectiveness by a large margin.
Our contributions can be summarized as follows:
• We address the challenging yet important task of Subgraph Matching with a vast amount of practical applications and propose NS UB S as the solution.
• One key novelty is a proposed encoder layer consisting of a propagation module and a matching module that dynamically passes the information between the input graphs.
• We conduct extensive experiments on real-world graphs to demonstrate the effectiveness of the proposed approach compared against a series of strong baselines in Subgraph Matching.
P RELIMINARIES 2. P ROBLEM D EFINITION
We denote a query graph as q =
( V q , E q ) and a target graph as G =
( V G , E G ) where V and E denote the node and edge sets.
q and G are associated with a node labeling function L g which maps every node into a label l in a label set Σ .
Subgraph :
For a subset of nodes S of V q , q [ S ] denotes the subgraph of q with an node set S and a edge set consisting of all the edges in E q that have both endpoints in S .
In this paper, we adopt the definition of non-induced subgraph.
Subgraph isomorphism : q is subgraph isomorphic to G if there exists an injective node-to-node mapping
M : V q → V G such that (1) ∀ u ∈ V q , L g ( u ) =
L g ( M ( u )) ; and (2) ∀ e ( u,u ′ )
∈
E q , e ( M ( u ) ,M ( u ′ ))
∈ E
G .
Subgraph Matching :
The task of Subgraph Matching aims to find the subgraphs in G that are isomorphic to q .
We call M a solution, or a match of q to G .
We call a pair ( q, G ) is solved if the algorithm can find any match under a given time limit, which we find a challenge for existing solvers on input graphs in experiments especially on large graphs.
For solved pairs, the number of found subgraphs by an algorithm is reported.
2. R ELATED W ORK
Non-learning methods on Subgraph Matching
Existing methods on Subgraph Matching can be broadly categorized into backtracking search algorithms (Shang et al., 2008; He & Singh, 2008; Han et al., 2013; 2019;
Kim et al., 2021; Wang et al., 2022) and multi-way join approaches (Lai et al., 2015; 2016; 2019; Kankanamge et al., 2017).
The former category of approaches employ a branch and bound approach to grow the solution from an empty subgraph by gradually seeking one matching node pair at a time following a strategic order until the entire search space is explored.
The multi-way join approaches rely on decomposing the query graph into nodes and edges and performing join operations repeatedly to combine the partially matched subgraphs to q .
However, they tend to work well on small query graphs generally with less than 10 nodes (Sun & Luo, 2020), and thus we follow and compare against methods in the former category, whose details will be shown in Section 2.3.
Learning-based methods for subgraph-related problems The idea of designing graph neural networks for graph-graph similarity has been explored, but not Subgraph Matching. GMN (Ling et al., 2020) captures general notions of graph similarity through inter-graph message passing, but outputs a similarity score instead of the discrete matching between 2 graphs. DMPNN (Liu & Song, 2022) uses node to edge conversions to obtain node and edge representations that better preserve isomorphism properties, but outputs approximate subgraph isomorphism counts instead of a discrete matching. Representation learning methods for Subgraph Matching use a geometric loss to provide soft nodenode correspondance scores, stops short of providing a discrete mapping of where the query occurs in the target graph.
For example, NM ATCH (Lou et al., 2020) learns node embeddings to predict a score for an input subgraph-graph pair indicating whether the subgraph is contained in another graph. I SO N ET (Roy et al., 2022) extends this idea using edge-edge correspondence scores to rank which query graphs are most likely to appear in the target.
Another direction of research aims to perform subgraph counting (Liu et al., 2020; Chen et al., 2020) supervised on the number of specific substructures, and again lacks an explicitly search strategy and thus falls short of yielding solutions for Subgraph Matching. Researchers tackling consistent subgraph matching (Yuan et al., 2022) handle complex node or edge constraints using a Subgraph Matching subroutine. Hence, advancements to Subgraph Matching can directly benefit such works.
Efforts on using RL for graph NP-hard problems
The idea of using RL to replace heuristics in search algorithms for NP-hard graph-related tasks is not new, and we identify three works similar to the present work.
(1) GLS EARCH (Bai et al., 2021) detects the maximum common subgraph (MCS) in an input graph pair, which is different from Subgraph Matching which requires the entire q to be matched with G , allowing further improvement in the neural network and search design.
RL-QVO (Wang et al., 2022) tackles Subgraph Matching via ordering the nodes in the query graph as a global pre-processing step before search, which is an orthogonal direction to our approach to select nodes in the target graph computed at each search step.
2. S EARCH - BASED METHODS FOR S UBGRAPH M ATCHING
Due to the NP-hard nature of Subgraph Matching, backtracking search is a naturally suitable algorithm since it exhaustively explores the solution space by starting with an empty match and adding one new node pair to the current match at each step.
When the current match cannot be further extended, the search backtracks to its previous search state, and explores other node pairs to extend the match.
However, naively enumerating all the possible states in the entire search space is intractable in practice, and therefore existing efforts mainly aim to reduce the total number of search steps for the backtracking search via mainly three ways (Sun & Luo, 2020): (1) Filter nodes in G to obtain a small set of candidate nodes for each node in q as a pre-processing step before the backtracking search; (2) Order the nodes in q before the search; (3) Generate a local candidate set of nodes in each step of the search based on the current search state.
Algorithm 1 summarizes the overall backtracking search based framework for Subgraph Matching.
It is worth noting that the first three means correspond to the three steps in the algorithm, and therefore any improvement in any of the three steps can be regarded as orthogonal to each other.
The basic idea of backtracking search is outlined in Algorithm 2.
The recursive algorithm starts with an empty node-node mapping, and tries to add one new node pair to the mapping M at each recursive call.
The action is the new node pair ( u t , v t ) , where u t ∈ V q is selected according to the heuristic-based ordering ϕ , and v t ∈ V G is selected according to a policy (which is to be learned by NS UB S) to be one of the local candidate nodes (line 8), that can be mapped to u t .
It is noteworthy that this local candidate node set “ A u t ⊆
V G ” is refined over the global candidate sets C based on the current search state s t .
s t is defined as ( q, G ) along with the current mapping M and u t .
A u t ⊆
V G ensures any node in A u t would lead to the extended subgraphs at s t still being isomorphic to each other.
Thus, the local candidate set A u t for u t is the action space, for which we learn a policy (line 9) to order the nodes, resulting in an ordered list A u t , ordered .
1: Input: q , G , C mapping M .
2: Output: Subgraph match mappings.
3: if | M | = | V q | then 4: output M ; 5: return; 6: end if 7: u t ∈ V q ← ϕ ( M ) ; 8: A u t ← s t .getLocalCand ( u t ) ; 9: A u t , ordered ← policy ( s t , A u t ) ; 10: for v t in A u t , ordered do 11:
M ← M.add ( u t , v t ) ; 12: Backtracking ( q, G, C, ϕ, M ) ; 13: M ← M.remove ( u t , v t ) ; 14: end for Despite existing efforts to compute a small C , a good ϕ , and a small A u t to reduce search space, we observe that the size of A u t can be up to thousands of nodes for many real-world large target graphs, calling for a smarter policy to order the nodes not only in q but also in G ( A u t to be specific).
To the best of our knowledge, all the existing methods adopt a random ordering in A u t , ordered .
We conjecture it is because existing local candidate computation techniques can further prune nodes from C , and thus enumerating A u t in a random ordering can be tractable on small graph pairs.
We will experimentally show that this attributes to their failure to find a match for many large graph pairs.
In fact, a theoretically perfect policy, policy ∗ , can find the entire match of the query graph in V q steps or recursive calls, assuming q has at least one match with G .
This again inspires our proposed method to improve the policy for node selection from A u t .
P ROPOSED M ETHOD
In this section we formulate the problem of Subgraph Matching as learning an RL agent that grows the extracted subgraphs by adding new node pairs to the current subgraphs.
We first describe the environment setup, then depict our proposed encoder-decoder neural network which provides actions for our agent to grow the subgraphs in a search context.
3. RL F ORMULATION OF S UBGRAPH M ATCHING
We formulate the Subgraph Matching problem as a Markov Decision Process (MDP), where the RL agent starts with an empty solution, and iteratively matches one node pair at a time until no more nodes can be matched.
As mentioned in Section 2.3, our policy assigns a score to each action in A u t , and therefore can be modeled as a policy network P θ ( a t | s t ) that computes a probability distribution over A u t for the current state s t , where the node pair to select consists of ( u t , v t ) .
However, since u t is chosen by ϕ , we regard an action as a node v t selected from A u t .
Since each action is a target node in A u t , the neural network must learn good node embeddings that capture the current matching status in each search state, which will be shown in Section 3.2.
We define our reward as R (+) =
if the subgraph is fully matched and R ( − ) = 0 otherwise.
To provide ample training signals to the neural network model, during training, we randomly sample subgraphs from the target graph and record the mapping between the nodes in the sampled subgraph and V G .
Therefore, after the search, we collect the positive training signals at each state as all the node-node pairs ( u, v ) that lead to a solution.
The collection of such positive pairs is denoted as
P ( s t ) .
Negative pairs N ( s t ) can be obtained by randomly sampling node-node pairs at each s t from the action space A u t .
However, the solution sparsity issue mentioned previously causes insufficient positive pairs.
We therefore propose the following look-ahead loss function which augments P ( s t ) with the positive node-node pairs in future states.
Overall, the look-ahead loss function can be formulated as
[Equation]
where T corresponds to the final step that matches the entire subgraph, and L ′ la is the cross-entropy loss computed at s t
+ k .
Specifically, L ce ( s t + k ) is the cross entropy loss and computed as the negative of the following:
[Equation]
where π θ (cid:0) ( u, v ) | s t (cid:1)
= σ (cid:16) P logit (cid:0) ( u, v ) | s t (cid:1)(cid:17) denotes the raw output of the policy network followed by applying the Sigmoid function.
Since we define R (+) = 1 and R ( − ) = 0 , L ce ( s t + k ) is simplified as
[Equation]
In addition to the look-ahead loss that encourages the policy network to recognize positive node-node pairs, we also adopt the max margin loss, L mm , proposed in Lou et al.
(2020) to encourage the encoder to produce subgraph-graph relation aware node embeddings h .
Our overall loss function is the combination of the novel look-ahead loss function and the max margin loss function, i.e.
L total =
L la + L mm .
More details can be found in the appendix.
3. E NCODER -D ECODER D ESIGN FOR P OLICY E STIMATION
Our neural network consists of an encoder which produces node-level embeddings for V q and V G and a decoder which transforms the node embeddings into P θ ( a t | s t ) .
We identify the following challenges: (1) Each state s t consists of q , G , and the mapping M t between the matched nodes
S t,q ⊆ V q and S t,G ⊆ V G , which should be effectively represented and utilized in predicting
P θ ( a t | s t ) ; (2) P θ ( a t | s t ) is dependent on s t and a t , potentially requiring the node embeddings to be recomputed at every search step and incurring too much computational overhead; (3) Existing Graph
Neural Networks (GNN) relying on message passing (e.g. Kipf & Welling (2016); Velickovic et al.
; You et al.
(2020)) are inherently local, which are incompatible with the policy estimation requiring global matching of q to G .
Even the more recent GNNs that enhance expressiveness beyond 1-Weisfeiler-Lehman test (Morris et al., 2020; Wijesinghe & Wang, 2022) still cannot guarantee the capturing of nodes in the solution, since otherwise the NP-hard task would then be solved.
This motivates the following design leveraging the properties of Subgraph Matching as much as possible.
3.2. E NCODER : E MBEDDING G ENERATION VIA Q C -S GMNN
The nodes of q and G are encoded into initial one-hot embeddings h (0) ∈ R | Σ | , and fed into
K sequentially stacked Query-Conditioned Subgraph Matching Neural Networks (Q C -S GMNN ) layers to obtain h ( K ) ∈ R D , where D is the dimension of embeddings, followed by a J UMPING
K NOWLEDGE (Xu et al., 2018) network to combine the node embeddings from the K layers to obtain the final node embeddings, denoted as “Aggregate” in Figure 1.
We start by observing that Subgraph Matching desires all nodes in q to be matched with G , and existing works in Subgraph Matching aiming at reduce A u t (Section 2.3) guarantee no false pruning.
In other words, A u t is guaranteed to contain the solution nodes in G that should match with u t , that is, A u t provides useful hints of which nodes should be matched together.
We then compute the candidate space A u ′ for every remaining query graph node u ′ / ∈ S t,q , resulting in a mapping
M ′ t = { u ′ (cid:55)→ A u ′ , ∀ u ′ ∈
V
q \ S t,q } .
Intuitively, M ′ t can be regarded as hints of future node-node mappings.
In contrast, M t = { u (cid:55)→ { v } , ∀ u ∈ S t,q } reflects the current state s t , which maps each node in S t,q to a unique node in G .
We define ˜ M t as the union of M t and M ′ t , and define ˜ M − 1 t as the reverse mapping of ˜ M t , which serve as the basis for the matching module.
Q C -S GMNN consists of a propagation module, which performs regular intra-graph message passing on q and G individually, and a matching module, which performs state-dependent subgraph-graph [Figure] … … 𝑆 " matching leveraging ˜ M t to pass information between q and G .
Specifically,
[Equation]
The first two steps can be any intra-graph message passing GNNs such as Graph Attention Networks (Velickovic et al., 2018) with a message function f msg and an aggregation function f agg , corresponding to the propagation module.
The middle three steps compute intermediate embeddings that will be used for the last two steps, i.e. the matching module.
Specifically, h ( k +1) u,G → q and h ( k +1) v,q → G compute the cross-graph message passing from G to q and q to G using ˜ M t and ˜ M − 1 t , respectively (represented as the red dashed lines in Figure 1).
A graph-level embedding h ( k ) q, intra is computed via f readout and used in the information passing from q to G to let the embeddings of V G queryconditioned.
We do not inject the graph-level embeddings of G into h ( k +1) u,G → q , since the large size of
G could result in too much information loss in the readout operation.
The last two steps combine the intra-graph embeddings and inter-graph embeddings via f combine to produce the final output embeddings.
It is noteworthy that f msg and f agg refer to the general class of functions that yield messages between two nodes and performs aggregation on a set of messages, and in practice, the propagation and matching modules can use different functions for f msg and f agg .
To address challenge (2), we make the observation that h ( k ) intra only depends on q and G and is independent of M t , and thus can be computed once and cached at the beginning of the search (denoted as the top branch in Figure 1) and later reused throughout the search.
Our Q C -S GMNN decouples the propagation and matching steps and outputs two sources of information separately, allowing the search to cache the state-independent node embeddings and dynamically select the computational paths during search.
Thanks to the caching, only the initial iteration requires the
O ( | E q | + | E G | ) computation, and all the subsequent iterations only involve O (cid:0) | V
q
||
¯
A u t | (cid:1) complexity, where | ¯ A u t | is the average size of local candidate space.
3.2. D ECODER : P θ ( a t | s t ) E STIMATION
Since the node embeddings of q has received the right amount of information from ˜ M t , we propose an attention-based mechanism to compute the state embedding: h s t = (cid:80) u ∈ V q f att ( h u , { h ′ u | u ′ ∈
V q } ) h u , where f att computes one attention score per node normalized across V q to tackle challenge (3).
Intuitively, the attention function learns which nodes are important for contributing to the eventual subgraph selected by s T .
Due to the cross-graph communication in Q C -S GMNN , we only aggregate nodes from V q to obtain the state representation h s t , taking advantage of the fact that | V q | is typically much smaller than | V G | in Subgraph Matching, further addressing challenge (2).
For the policy, we aim to tackle challenge (3), by using h s t .
The reasons are two-fold.
First, by definition P θ ( a t | s t ) requires s t as input; Second, the attention mechanism used to compute h s t capturing the future subgraph.
Combined with a bilinear tensor product with learnable parameter
W [1: F ] ∈ R D
× D × F with a hyperparameter F to allow the action node embeddings h u t and h v t to fully interact, we obtain P logit ( a t | s t ) =
MLP (cid:0) CONCAT( h Tu t W [1: F ] h v t , h s t ) (cid:1) , followed by a softmax normalization over the logits for all the actions.
The decoder has time complexity
O (cid:0) | V q | + | ¯ A u t | (cid:1) .
E XPERIMENTS
We evaluate NS UB S against seven backtracking-based algorithms for exact Subgraph Matching, and conduct experiments on six real-word target graphs from various domains, whose details can be found in the supplementary material.
We find NS UB S written in Python can outperform the state-of-the-art solver under most cases, suggesting the effectiveness of the learned policy for ordering nodes in
G .
Code, trained model, and all the datasets used in the experiments are released as part of the supplementary material for reproducibility.
More results and the ablation study can be found in the supplementary material.
4. D ATASETS AND E VALUATION P ROTOCOL
[Table]
We use one synthetic dataset BA and six realworld target graphs.
For D BLP and Y OUTUBE , we prepare two query sets of small and large query graphs, denoted as “-S” and “-L”, respectively, i.e. D BLP -S, D BLP -L, and Y T -S, Y T -L.
As shown in Table 1, the largest target graph,
Y OUTUBE , has over 1M nodes and 2M edges.
To train our model, we sample query graphs of any sizes and let NS UB S perform the search algorithm and collect training data from the search tree.
Therefore, we sample query graphs from each target graph of sizes ranging from 4 nodes to 128 nodes, and validate that no query graph in the testing set is visible to the model, that is, no graph in the training set is isomorphic to any graphs in the testing set.
During the testing stage, for each target graph, we use the following evaluation protocol.
For each graph pair, we set a time limit of 5 minutes, and record the result of whether a solution is found or not, and the number of solutions for solved pairs.
4. B ASELINES AND P ARAMETER S ETTINGS
We compare NS UB S against a series of baseline solvers whose source codes are provided by (Sun & Luo, 2020): L DF (Sun & Luo, 2020), N LF (Sun & Luo, 2020), Q UICK SI (Shang et al., 2008),
G RAPH QL (He & Singh, 2008), T SO (Han et al., 2013), C FL (Bi et al., 2016), C ECI (Bhattarai et al., 2019), and DP- ISO (Han et al., 2019).
We also include NM ATCH
(Lou et al., 2020) as a learningbased method for exact Subgraph Matching, by adapting the original implementation provided by the authors of (Lou et al., 2020) into our backtracking search framework.
Specifically, at each search step, we invoke the inference step of the released trained NM ATCH model over the input graphs, and obtain a matching score for each ( u t , v t ) action node pair to guide the selection of nodes in A u t .
Since we are among the first to learn a policy for selecting nodes in G , we use DP- ISO for filtering and G RAPH QL for query node ordering.
We implement the backtracking search framework and
DP- ISO ’s local candidate computation algorithm in Python.
NS UB S uses 8 layers of the proposed Q C -S GMNN encoders.
ω is set to 10 and max _ iters is set to 120.
Training is performed on a server with NVIDIA Tesla V100 GPUs.
We train NS UB S for approximately 2 days with randomly sampled subgraphs for each target graph with the AdamW optimizer (Loshchilov & Hutter, 2017) with the initial learning rate 0.0005 and the ϵ parameter set to 0.01 for numerical stability.
Gradient clipping is applied with the maximum norm of the gradients set to 0.1.
We use a validation set to select the best model to evaluate.
[Figure]
4. R ESULTS
To examine the efficiency of each method and analyze the efficacy across time, we conduct the following evaluation.
For each ( q, G ) pair, we record the time the method takes to find a solution, and accumulate the number of solved pairs across time.
From t = 0 to t = 300 seconds, an increase at t indicates the method solves one graph pair at t .
The earlier a method solves the graph pairs, the faster and better the method is.
In theory, given an infinite amount of time, every method adopting the backtracking search algorithm would be able to solve a graph pair.
However, such assumption is not practical.
Thus, the curves in
Figure 2 have the practical implication that under a reasonable amount of time budget, the idea of using a smarter policy indeed brings better performance to Subgraph Matching.
Another observation is that the baseline solvers flatten towards the end of 5 minutes, indicating that they get stuck in [Table] unpromising search states that are unlikely to contain the solution, confirming the severity of the aforementioned challenges of solution and reward sparsity.
As shown in Figure [Table] NS UB S initially seems not as good as other models in the first few seconds due to the additional neural network computational overhead at each step, but achieves the same or better performance on all of the 9 query sets after 5 minutes.
We observe baseline solvers tend to fail on larger target graphs, as search space pruning on its own is not effective enough to guarantee solutions in such cases with a large amount of candidate nodes.
Learning-based methods outperform solver baselines because they provide a better target graph node ordering, under the same search framework.
Out of the learning-based methods, NS UB S consistently outperforms NM ATCH , as it features a more powerful encoder that efficiently computes a policy conditioned on the current search state with a better inter-graph communication mechanism.
This also suggests that the target graph node ordering provided by NS UB S is much better than the random ordering adopted by solver baselines, confirming that our novelties indeed greatly improve Subgraph Matching performance.
We observe that when the query graph size increase, all methods tend to show lower performance, which can be attributed to the exponentially growing search space.
It is noteworthy that the survey paper comparing existing solvers (Sun & Luo, 2020) uses query graphs up to 32 nodes, whereas we challenge all methods by testing on query graphs up to hundreds of nodes.
The fact that NS UB S is able to solve more graph pairs than baselines when the target graphs are large demonstrates good scalability of NS UB S.
Given the nature of Subgraph Matching, we also evaluate the ability of each method to find as many solutions as possible.
As Table 2 indicates, NS UB S outperforms baseline methods on 7 out ofdatasets, suggesting that the slower but more intelligent NS UB S can not only ensure one solution is found, but also provide as many as and even more solutions compared against the faster baseline solvers.
The exceptions are HPRD and E THE , where G RAPH QL solves less pairs as shown in
Figure 2, but on average finds more solutions per graph pair across these two datasets.
We empirically observe that the baseline solvers tend to find many solutions because as soon as one solution is found, nearby solutions can be found.
In contrast, NS UB S continues performing neural network operations after one solution is found.
This indicates the efficiency limitation of the current model, and calls for the need for future efforts to speed up the neural network computation, design even better policy network and training methods to allow discovery of more solutions in lesser iterations, etc.
C ONCLUSION
In this paper, we tackle the challenging and important task of Subgraph Matching, and present a new method for efficient and effective exact Subgraph Matching.
It contains a novel encoder-decoder neural network architecture trained using a novel look-ahead loss function and a max margin loss to improve the policy estimation as well as the encoder.
The core component, Q C -S GMNN , is a queryconditioned graph encoder that performs intra-graph propagation and inter-graph node matching to capture each state.
To address the reward sparsity issue posed by the large action space, we augment the positive node-node pairs at each search step with future states’ node-node pairs.
We experimentally show the utility of the proposed NS UB S method on the important Subgraph Matching task.
Specifically, NS UB S is able to solve more graph pairs than several existing Subgraph Matching solvers on one synthetic dataset and six large real-world datasets.
A D ETAILS ON T RAINING AND T ESTING OF NS UB S A. D ETAILS ON C OLLECTING T RAINING S IGNALS
As mentioned in the main text we utilize the max margin loss proposed in Lou et al.
(2020) which can be written as
[Equation]
where
[Equation]
The intuition behind the loss function is to encourage the encoder to produce node embeddings that capture the subgraph-graph relationship.
Specifically, the loss encourages each dimension of h u to be less than h v , and the error term E measures the deviation of the current node embeddings from this desired property.
It is noteworthy that both L la and L mm rely on the positive and negative node-node pairs, which are obtained by performing search on ( q, G ) pairs where q is the randomly sampled training subgraph queries from G .
Therefore, the overall NS UB S model does not need any pre-solved graph pairs for training.
Here we describe more details on how we prepare the positive node-node pairs P ( s t ) .
During training, we set a time limit of 5 minutes for each ( q, G ) pair, and at the end of the search process, we obtain a search tree where each node in the search tree corresponds to a state s t .
For a state s t , we look ahead at all sequences of states leading to a solution starting from s t , and compute the L la loss according to Equation 1 for each sequence, and sum up the loss for all such sequences.
To obtain N ( s t ) , we randomly sample | P ( s t ) | node-node pairs from the action space
A u t , where u t is the query graph node selected by ϕ as described in Section 2.3, and A u t is the local candidate nodes in G to be selected by the neural network.
A. D ETAILS ON T ESTING G RAPH P AIRS
We conduct evaluation on the following testing graph datasets:
The synthetic dataset BA is unlabeled and generated using the Barabási–Albert model (Barabási & Albert, 1999) with the parameter of attachment set to 3.
We sample 50 query graphs each of 64 nodes as the query set.
The sampling algorithm starts with a randomly selected initial node, and then performs random walk until a subgraph consisting of a pre-defined number of nodes is sampled.
Each step in the random walk selects a node from the neighboring nodes of the current node to visit in the next step, where the node can be a new node or an already selected node , i.
e. the random walk is allowed to backtrack.
We define the raw sampling probability to be
/p if the node is the selected subgraph
and p otherwise
A small p therefore encourages re-visitation and the final subgraph tends to be “star“-like, while
a
large
p typically yields a more “path“-like
subgraph.
Each of the
50 sampled
subgraphs uses a different p parameter by sweeping across the range from 0 .
001 to 1000 .
Specifically, the i -th sampled subgraph uses p = 0 .
001 ∗ exp (cid:0) log(10 6 ) / 49 ∗ ( i − 1) (cid:1) , i.e. the first subgraph uses p = 0 .
001 , the second uses p = 0 . 00133 , the third uses p = 0 . 00176 , etc.
The 49th subgraph uses p = 754 .
312 , and the last uses p = 1000 .
Without specific mentioning, the sampling of subgraphs for other datasets uses this algorithm
The B RAIN dataset is obtained from mouse retina connectome (Helmstaedter et al., 2013) with node labels representing the coarse type determined from supplemental text (Jonas, 2015).
We sample 50 query graphs each of of 64 nodes.
There are 5 types of node labels in total.
The HPRD target graph is a protein-protein interaction graph obtained from a recent survey paper on Subgraph Matching (Sun & Luo, 2020) without node labels.
Similar to B RAIN , we sample 50 64-node graphs as the query graphs. 4.
The C OSMOS graph represents the network of galaxies (Coutinho et al., 2016) without node labels, for which we sample 50 query graphs each of 32 nodes as queries.
The D BLP and Y OUTUBE target graphs are also used in the survey paper (Sun & Luo, 2020), but instead of sampling subgraphs as query graphs, we rely on ground-truth communities mined from an algorithm (Yang & Leskovec, 2012) as query graphs.
According to Leskovec & Krevl (2014), for D BLP , authors who published to a certain journal or conference form a community, and for Y OUTUBE , user -defined groups are considered as ground-truth communities.
Since many ground-truth communities are provided by Leskovec & Krevl (2014), we sample a 50-graph small query set and a 50-graph larger query set for these two datasets.
Specifically, D BLP -S contains communities of 20-30 nodes, D BLP -L contains communities of 30-60 nodes, Y T -S contains communities of 30-40 nodes, and Y T -L contains communities of 40-100 nodes.
The E
THE dataset is obtained from a recent paper on financial anomoly detection (Chen & Tsourakakis, 2022).
The graph represents 1-week Ethereum blockchain transactions where each edge represents a transaction with the amount.
We run the released code provided by the paper to extract top anomalous subgraphs, and filtering subgraphs that are too small or too large, yielding 24 subgraphs ranging from 6 to 822 nodes as query graphs.
Intuitively, these subgraphs are relatively dense and correlate with possibly malicious behavior.
We remove the transaction amount from the edges, and run Subgraph Matching using the mined subgraphs as query graphs and the original transaction graph as the target graph.
Although NS UB S can potentially be extended for clique or anomaly detection, we leave the investigation as future work.
A. D ETAILS ON T RAINING AND V ALIDATION G RAPH P AIRS
For each target graph, we sample query graphs of various sizes to perform curriculum learning, as shown effective by earlier graph matching works (Bai et al., 2021; Lou et al., 2020).
We ensure the testing query graphs and training query graphs are different by using different random seeds and further running an isomorphism checker to ensure none of the testing query graphs are visible during training.
The query graphs come in the following sizes: 8, 16, 24, 32, 48, 64, 96, and 128 nodes.
It is noteworthy that the query graphs are obtained from provided ground-truth communities or mined subgraphs for D BLP , E THE and Y OUTUBE for testing, but during training, all the query graphs are obtained via subgraph sampling.
Regarding the validation scheme, we use the following validation set for validating the models:query graphs of size 8, 3 query graphs of size 16, 3 query graphs of size 32, 3 query graphs of size 64, and 3 query graphs of size 128.
These 15 query graphs are sampled from the same target graph with different random seeds, and we ensure they are not isomorphic to any query graphs in the training set (nor isomorphic to any query in the testing set if the testing set is obtained via random subgraph sampling).
The overall training process consists of the following iterative steps: (1) Sample a query graph from
G and perform search with a limit of 5 minutes; (2) Collect training signals and add them to a replay buffer; (3) Perform training by sampling a batch of training examples from the replay buffer and running back-propagation; (4) Once every 5 times of performing search on training graph pairs, we iterate through the 15 graph pairs in the validation set with a time budget of 40 seconds, and record the validation reward, which is defined as the average best subgraph size.
We accept the trained model if the validation reward improves, and revert to the previous best model otherwise by loading the best model’s checkpoint.
At the end of the training process, we evaluate the best model that achieves the best validation performance.
A. D ETAILS ON H YPERPARAMETERS
For the encoder, we set the intra-graph f agg and f msg functions to G RAPH SAGE (Hamilton et al., 2017), and set the inter-graph f agg function to be SUM and f msg function to be dot-product style attention (Vaswani et al., 2017) over incoming messages.
Specifically, the message collected by each query node, h u,G → q ∈ R D , consists of attended node embeddings from v ′ ∈
˜ M t ( u ) .
Overall, h u,G → q is computed as
[Equation]
The message collected by each target node, h v,q → G ∈ R 2 D , consists of attended node embeddings from u ′ ∈
˜ M − 1 t ( v ) and the whole query graph embedding, h q, intra .
Overall, h v,q → G is computed as
[Equation]
(6) where
[Equation]
[Table] In total, we use four different MLPs, i.e. MLP q , MLP G , MLP VAL ,q , and MLP VAL ,G following (Vaswani et al., 2017), with an ELU( · ) activation after the final layer.
We set the f combine function to be the concatenation CONCAT followed by MLP .
We choose
MEAN as the readout function f readout for computing the query graph-level embedding.
We choose the MAX function as the aggregation function for our Jumping Knowledge network which aggregates the node embeddings.
We apply layer normalization (Ba et al., 2016) to the final node embeddings before feeding into the decoder.
For the encoder, we stack 8 layers of intra-graph message passing with dimension 16.
We stack 8layers of the inter-graph message passing with all MLP s outputting dimension 16.
For the decoder, we set MLP att to dimensions [16, 4, 1] and MLP v to dimensions [16, 32, 16, 8, 4, 1].
We set the policy head’s bilinear layer, W [1: F ] , to output dimension F = 32 and the policy head’s MLP to dimensions [48, 32, 16, 8, 1].
For all the MLP s, we use the ELU( x ) activation function on the hidden layers.
For MLP v , we apply a LeakyReLU( · ) function following the final layer.
The goal of the encoder is to learn good node embeddings that capture the structural matching of q and G , and thus we do not encode the node labels as initial encodings.
Instead, we rely on the candidate set generation algorithm to handle the constraint that only nodes of the same label can match.
Therefore, it is critical to encode the nodes into initial encodings properly.
A simple way to encode the nodes is to assign a constant encoding to every node in both q and G .
To enhance the initial encodings, we adopt Local Degree Profile (LDP) scheme (Cai & Wang, 2018) concatenated with a 2-dimensional one-hot vector indicating whether a node is currently selected or not.
Our replay buffer is of size 128.
During the training process, we repeatedly run 5 minutes of search, populating the replay buffer, 3 minutes of replay buffer sampling and back-propagation, training on as many replay buffer samples as possible, and performing validation to choose whether or not we commit the learned model.
One iteration of this process typically takes around 10 minutes.
Hyperparameters were found by tuning for performance manually against the validation dataset.
B N OTES ON S EARCH B. I NDUCED
VS N ON -I NDUCED S UBGRAPHS 𝑞 is an induced subgraph of 𝐺 .
𝑞 is a non-induced subgraph of 𝐺 .
One key detail regarding the subgraph definition is whether the subgraph is induced or non-induced.
An induced subgraph q [ S ] consists of all the nodes S ⊆ V q and requies that for every edge ( u, u ′ )
∈
E q , if both u and u ′ are in S , then the edge ( u, u ′ ) must be included in the edges of q [ S ] as well.
Intuitively, an induced subgraph does not allow any edges in the original graph to be dropped, as long as both endpoints of the edge are included by the subgraph.
In contrast, a non-induced subgraph q [ S ] consists of all the nodes S ⊆ V q but allows edges in E q to be dropped.
In this paper, we adopt the definition of non-induced subgraph, which is consistent with Han et al.
B. C HOICE OF F ILTERING , Q UERY N ODE O RDERING , AND L OCAL C ANDIDATE C OMPUTATION
Motivated by prior work benchmarking solver baselines (Sun & Luo, 2020), we adopt DP- ISO as the filtering method, G RAPH QL as the query node ordering method, and G RAPH QL as the local candidate computation method in NS UB S and NM ATCH .
As shown by the experimental results in the main paper, this design choice plays a much smaller role in Subgraph Matching than smart target graph node ordering, highlighting the need for NS UB S. Furthermore, we find that optimal filtering, query node ordering, and local candidate computation settings are highly dataset-dependent and hard to determine beforehand; however, because NS UB S’s design is orthogonal to such choices, it could easily be adapted to different filtering and query node ordering algorithms.
We leave such study to future work.
The filtering method produces a global candidate set, C : V q → V t , to drastically prune the search space of possible matchings.
A simple method to compute C is to only allow mappings from u t to v t if v t has degree higher than or equal to the degree of u t .
Different filtering algorithms use different such rules (Sun & Luo, 2020).
The query node ordering gives a search plan on which u nodes to select first.
A simple method is picking the u nodes with the least candidate target nodes given by C .
Different node ordering algorithms use different such rules (Sun & Luo, 2020).
During the search process, the local candidate set guarantees all subgraph mappings found throughout the search process are isomorphic.
Specifically, it ensures u t is matchable to v t , i.e. v t ∈
A u t only if (1) all edges between u t and the currently matched query subgraph (with node set S ) exist between v t and the currently matched target subgraph: ( u t , u ′ ) ∈
E q , u ′ ∈ S =
⇒ ( v t , M ( u ′ ))
∈
E G and (2) the matching, ( u t , v t ) exists in the candidate set: v t ∈ C ( u t ) .
There are many different implementations and optimizations to ensure these conditions hold.
For instance, a query tree data structure (Han et al., 2019) can be stored, allowing O (1) lookup for ( u t , u ′
) ∈
E q connections given a particular query node ordering.
Different local candidate computation algorithms use different such optimizations (Sun & Luo, 2020).
Even though the subgraph isomorphism constraint is ensured through the local candidate set, Subgraph Matching is by no means an easy task due to the large amount of nodes in A u t .
Among different techniques to further improve the accuracy of Subgraph Matching approaches, learning a state-dependent policy to select nodes from q is one direction worth mentioning.
We currently only learn to select nodes in A u t ⊆
V G partly because there is usually a small amount of nodes in q , e.g. 32 nodes or 128 nodes, while the number of nodes in A u t is much larger.
As mentioned in the main text, RL-QVO (Wang et al., 2022) learns a state-independent node ordering policy, ϕ , via RL that is executed before search.
We call such ϕ query node ordering.
We argue it is a promising future direction to explore learning to select both nodes in q and nodes in G at each search iteration.
As shown effective by previous works, we adapt a promise-based search strategy (Bai et al., 2021), which backtracks to any earlier search state, instead of the immediate parent, whenever a terminal state is reached.
We choose which earlier search state to backtrack to by computing a 2:1 weighted average of the search depth normalized by the query graph size and the percentage of explored actions, allowing search to quickly exit local minima.
We include this adaptation on all learning methods.
We also tried the promise-based search on the solver baselines, but found the performance difference is minimal, typically around 2%.
This is because solver baselines do not assign any ordering to the target graph nodes, thus there is no clear incentive to backtracking early.
C C OMPARISON WITH M AXIMUM C OMMON S UBGRAPH (MCS) D ETECTION
Subgraph Matching and MCS detection are highly related tasks, and one can convert Subgraph
Matching to MCS detection by feeding the input ( q, G ) pair to an MCS solver, and check if the MCS between q and G is identical to q .
However, we note the following differences at the task level:
Subgraph Matching requires all the nodes and edges in q to be matched with G , whereas MCS detection does not require one of two input graphs to be contained in another.
Subgraph Matching by definition requires q to be smaller or equal to G , since otherwise the solver can immediately return “no solution”.
In practice, the query graph is usually given by the user as input, and usually contains less than 100 nodes (Sun & Luo, 2020).
The first difference has several consequences.
First, although one can solve Subgraph Matching via an MCS solver, the other way does not hold, i.e. one cannot use a Subgraph Matching solver for MCS detection, since Subgraph Matching has the stronger constraint of matching the entire q .
Second, the stronger constraint of Subgraph Matching allows existing search algorithms to design pruning techniques as mentioned in the main text.
The second difference implies that the learning models designed for Subgraph Matching may not work well for MCS detection and vice versa.
For example, NS UB S has a novel encoder layer with a matching module that has time complexity O (cid:0) | V q
|| ¯
A u t | (cid:1) .
However, if q becomes prohibitively large, e.g. as large as G containing millions of nodes, then the matching step would become a bottleneck and make the overall approach too slow to be useful in practice.
Therefore, NS UB S cannot be used for
MCS detection not only because fundamentally the search algorithm leverages the stronger constraint if Subgraph Matching, but also because the learning model would be inefficient and thus useless in practice.
By the same reasoning, NS UB S is likely to be ineffective for graph isomorphism checking when both input graphs are of the same size and very large.
This suggests the difficulty of designing a general neural network architecture that works efficiently and effectively for a series of related but different combinatorial optimization tasks.
In theory, many such tasks are equivalent and can be converted to each other, but in practice, specialized models should be designed to render a truly useful learning-based approach.
A similar argument can be made for GLS EARCH (Bai et al., 2021) designed for MCS detection.
GLS EARCH treats both input graphs symmetrically and does not leverage the fact that all the nodes and edges in q must be matched in G .
The learning component GLS EARCH assumes both input graphs can be very large, and therefore instead of outputting a policy P θ ( a t
| s t ) for every action a t at s t , GLS EARCH performs the execution of each action to get its next state s t +1 , and compute the value associated with s t +1 for the Q ( s t , a t ) .
This is named as “factoring out action” in Bai et al.
(2021), and requires sequentially going through all the actions to obtain the next states, for which GLS EARCH adopts a heuristic to reduce the amount of actions.
To adapt GLS EARCH for
Subgraph Matching, one has to use a heuristic to reduce the local candidate space, i.e. the action space, in order to be efficient enough to compare against existing solvers.
In contrast, NS UB S efficiently computes one embedding per node for both q and G using the Q C -S GMNN encoder layer, and computes P θ ( a t | s t ) in the decoder by batching the node embeddings that are in the action space, i.e. P
[Equation]
s t ) (cid:1) can be turned into a batch operation for all the node embeddings involved in the action space of s t .
The v θ ( s t ) is only needed during the training stage to enhance P θ ( a t | s t ) , and thus does not need to be predicted during inference.
In short, NS UB S cannot be used for large-input MCS detection due to the matching module performing matching between nodes in q and G , while GLS EARCH may be adapted for Subgraph Matching, it is likely to be ineffective due to the lack of policy network to efficiently compute a score for each pair of nodes leveraging the constraint of Subgraph Matching.
D A BLATION S TUDIES AND A DDITIONAL R ESULTS D. A BLATION S TUDIES
We perform a series of ablation studies whose results are shown in Table 3.
We find our key novelties indeed greatly contribute to NS UB S’s superior performance on Subgraph Matching, particularly the encoder-decoder design.
Table 3 shows the ablation study results.
We first perform the random sampling of negative node-node pairs ( N ( s t ) in Equation 2) from all the node-node pairs in V q and V G instead of from A u t .
We denote the model as “NS UB S-rand-neg”, which performs worse than NS UB S but still outperforms baselines.
This suggests that the negative sampling should be performed using “harder” examples sampled from the local candidate space instead of all the possible node-node pairs.
Such harder negative examples train the model to better identify the promising actions over the unpromising ones at each state.
We replace the look-ahead loss with a simpler version, by only looking at the current state’s positive node-node pairs without considering future states.
NS UB S-no-look-ahead performs worse than NS UB S, indicating the usefulness of the look-ahead loss.
We remove the max margin loss, and as a result, NS UB S-no-mm performs much worse, suggesting the necessity for training the encoder to produce good node embeddings.
Since the encoder training is shown to be important, we then perform a series of ablation study experiments on the encoder.
NS UB S-2-encoder-layers uses 2 encoder layers instead of 8.
NS UB S- D = 4 decreases the embedding dimension from 8 to 4.
NS UB S replaces the G RAPH SAGE model with G IN .
These 3 models perform worse than NS UB S, among which NS UB S- D = 4 performs the worst, indicating that a dimension that is too small cannot capture enough information for the HPRD dataset. [Table]
NS UB S-no-Q-matching removes the concatenation of h ( k +1) q, intra in the computation of h ( k +1) v,q → G in Equation 4.
The worse performance shows the contribution of making the attention from q to G conditioned on the whole-graph representation of q . 6.
NS UB S-no-LDP-encode removes the Local Degree Profile encoding mentioned in Section A.4.
The worse performance shows the importance of encoding the nodes initially with degree information. In addition
[Table]
we perform the ablation study by replacing our Q C -S GMNN encoder with the Graph
Matching Neural Network
GMN) ( Li et al., encoder
GMN introduces the idea of
inter
graph
message passing, but our novelties make it feasible, in terms of efficiency and effectiveness, for
Subgraph Matching.
We summarize three key differences between GMN and Q C -S GMNN :
• GMN produces a soft node-node matching matrix between two graphs instead of hard node selections indicating which nodes should be matched between q and G .
We therefore only utilize GMN’s encoder layer and everything else being the same as our model, including the decoder, the training scheme, the search framework, etc.
In other words, we adapt GMN for Subgraph Matching denoted as GMN-encoder in Table 3.
• To improve GMN’s efficiency, Q C -S GMNN (1) prunes the intergraph interaction space using the local candidate set and (2) decouples the intra- and inter- message passing for caching.
• To improve GMN’s effectiveness, Q C -S GMNN (1) prunes noisy inter-graph interactions with the local candidate set and (2) proposes carefully designed graph-to-node propagation.
The worse performance of GMN indicates the necessity of the proposed Q C -S GMNN designed for
Subgraph Matching.
Similar to GMN, we adapt GLS EARCH ’s encoder which is designed for MCS to our task of Subgraph
Matching, denoted as GLS EARCH -encoder, which performs worse as detailed in Section C.
[Figure]
D. P ERFORMANCE ACROSS I TERATION
We show the number of solved pairs across search iterations in Figure 4, similar to Figure 2 except for the x-axis which is replaced with search iterations.
It is noteworthy that all the methods are implemented under the same search framework, and therefore the search iteration counting and measurement are consistent across the methods.
D. P ERFORMANCE W . R . T . Q UERY S IZES
We show the performance of each method under different query graph sizes for BA and HPRD.
As shown in Figure 4 and 5, the difficulty of solving Subgraph Matching increases as the query graph sizes increase.
When the query graph only contains 8 nodes, all the methods can solve all the graph pairs under the 5 minutes time budget.
However.
as | V q | increases to 128 nodes, all the methods fail to solve any graph pair, suggesting the room for improvement.
In the main text, we report the results for | V q | = 64 , which is of moderate difficulty.
Under other graph sizes, the proposed NS UB S performs either the best or very close to the best method highlighted in bold.
E R ESULT V ISUALIZATION
We show five instances of solved graph pairs by NS UB S in Figures 5, 6, 7, 8, 9, 10, 11 and 12.
We first plot (1) the query graph on its own, then plot (2) the query graph matched to the target graph, and finally plot (3) the target graph. In other words, the first and second plots correspond to the same [Table]
[Table] [Table] query graph but their node positions/layouts are different due to different layouts.
In the second plot we fix the positions of nodes in q to match the positions of their matched nodes in G , i.e. the nodes in the second and the third plots have the same relative node positions for visualizing the node-node mapping.
The colors of nodes are for the purpose of visualizing the mapping.
For clarity, we only show a subgraph of G instead of the entire G as it contains too many nodes and edges to show.
Specifically, we include the matched q in G and grow the matched subgraph by including the first-order neighbors of the matched nodes.