A Framework For Differentiable Discovery of Graph Algorithms
Abstract
Recently there is a surge of interests in using graph neural networks (GNNs) to learn algorithms.
However, these works focus more on imitating existing algorithms, and are limited in two important aspects: the search space for algorithms is too small and the learned GNN models are not interpretable.
To address these issues, we propose a novel framework which enlarge the search space using cheap global information from tree decomposition of the graphs, and can explain the structures of the graph leading to the decision of learned algorithms.
We apply our framework to three NP-complete problems on graphs and show that the framework is able to discover effective and explainable algorithms.
Introduction
Many graph problems such as minimum vertex cover (MVC), minimum dominant set (MDS) and maximum cut (Max-Cut) are NP-hard.
The classical algorithm design paradigm often requires signiﬁcant efforts from domain experts to understand and exploit problem structures, in order to come up with effective procedures.
Thus there is a surge of interests in recent years to use learning and differentiable search to discover graph algorithms (see Appendix B for more related works).
In this context, GNNs have been widely used for representing and learning graph algorithms [1, 2].
However, directly using a GNN model to deﬁne the algorithm search space may not be enough for discovering an algorithm better than existing greedy ones [3, 4] as it only ﬁnds local algorithms that miss out the global information, which foundamentally restricts their expressiveness power.
Another important aspect which have largely been ignored in previous work is explaining the learned algorithm encoded in GNN.
Many previous works focus on the ability of GNNs to imitate existing graph algorithms, without showing new algorithms are being learned.
Therefore, there is an urgent need to develop explainable graph models to understand the learned algorithm.
In this paper, we propose a new framework for differentiable graph algorithm discovery (DAD), focusing on two important aspects of the discovery process: designing a larger search space, and an effective explainer model.
More speciﬁcally, we design a search space for graph algorithms by augmenting GNNs with cheap global graph features .
Our proposed global features are specially designed for learning graph algorithms.
It reveals to be a simple yet effective way of enhancing the capacity of GNNs.
After the GNN is sufﬁciently trained, we employ a novel graph explainer model to ﬁgure out the structural property of the graph leading to the algorithm decision.
The graph explainer model allows us to transform the algorithm represented in continuous embedding space back to the interpretable discrete space, so that it can assist human experts in understanding the discovery.
We show that our DAD framework is able to discover graph algorithms that achieve better approximation ratios.
Besides, we apply our explainer model to the learned algorithms and demonstrate some interesting and explainable patterns.
Except for methodology, we also contribute in generating
[Figure]
a new dataset.
We run Gurobi for around 12,000,000 core hours to generate a reasonably large set of (graph problem, solution) pairs, with varying graph sizes.
It could be a very useful benchmark dataset for graph algorithm learning, which will help with future researches in this area.
Differeniable Graph Algorithm Discovery (DAD) Framework
We focus on three NP-hard problems in this paper: MVC, Max-Cut, and MDS.
Let G =
( V, E, w ) be a weighted graph, where V denotes the set of nodes, E the set of edges, and w : E (cid:55)→ R the edge weight function.
DAD innovates on three important aspects of the graph algorithm discovery process.
Search space design.
we make use of cheap global information which can be obtained in subquadratic time in the number of nodes and edges of the graph.
In particular, we will ﬁnd spanning trees of the original graph, and use the solutions on these trees as augmented node/edge features.
Learning method.
We can use either supervised or unsupervised approaches to train the GNNs.
Explainer model.
We design a novel graph explainer model that uses subgraph pattern selection to ﬁnd the most inﬂuential subgraph patterns in an information theoretic sense.
This is trained by differentiating through a blackbox combinatorial solver.
2.1 Cheap Solutions As Global Features
Inspired by Kelner et al.
[5], which speeds up the linear system solvers by 1) solving problem on the low-stretch spanning tree T ⊆ G ; 2) reﬁne the initial solution on the original graph G , we generalize the idea to solve a broader class of graph problems.
In many graph problems, global optimal solutions can be found efﬁciently by algorithms such as dynamic programming if the graph is a tree.
Therefore, we propose to use (i) solutions on spanning trees T and (ii) approximate solutions of greedy algorithms on G as cheap global features to augment the original graphs.
(i) Given a graph G , we ﬁrst ﬁnd its spanning tree T ⊆ G .
There are multiple ways of constructing the trees, and we can obtain n spanning trees T (1) , · · · , T ( n ) for each graph, using the same set of n algorithms.
On each tree T ( k ) , we can apply dynamic programming (DP) based algorithms to quickly ﬁnd an optimal solution on the tree, denoted by a binary vector y T ( k ) ∈ { 0 , 1 } | V | .
The tree solutions, together with the trees themselves, can be used as global features for the graph G .
[Equation]
(ii) We can also operate on the original graph G to quickly obtain an approximate solution by using some greedy algorithms.
With a set of m greedy algorithms denoted by Gd (1) , · · · , Gd ( m ) , we can obtain a set of approximate solutions.
[Equation]
The tree solutions and greedy solutions will be concatenated and used as node features.
Besides, each spanning tree can be represented by a binary matrix T ( k ) ∈ { 0 , 1 } | V |×| V | , where the ( i, j ) -th entry indicates whether the edge ( i, j ) is in the tree.
These spanning trees will also be concatenated and used as edge features.
Then the overall features can be denoted by
[Equation] , · · · , y Gd ( m ) ] ∈ { 0 , 1 } | V |× ( n + m ) , (3) edge features: Z :=
[ T (1); · · · ; T ( n )]
∈ { 0 , 1 } | V |×| V |× n .
In the rest of this paper, we denote X i as the i -th row vector of X which corresponds to the features of node i , and Z ij as the vector Z [ i, j, :] which corresponds to the features of the edge ( i, j ) .
2.2 Learning Distributed Local Graph Algorithm
A GNN computes the node embeddings by iteratively aggregating the messages from neighbours:
[Equation]
where h ( t ) i is the d -dimentional feature embedding for node i ∈ V at t -th layer, θ ∈ Θ are the parameters in the GNN, F θ is a nonlinear function, and N ( i ) denotes the neighbours of node i .
To learn the parameters θ in the GNN, we consider both the supervised and unsupervised setting:
Supervised learning with ILP solvers.
In the supervised setting, for each graph G , a solution y ∗ is given by running an expensive solver.
We use hindsight loss [6, 2] to alleviate the mode averaging:
Hindsight loss: min k ∈{ 1 , ··· ,K } (cid:96) ( y ∗ i , p i,k ) where p i,k =
OutputLayer k ( h ( T ) i ) , (6)
K could be the number of modes, and (cid:96) is the binary cross entropy loss.
Unsupervised learning with continuous relaxation.
The design of the unsupervised learning mainly follows [7] and more details and principles can be found there.
[Equation]
where Y ∼ Bernoulli ( p ) , (7)
Note that it is a relaxed version of the loss proposed by Karalias and Loukas [7].
Here we treat the l constraints seperately for efﬁcient computations.
See Appendix F for more details.
2.3 Explain The Learned GNN
We simply denoted the learned GNN as F θ .
To understand what algorithm is discovered in F θ , we propose a novel method to explain its predictions { p i }
i ∈ V .
We want to ﬁnd that, for each node i , which subset of nodes V iS ⊆ V and edges E iS ⊆
E are most inﬂuential to the prediction p i .
Besides, the global features X
and Z are induced by the solutions of n spanning trees and m greedy algorithms, which we denote as S :
= { T (1) , · · · , T ( n ) , Gd (1) , · · · , Gd ( m ) } .
We are also interested in ﬁnding which trees or algorithms provide more useful features for the prediction.
Since we focus on node-level predictions, our explainer is deﬁned as a mapping that ﬁnds nodedependent subsets
[Equation]
where V iS and E iS are selected subsets of k V nodes and k E edges respectively, and S iS ⊆
S is a subset of k S trees/algorithms.
More precisely, we parameterize E as a second GNN along with a top- K operation, where the GNN is applied to score the set of structural elements in ( V, E, S ) , and the top- K operation selects the ( k V , k E , k S ) highest scoring elements.
We here provide our optimization technique below.
See Appendix A for more details on the parameterization.
Variational lower bound of mutual information.
To learn the explainer E φ , we employ the learning to explain (L2X) framework in [8].
In L2X, E φ is learned by maximizing the mutual information between the predicted label Y i and the selected subsets ( V i S , E i S , S i S ) .
However, due to intractability, a variational distribution parameterized by a neural network Q ψ will be learned jointly with the explainer E φ to maximize the variational lower bound of the mutual information
[Equation]
where the expectation is taken over the predictive probability p i given by the learned GNN, over all node i in graph G and all graph G in the training set G train .
Differentiable top- K .
The additional technical challenges for optimizing the variational objective in
Eq.
9 is that the top- K operation in the parameterized explainer (Eq. 12) is not differentiable.
More speciﬁcally, a top- K operation over the scores c 1 , · · · , c M for some M is equivalent to solving the following integer linear programming (ILP) problem:
[Equation]
It is easy to see that the optimal solution x ∗ j = 1 only if c j is among the top- K scores.
Given this equivalence, we can employ the blackbox differentiation techniques introduced by Vlastelica et al. [9] to compute the gradient of the ILP solver, and optimize the parameters φ in the explainer.
Our method is closely related but different from GNNExplainer [10].
See Appendix C for details.
Experiment
Below we present both numerical and explanation results.
Please refer to Appendix D, H, J for details on experiment setup and complete set of experimental results.
3.1 Quantitative results
[Figure]
x i
[Figure]
a t i o n r a t
i
[Figure]
Synthetic graphs
We ﬁrst conduct experiments on MVC Barabasi Albert (BA) graphs.
We can see in Figure 2(a) DAD leverages but goes beyond the cheap algorithms, with both supervised and unsupervised (DAD-U) learning strategies.
The gain is signiﬁcant regarding both the average (dark color) and maximum (light color) test ratio.
Figure 2(b) compares against other GNNs with global information, where our design consistently outperforms alternatives.
We also test the extrapolation ability of DAD, where we train the models on graphs up to 300 nodes [Figure] and evaluate them up tonodes.
Figure 2(c) shows consistently better results than the best classical baseline algorithm.
[Table] [Table]
Real-world graphs We run MVC and MDS tasks on the social networks, and run MAXCUT on the physics( Optsicom ) graphs (see Appendix I).
Table 1 and Table 2 show that the relative error of DAD can be several magnitudes smaller than the second best classical algorithms in some cases.
3.2 Explaining learned algorithms
[Figure]
In this section, we use our proposed explainer to explain the learned algorithm on BA graphs.
Explanation with edge selection: Here we limit the number of nodes to be 5, and edges to bewhen explaining each target node of a graph.
We found in Figure 3(a) that some nodes depict the greedy behavior, where the budget for edge explanations is mostly allocated to adjacent edges.
Explanation with node selection: We try to understand the correlation between selected explanation nodes and the node predictive probabilities in ﬁgure 3(b).
We can see the existence of anchor nodes which are commonly selected for explanation (red colors).
The anchors tend to distribute evenly among both high probability (with dark blue boundary) and low probability nodes.
Such diversity driven anchoring behavior is quite similar to landmarks in kernel methods.
Explanation with feature selection: We further look at the contribution of different cheap global features to the GNN prediction for Max-Cut problem in Figure 3(c).
We learn two principles in instantiating our framework: 1) better algorithm solution generally introduces better global information; 2) having diverse algorithmic solutions is better than multiple similar ones.
Appendix A Parameterization of the explainer model
Parameterization of E .
It is notable the prediction p
i is computed by F θ based on the T -hop subgraph of the node i and is irrelavent to nodes of distrance larger than T .
Therefore, when working on node i , the explainer only needs to select the inﬂuential nodes/edges from its T -hop subgraph, denoted by G ( i, T ) :
= ( V ( i, T ) , E ( i, T ) , w ) .
Therefore, we deﬁne explainer GNN as
Explainer GNN: F E φ : ( V ( i, T ) , [Equation] T
[Equation] , X [Equation] T
[Equation]
where X ( i, T ) : =
[ X j ] j ∈ V ( i,T ) and Z
( i, T ) :=
[ Z jk ] ( j,k ) ∈ E ( i,T ) are features induced by the sub- graph.
Then multi-layer perceptrons (MLP) are applied to deﬁne the scoring functions: (I) Node scores: c j = MLP Vφ ( h E j ) for each node j ∈ V ( i, T )
(II) Edge scores: c j,k = MLP Eφ ([ h E j , h E k , E j,k ]) for each edge (
j, k ) ∈ E ( i, T )
(III) Feature scores: c = MLP S φ (cid:0) Pooling (cid:0) { h E j } j ∈ V ( i,T ) (cid:1)(cid:1) , where the output c is a ( n + m ) - dimensional vector that gives the score for
features
induced by
the n spanning trees and the m greedy algorithms. With the scores, the subsets ( V iS , E iS , S iS ) can be selected as choosing the elements with scores in top- K , for K = k V , k E , and k S , respectively.
In summary, the explainer model can be written as the composition of three operations
Parameterized Explainer: E φ = top-
[Equation]
Parameterization of Q .
Again we will parametrize the variational distribution Q ψ by a third GNN
F Qψ : ( V iS , E iS , X iS , Z iS ) (cid:55)→ { h Qj } j ∈ V ( i,T ) followed by pooling and MLP:
[Equation] where the features ( X iS , Z iS )
=
H ( V iS , E iS , S iS , X, Z ) are induced by the selected subsets via a differentiable mapping H .
B Related Work
Expressiveness of GNNs for representing algorithms.
GNNs have been used to learn graph algorithms.
Some recent works have discussed the representation power of GNNs for representing graph algorithms.
Xu et al.
[11] showed that GNNs are at most as powerful as the Weisfeiler-Lehman (WL) test in distinguishing graph structures.
Maron et al.
[12, 13] proposed k -GNN which can represent the results of k -WL test.
Barceló et al.
[14] showed that GNNs are too weak to represent logical Boolean classiﬁers - FOC 2 , and proposed to add a global read-out functionto break this limitation.
Focusing on combinatorial problems including MDS and MVC, Sato et al.
[4] derived the approximation ratios of algorithms that GNNs can learn, and theorectically showed that adding the information of port numbering and weak-coloring can improve those approximation ratios.
Learning based graph algorithms.
Empirically, several works have demonstrated the ability of
GNNs for imitating existing graph algorithms.
For instance, GNN is used to learn the convergent states of graph algorithms [1], imitate DP algorithms [15], and imitate individual steps and intermediate outputs of classical graph algorithms [16].
To learn a new and more effective graph algorithm, Khalil et al.
[17] combined reinforcement learning with GNNs to learn greedy policies that can solve graph problems such as MVC and Max-cut.
Karalias and Loukas [7] proposed an unsupervised framework for learning graph algorithms and demonstrated the results on maximum clique and local partitioning problems.
C Compare with GNNExplainer
Discussion.
Our explainer model is very different from GNNExplainer [10], which may be of independent interests in term of explainer model for GNNs.
For instance, GNNExplainer optimizes the selection mask (i.e., the explainer) for an individual graph, while we parameterize the explainer as another GNN which can be applied to explain the predictions on a class of different graphs.
Besides, the variational Q in GNNExplainer is deﬁned to be the origianl GNN F θ which is ﬁxed, while we optimize Q over a parameteric family, so that our method is more principled and optimal.
Furthermore, we formulate the top- K selection as a solution to an ILP and apply a blackbox differentiation techique to optimze the explainer model, which has not been attempted in the space of explainer models before.
More discussions can be found in Appendix E.
D Experiment setup
We leave the details of greedy algorithms and dynamic programming on trees in Appendix G.
We ﬁrst compare against some of the cheap algorithms that are also served as features.
As we use the continuous relaxation in Eq.
7, we also compare with the linear/semi-deﬁnite programming (LP/SDP) with randomized rounding for these problems:
• MVC: LogN-Approx (node-degree greedy), 2Approx-Greedy (edge selection with degree greedy), 2Approx (edge selection) and LP relaxation are included.
• MDS: Greedy (sequential coverage based greedy selection) and LP relaxation are included. • Max-CUT: 2Approx-Greedy (greedy local adjustment), SDP and MaxSpanning (solution directly obtained on max spanning tree, as any node assignment is a valid cut) are included.
We here include several recent works that extends GNNs with different forms of global information:
• Onehot [7, 18]: adds one-hot encoding to a random node. • RandFeat [19]: uses random node features to break the tie.
• CPNGNNs [4]: leverages port numbering in GNN’s message passing, together with weak 2-coloring node features.
As CPNGNNs only works for graphs with bounded degree, we use the position encoding [20] for port number representation instead.
Synthetic data prepration We use two random graph models, namely
Erdos
Renyi (ER) with edge probability 0 . 15 , and Barabasi Albert (BA) with edge attachment 4 to generate random graphs for training and test.
We vary the graph sizes in { 16-20 , 32-40 , 64-75 , 128-150 , 256-300 , 512-600 , 1024-1100 } .
In each { problem , graph type , graph size } conﬁguration, we generation { 10 k, 1 k, 1 k } graph instances for training, validation and test, respectively.
We run Gurobi on each instance to get the solution for evaluation or supervised training.
See Appendix H for more details on setup and Gurobi .
[Figure]
[Figure]
E Other related works
Explainer models.
Existing work on explainer models approach the problems from three directions.
The ﬁrst line of work use gradients of the outputs with respect to inputs to identify the salient features in the inputs [21, 22]; The second approximates the model with simple interpretable models, such as locally additive models [23–26]; the third deﬁnes input pattern selection operators, such that the outputs of the model based on the selected input patterns has large mutual informaton with the original model outputs [8, 10].
The difference of our explainer model compared to GNNExplainer [10] is discussed in Sec C.
F Probabilisitc relaxation of constraints
In main paper we mentioned that we are solving the following probabilistic relaxation of the integer programming:
[Equation]
where Y ∼ Bernoulli ( p ) ,
This can be more general for many constrained optimization problems.
For example:
MVC: MVC constraint requires that each edge e
= ( i, j ) has p i + p j ≥ 1 .
In the probabilistic sense, the probability of violating this constraint is (1 − p i ) ∗ (1 − p j ) .
Thus the expected penalty would be:
[Equation]
MDS: MDS constraints are placed on nodes.
The ILP constraint says p i + (cid:80) j ∈N ( i ) p
j ≥ 1 .
Again, we write it in the probability sense, with the expected penalty be:
[Equation]
In our experiment, we use above expected penalty to handle the hard constraints in unsupervised learning setting.
G Details of cheap algorithmic features
The cheap algorithm conﬁgurations are described in Table 3.
For unweighted graphs the spanning for DAD on different problems. [Table] MVC DP on random spanning [Table]
DP on
[Table]
coloring [Table] max [Table]
min
[Table]
low-
[Table]
[Table]
trees are usually not unique, so we can use multiple tree solutions as global features for DAD.
We use
AKPW [27] for computing the low-stretch spanning tree for Max-Cut problems.
G.1 Obtaining tree solutions
Note that although these combinatorial optimization on trees are easier than NP-hard, but they are still nontrivial.
Here we cover the recursion of dynamic programming for these problems:
MVC:
Firstly we pick a random node as root, and traverse the tree in DFS order.
Suppose we use f [ n, 0] to denote the cover size of the subtree rooted at node n , when the node n is not chosen, and f [ n, 1] to denote the cover size when node n is chosen, then we have:
[Equation]
And the ﬁnal cover size is obtained by min { f [ root , 0] , f [ root , 1] } .
MDS:
Firstly we pick a random node as root, and traverse the tree in DFS order.
Suppose we use f [ n, 0] to denote the dominant set size of the subtree rooted at node n , when the node n is chosen; use f [ n, 1] to denote the situation when n is not picked, but it has been dominated by other nodes; use f [ n, 2] to denote that we don’t care about node n ’s situation, but its subtree should satisfy the constraint.
Then we have:
[Equation]
and ﬁnally the dominant set size equals to min { f [ root , 0] , f [ root , 1] } .
Max-Cut: Max-Cut on tree is easy when all the edge weights are non-negative, as every tree is a bipartite graph.
We can perform two-coloring on this tree to obtain the solution.
By ﬂipping the colors afterwards, we can get another equivalent solution.
Although this solution is simple, it still has nontrivial effect on obtaining the global information, as the 2-coloring solution on tree is the weak 2-coloring on the original graph.
It is known that for some problems, such information can help boost the approximation ratio of distributed local algorithms [4].
H Experimental details
We run all the experiments on a cluster with 6149 nodes.
In each node, there are 64 cores.
To obtain the solution for evaluation or supervised training, for each graph per task, we run Gurobi on one node with the time limit as 1 hour.
As we have three tasks, two graph models, seven graph sizes, and 12 k graph instances in each category, the computational budget is 32 million core hours.
In reality, we used around 12 million core hours because only the larger graph tasks can run up to 1 hour.
Compared to that of the exact solution, the core hour consumption of the relaxed LP is neglectable.
However, the SDP for Max-CUT is computationally intensive.
We used cvxpy to realize it.
For the larger graphs, it can take up to 40 mins to resolve one graph with 64 cores.
It takes around 0.2 million core hours to obtain the SDP solutions.
We tuned the hyperparameters of GNN models for each graph category, such as the number of layers and the number of spanning trees, using grid search.
We run each job up to 24 hours on a 64-core node.
It takes around 5 million core hours to run the jobs on the synthetic datasets and 0.3 million core hours for the real datasets.
In total, it takes us around 17.5 million core hours to run all the jobs.
I More real world data information
We collect a set of social network dataset Collab, Twitter, Github and Facebook from Morris et al. [28], following Karalias and Loukas [7].
Each dataset comes with a set of graphs, and we split them into training/validation/test with ratio 6:2:2.
Additionally, we collect Memetracker graph from
SNAP [29] and Optsicom used in Khalil et al.
As these only have a few graphs, we use the same strategy from Khalil et al.
[17] to generate graphs.
Speciﬁcally, for Memetracker, we use
[Table]
[Table]
widely-adopted Independent Cascade model and sample a diffusion cascade from the full graph with constant set to 7, and consider the largest connected component in the graph as a single graph instance
; for Optsicom we keep the graph structures, but perturb the edges weights using Bernoulli distribution (denoted as Optsicom-B) or Gaussian distribution with zero mean and 0.1 standard deviation (denoted as Optsicom-G).
See Table 4 for the ﬁnal statistics about the datasets.
For the completeness [Figure] we additionally include MVC and MDS results on Collab and Facebook datasets in Table 5.
These datasets are used in Karalias and Loukas [7] but not very suitable for evaluating MVC or MDS tasks, as it is easy to get exact solution with simple algorithms on thest two datasets.
J More experimental results J.1 More in-distribution generalization results
[Figure]
In main paper we covered the comparison between DAD and other classical algorithms, as well as other types of global GNNs on Barabasi Albert graphs.
Here we present the results on Erdos Renyi graphs, as well as the results with unsupervised learning in ﬁgure 6 and ﬁgure 7.
We can see the proposed DAD consistently beats all other alternatives in all these settings.
J.2 More extrapolation results
Here we show the extrapolation results on Erdos Renyi and Barabasi Albert graphs, where DAD is trained with supervion on graphs with up to 300 nodes.
We can see from ﬁgure 8, DAD still extrapolates well to large graphs.
The unsupervised learning extrapolates in a similar way, as seen in ﬁgure 9.
[Figure] [Figure]
MDS-ER Supervised
Maxcut-ER Supervised
[Figure]
i
[Figure]
t i o w .
r .
t G u r o b i
[Figure]
One interesting ﬁnding is that, it achieves approximation ratio that is less than 1 on MDS large graphs.
This indicates that the Gurobi is not capable of generating high quality solution on large graphs.
Also for ER graphs, it is harder to extraplate to smaller graphs.
As we ﬁx the edge probability for different sizes of the graphs, the node degree distribution would shift when graph size changes.
This may prevent GNNs from extrapolating well.
J.3 More ablation results
[Table] [Table]
Here we include more ablation results
[Table]
on both real world datasets (see Table 7 and Table 6) and synthetic datasets (see ﬁgure 10).
We can see the conclusion is still consistent with our claim in the main paper.
[Figure] [Figure]
t i o n r
[Figure] [Figure]
MVC-ER Supervised
MDS-ER Supervised
MaxCut-ER Supervised
[Figure]
b i
[Figure]
MVC-BA Supervised
MDS-BA Supervised
MaxCut-BA Supervised
[Figure]
MVC-ER Unsupervised
MDS-ER Unsupervised
MaxCut-ER Unsupervised
[Figure]
[Figure] [Figure]
i
[Figure]