G RAPH E DIT N ETWORKS
Anonymous authors
Paper under double-blind review
A BSTRACT
While graph neural networks have made impressive progress in classiﬁcation and regression on graphs, few approaches to date perform time series prediction on graphs and those that do are mostly limited to edge changes.
We suggest that graph edits are a more natural interface for graph-to-graph learning.
In particular, graph edits are general enough to describe any graph-to-graph change, not only edge changes, they are sparse, making them easier to understand for humans and more efﬁcient computationally, and they are local, avoiding the need for pooling layers in graph neural networks.
In this paper, we propose a simple linear layer - the graph edit network - which takes node embeddings as input and generates a sequence of graph edits that transform the input graph to the output graph.
Theoretically, we show that a mapping between the node sets of two graphs is sufﬁcient to construct training data for a graph edit network and that an optimal mapping yields edit scripts that are almost as short as the graph edit distance between the graphs.
We further provide a proof-of-concept empirical evaluation on several graph dynamical systems, which are difﬁcult to learn for baselines from the literature.
I NTRODUCTION
Recent advances in graph representation learning have mostly focused on tasks of classiﬁcation or regression, i.e. tasks with graph-structured input but numeric output (Battaglia et al., 2018; Kipf & Welling, 2016a; Veli ˇ ckovi ´ c et al., 2018).
By contrast, few approaches to date can transform a graph-structured input to a graph-structured output (Hajiramezanali et al., 2019; Paaßen et al., 2018; Zambon et al., 2019).
This lacuna is crucial because time series prediction on graphs requires graph-structured output, in particular the next graph in a time series.
Applications of time series prediction on graphs include epidemiological models (Keeling & Eames, 2005), social (Liben-Nowell & Kleinberg, 2007; Masuda & Holme, 2019), telecommunications (Nanavati et al., 2006), trafﬁc (Cui et al., 2019), citation (Shibata et al., 2012), and ﬁnancial transaction networks (Chan & Olmsted, 2017), as well as student solutions in intelligent tutoring systems (Paaßen et al., 2018).
In each of these settings, predicting the changes in graphs can deepen the understanding of the domain and provide useful knowledge for designing interventions.
Currently, methods for time series prediction on graphs are limited to the dynamics of the node attributes (Yu et al., 2018), or changes in connectivity (Goyal et al., 2020; Hajiramezanali et al., 2019), but do not cover changes in the node set.
Fortunately, there exists a rich research tradition of edit distances (e.g. Levenshtein, 1965; Zhang & Shasha, 1989; Sanfeliu & Fu, 1983) which can describe any change between two graphs.
Further, edits are sparse and have a simple semantic (delete, insert, relabel), which makes them easier to interpret for human observers and makes them computationally more efﬁcient (linear instead of quadratic) compared to a dense representation.
Finally, edits are local, enabling us to make edit decisions at each node instead of coordinating information across the entire graph.
In this work, we connect graph neural networks to edit distances by developing a simple, linear output layer that maps node embeddings to graph edits.
We call our output layer the graph edit network (GEN).
We also develop a general training and inference scheme to transform any graph G t to its successor G t +1 using only local binary edit decisions and a regression for node attributes.
Theoretically, we show that a) a mapping between the nodes of G t and G t +1 is sufﬁcient to construct training data for the GEN, b) this construction yields almost no overhead compared to directly transforming the mapping to graph edits, and c) provided that the mapping between G t and G t +1 is optimal and the GEN can perfectly reproduce the training data, the edit script is almost as short as the graph edit distance (Sanfeliu & Fu, 1983).
In addition to this core theoretical contribution, we provide a proof-of-concept of our model by demonstrating that GENs can learn a variety of dynamical systems on graphs which are more difﬁcult to handle for baseline systems from the literature.
We also show that the sparsity of edits enables
GENs to scale up to realistic graphs with thousands of nodes.
B ACKGROUND
Graph Neural Networks: Graph neural networks (GNNs) compute representations of nodes in a graph by aggregating information of neighboring nodes (Defferrard et al., 2016; Kipf & Welling, 2016a; Micheli, 2009; Scarselli et al., 2009).
In particular, the representation φ l ( v ) ∈ R n l of node v in layer l is computed as follows:
[Equation]
where N ( v ) is some neighborhood of v in the graph and f l merge as well as f l aggr are functions that aggregate the information of their arguments, returning a single vector (Xu et al., 2019).
The representation in the 0 th layer is usually deﬁned as the initial node attributes or a constant vector for all nodes (Kipf & Welling, 2016a).
Recently, many implementations of f l merge , f l aggr , and neighborhood
N have been suggested, such as a weighted sum via the graph Laplacian (Kipf & Welling, 2016a), recurrent neural networks (Hamilton et al., 2017), or attention mechanisms (Veli ˇ ckovi ´
c et al., 2018).
Our approach is agnostic to the choice of graph neural network.
We merely require some vectorial embedding for each node in the input graph.
Graph Generators: Multiple works in recent years have proposed recurrent models to generate graphs (Bacciu et al., 2019; Li et al., 2018; You et al., 2018a;b; Zhang et al., 2019).
Roughly speaking, these recurrent models ﬁrst output a node, and then all connections of this node to previous nodes until a special end-of-sentence token is produced.
While such a scheme does enable time series prediction, it only works for insertions, i.e. starting at an empty graph and inserting nodes and edges over time.
If one wishes to account for general graph changes, one ﬁrst has to encode a graph into a vector and then decode from this vector the graph in the next time step, as is done in molecular design and drug discovery (Jin et al., 2019; Fu et al., 2020).
However, such models have to generate the next graph from scratch and can not exploit the sparsity and interpretability of edits, as we suggest.
Link Prediction:
Link prediction is complementary to graph generation, assuming a constant number of nodes, but changing connectivity between them (Liben-Nowell & Kleinberg, 2007;
Richard et al., 2014; Shibata et al., 2012).
Typically, this is performed by ﬁrst computing node features and then an afﬁnity index between two nodes based on their features.
Edges with low index are then predicted to vanish, while edges with high index are predicted to appear.
For example, Goyal et al.
(2020) combine dense and recurrent blocks are combined to build an autoencoder for link prediction, while Hajiramezanali et al.
(2019) combine a GNN and a RNN to obtain a spatio-temporal variational graph autoencoder.
In GENs, we predict edge changes with a similar scheme, using a graph neural network to obtain the node features and then mapping these node features to the graph changes.
However, in contrast to prior work, we do not predict the next adjacency matrix but only the change in adjacencies, which is a much sparser signal, reducing the time complexity from quadratic to linear.
Additionally, GENs can not only handle edge changes, but also node changes.
We note that our current paper is limited to a Markovian setting, i.e. we do not consider the past for computing node representations.
This limitation could be addressed by combining our output layer with EvolveGCN (Pareja et al., 2020) which uses a recurrent net to predict the weights of a graph neural net, thus being able to handle changes in the node set.
Dynamic Attributes: Recently, graph neural networks have been extended to predict changes to node attributes, while the nodes and edges remain ﬁxed (Cui et al., 2019; Seo et al., 2018), which is particularly useful for trafﬁc networks.
GENs are complementary to these works, in that we consider the more general case of graph topology changes.
Time Series Prediction on Graphs: To our knowledge, only very few works to date have addressed the most general case of time series of graphs, where both nodes and edges are permitted to change.
In particular, Paaßen et al.
(2018) suggest several kernel-based time series prediction methods for graphs.
However, their scheme is limited to predictions in the kernel space and mapping a prediction back to a graph requires solving an inverse kernel problem, relying on approximations
that impact accuracy (Paaßen et al., 2018).
Zambon et al.
(2019) embed the time series into a vector space using a GNN and use a recurrent neural network to predict the next time step.
To obtain the corresponding graph, a multi-layer perceptron is used to compute the adjacency matrix and node features from the predicted embedding.
Besides being computationally expensive, this dense decoder also assumes a ﬁxed order of the nodes.
Graph Edits:
We deﬁne an attributed, directed graph as a triple G =
( V, E, X ) ,
where V = { 1 , . . .
, N } is a ﬁnite set of node indices,
E ⊆
V × V is a set of edges, and X ∈ R N × n is a matrix of node attributes for some n ∈ N .
We deﬁne the nodes as indices for notational simplicity, but we do not assume any speciﬁc order, i.e. we treat isomorphic graphs as the same.
Now, let G be the set of all possible attributed directed graphs.
We deﬁne a graph edit as some function δ : G → G .
In particular, we consider the graph edits of Sanfeliu & Fu (1983), namely node deletions del i , which delete the i th node from a graph, node replacements rep i,x , which set the attribute of node i to x , node insertions ins x , which add a new node with attribute x to a graph, edge deletions edel i,j , which delete the edge ( i, j ) from a graph, and edge insertions eins i,j , which insert the edge ( i, j ) into a graph.
We then deﬁne an edit script ¯ δ as a ﬁnite sequence ¯ δ =
δ 1 , . . .
, δ T of graph edits and we deﬁne the application of ¯ δ as the composition of all edits, i.e. ¯ δ ( G ) :
= δ T ◦ . . .
◦
δ 1 ( G ) .
Finally, we deﬁne the graph edit distance d GED ( G t , G t +1 ) as the length of the shortest script ¯ δ such that ¯ δ ( G t ) =
G t +1 .
It can be shown that the GED is well-deﬁned and a proper metric, i.e. a script connecting any two graphs always exists, the GED between two isomorphic graphs is zero, the GED is symmetric, and it conforms to the triangular inequality (Abu-Aisheh et al., 2015; Sanfeliu & Fu, 1983).
While prior work has already attempted to approximate the graph edit distance with graph neural nets (Bai et al., 2019;
Li et al., 2019)
our work is, to our knowledge, the ﬁrst to produce actual graph edits as network output and to avoid graph pooling layers.
G RAPH E DIT N ETWORKS
Let G 1 , G 2 , . .
, G T be a time series of graphs.
Our goal is to develop a neural network that takes a graph G t as input and outputs graph edits that transform G t to G t
+1 .
For simplicity we make a
Markov assumption, i.e. G t is sufﬁcient to predict G t +1 (future research could address this limitation, e.g. by applying EvolveGCN of Pareja et al., 2020).
Now, let G t =
( V, E, X ) be an attributed graph with N nodes.
Our proposed processing pipeline has three steps.
First, we use some graph neural network (refer to Equation 1) to compute a matrix of node embeddings Φ ∈ R N × n .
Second, we use a linear layer to compute numerical edit scores that express which nodes and edges should be deleted, inserted, and relabeled, respectively.
Third, we translate these scores via Algorithm 1 to an edit script ¯ δ and apply this script to the input graph to obtain the output graph G t +
=
¯ δ ( G t ) .
This pipeline is also illustrated in Figure 1.
In the remainder of this section, we describe the graph edit network layer (Section 3.1), our training scheme (Section 3.2), our inference scheme (Section 3.3), and ﬁnally our theoretical results (Section 3.4).
3. G RAPH E DIT N ETWORK L AYER
Our proposed graph edit network (GEN) is a linear layer to compute edit scores that express which nodes and edges should be deleted, inserted, or relabeled.
The input of our GEN is a matrix Φ ∈ R N × n of node embeddings as returned by a graph neural network (refer to Equation 1).
We then compute node edit scores (cid:126)ν ∈ R N , edge ﬁlter scores (cid:126)e + ∈ R N as well as (cid:126)e − ∈ R N , and new node attributes Y via linear maps from Φ .
After this is done, we consider only those pairs ( i, j ) where e + i > 0 and e − j > 0 and compute an edge edit score (cid:15) i,j via another linear layer that receives (cid:126)φ i , (cid:126)φ j , and the inner product (cid:126)φ Ti · (cid:126)φ j as inputs.
The interpretation of these scores is that ν i should be positive if a new node connected to i is inserted, ν i should be negative if node i is deleted, e + i , e − j , as well as (cid:15) i,j should be positive if edge ( i, j ) is inserted and e + i , e − j , as well as − (cid:15)
i,j should be positive if edge ( i, j ) is deleted.
Note that we only compute the edge edit score (cid:15) i,j for edges ( i, j ) where e + i > 0 and e − j > 0 .
Thus, if edge changes concern only a number of nodes in O ( √ n ) , the GEN layer operates in linear instead of quadratic time.
We can also enforce the linear time by setting all e + i and e − j to zero that are not in the top R for some R that is either constant or in O ( √ n ) .
From scores to edits: Next, we translate these scores into edits.
The formal translation scheme is given in Algorithm 1.
Roughly speaking, we delete any node i where the node edit score
ν i is smaller than − 12 , we insert a new node with attribute (cid:126)y i , connected to i , whenever ν i is larger than + 12 , and we replace the attribute (cid:126)y i with (cid:126)y i otherwise.
For edges, we delete any edge ( i, j ) where (cid:15) i,j < − 12 , where ν i < − 12 , or where ν j < − 12 , and we insert any edge where (cid:15) i,j > + 12 .
The complexity of
Algorithm 1 is as follows.
In line 2, we ﬁrst construct | E ∩ { ( i, j ) | ν
i < − 12 or ν j < − 12 }| edits, which is bounded by | E | , which in turn is in O ( N ) for a sparse graph and O ( N 2 ) for a dense graph.
Lines 3-8 perform |{ ( i, j ) | e + i > 0 , e − j > 0 }| iterations, which can be bounded to some constant Rby the edge ﬁltering trick above.
Lines 9-15 iterate over all nodes several times, which is in O ( N ) .
The space complexity is the same since we add one edit each iteration, which needs to be stored.
The overall time and space complexity is thus O ( N ) for sparse graphs and O ( N 2 ) for dense graphs.
{+Algorithm 
+}
The scheme to translate the outputs of the GEN layer ν i , (cid:126)y i , e + i , e − i , and (cid:15)
i,j to graph edits.
1: function TRANSLATE (graph G = ( V, E, X ) , node edit scores (cid:126)ν ∈ R N , attributes Y ∈ R N × n , edge ﬁlter scores (cid:126)e + ,(cid:126)e − ∈ R N , and edge edit scores E ∈ R N × N ) 2: Initialize script ¯ δ with edel i,j for all ( i, j ) with ν i < − 12 or ν j < − 12 in lexicographic order.
{+3: for i with e + i > 
+}
{+and ν i ≥ − 12 do 4: for j with e − j > 
+}
and ν j ≥ − 12 do 5:
Append edel i,j to ¯
Note the special case of node insertions in this scheme.
As with other edits, we make the decision to insert a new node locally at each node instead of globally for the graph.
This relieves the need to aggregate information across the entire graph.
Further, by connecting a new node directly with an existing one, we ensure that any two new nodes can be distinguished purely based on their graph connectivity, without relying on auxiliary information.
3. T RAINING
The key challenge in training GENs is to identify which scores the network should produce such that the GEN transforms the input graph G t into its desired successor G t +1 .
In other words, we require a teaching signal consisting of ground truth scores (ˆ ν, ˆ Y , ˆ e + , ˆ e − , ˆ E ) , such that the edit script ¯ δ returned by Algorithm 1 yields ¯ δ ( G t ) ∼ =
G t +1 , where ∼ = indicates isomorphism.
Unfortunately, we observe that such a one-step teaching signal is sometimes insufﬁcient.
Consider the two example graphs G t = ( { 1 } , ∅ , (0)) and G t +1 =
( { 1 , 2 , 3 } , { (1 , 2) , (1 , 3) } , (0 , 0 , 0) T ) .
In this case, there exists no one-step teaching signal that transforms G t to G t +1 because we can only insert a single new node at a time.
However, it is possible to set up a two-step teaching signal (ˆ ν 1 , ˆ Y 1 , ˆ e +1 , ˆ e − 1 , ˆ E 1 ) , (ˆ ν 2 , ˆ Y 2 , ˆ e +2 , ˆ e − 2 , ˆ E 2 ) with ˆ ν 1 = (1) and ˆ ν 2 =
(1 , 0) T and all other scores set to zero which does the job.
In particular, by plugging these values into Algorithm 1 we obtain the edits ¯ δ 1 = ins , eins 1 , 2 and ¯ δ 2 = ins , eins 1 , 3 , such that ¯ δ = ¯
δ 1 , ¯ δ 2 does indeed yield ¯ δ ( G t ) ∼ = G t +1 .
In general, Theorem 2 shows that a teaching signal with K + 1 steps sufﬁces to transform any input graph G t into any output graph G t +1 , where K steps only perform insertions and the last step performs all other edits.
Provided that a teaching signal exists, our training procedure should ensure that the actual edit scores ( (cid:126)ν 1 , Y 1 ,(cid:126)e +1 ,(cid:126)e − 1 , E 1 ) , . . .
( (cid:126)ν K +1 , Y K +1 ,(cid:126)e + K +1 ,(cid:126)e − K +1 , E K +1 ) result in the same edits as the teaching signal when being plugged into Algorithm 1.
To do so we treat every edit decision in Algorithm 1 as a binary classiﬁcation and punish different decisions with a classiﬁcation loss, such as the hinge loss (Zhao et al., 2017) or crossentropy (please refer to Appendices B and C for a more detailed discussion of loss functions).
In particular, in the ﬁrst K steps of a teaching signal, we have a classiﬁcation loss for the decision of inserting a node ( ν k,i > + 12 ) or not ( ν k,i ≤ + 12 ), plus a loss for punishing deviations between predicted attributes (cid:126)y k,i and desired attributes ˆ y k,i for all i with ˆ ν k,i > + 12 .
For step K + 1 , the same idea applies. For each node we have a binary classiﬁcation loss for the decision of deleting a node i ( ν K +1 ,i < − 12 ) or not; plus the regression loss between (cid:126)y K +1 ,i and ˆ y K
+1 ,i for non-deleted nodes i ; plus the classiﬁcation loss regarding whether to change the outgoing edges of node
i ( e + K +1 ,i > 0 ) or not; plus the classiﬁcation loss regarding whether to change the incoming edges of node i ( e − K +1 ,i > 0 ) or not; plus the classiﬁcation loss regarding whether to delete an existing edge ( i, j ) ( (cid:15) i,j < − 1 ) or not; plus the classiﬁcation loss regarding whether to insert a non-existing edge ( i, j ) ( (cid:15) i,j > 1 ) or not.
The sum of all these losses forms our training loss for a single graph pair ( G t , G t +1 ) .
Because this loss is differentiable, we can train our neural net end-to-end by performing a gradient descent scheme on this loss, e.g. using Adam (Kingma & Ba, 2015).
Importantly, edge ﬁltering needs to be adjusted to the training data.
In particular, if we impose a limit on the maximum number nodes with e
+ i > 0 or e − i > 0 , this limit should be higher than the maximum number of those nodes in the teaching signals for the training data - otherwise, the training can never achieve zero loss.
If the limit is high enough, however, the training procedure is the same with or without the limit.
The limit only impacts inference.
3. I NFERENCE
Once training is complete, we wish to use our GEN for inference.
In particular, given a previously unseen graph G t , we want to know its successor G t +1 .
Because G t +1 is unknown, we can not construct a teaching signal.
Instead, we plug the current graph G t into our graph neural net to compute node features Φ , then use the GEN to compute scores ( (cid:126)ν, Y ,(cid:126)e + ,(cid:126)e − , E ) , and plug these into Algorithm 1 to retrieve an edit script ¯ δ , which then yields our predicted graph G t +1 =
[-+
-]
¯ δ ( G t ) (also refer to Figure 1).
This is the simple one-step scheme that we will also use in our graph dynamical system experiments.
In case our training data requires multi-step teaching signals, our inference also needs multiple steps.
In particular, we use the following scheme: 1) Color all nodes red.
If no red nodes are left, go to 4.
Otherwise, re-compute the node features (cid:126)φ i , the node edit score ν i , and the attributes (cid:126)y i for all red nodes i .
For all i with ν i > + 12 , insert a new node with attributes (cid:126)y i , draw an edge from i to the new node, and color the new node red.
Color all nodes i with ν i ≤ + 1 2 blue.
Then go to 2.
4) Compute the node features Φ and the edit scores ( (cid:126)ν, Y ,(cid:126)e + ,(cid:126)e − , E ) for all nodes.
Set all ν i > 12 to zero
Then , call Algorithm 1 and apply the resulting script to the graph.
In general, it may be necessary to provide state information (e.g. via a recurrent neural net) to ensure that the network can distinguish whether it still needs to insert nodes or not.
In our experiments, however, it is sufﬁcient to either summarize all edits in a single step or to supply the network with a binary node attribute that ﬂags whether we are still in ’insertion mode’ or not.
3. T HEORY
In this section, we wish to answer two questions.
First, how to construct a teaching signal for a graph edit network?
Second, how short can the output edit script of a GEN get, provided that it still transforms graph G t to graph G t +1 ?
The answer to both questions lies in making the theoretical connection to graph edit distances more explicit.
To do so, we ﬁrst introduce a key concept that will help us, namely that of a graph mapping.
Deﬁnition 1 (Graph Mapping) .
Let G t =
( V = { 1 , . . .
, M } , E, X ) and G t +1 =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) be two non-empty graphs, i.e. M, N > 0 .
Then, we deﬁne a graph mapping ψ between G t and G t +1 as a bijective mapping ψ : { 1 , . . .
M + N } → { 1 , . .
M + N } with the additional restriction that for the set Ins ψ := { j ≤ N | ψ − 1 ( j ) >
M } we obtain ψ − 1 (Ins ψ ) =
{ M + 1 , . . .
, M + | Ins ψ |} .
Graph mappings are useful because they are intimately connected to edit scripts.
In particular, we re-state a result from the literature that any edit script converts to a graph mapping and back and that this conversion never increases the length of the script.
Theorem 1 (Script to mapping) .
Let G t and G t +1 be any two graphs.
There exist two polynomial algorithms to translate any edit script ¯ δ with ¯ δ ( G t ) ∼ = G t +1 to a graph mapping ψ ¯ δ between G t and G t +1 , and to translate any graph mapping ψ between G t and G t +1 into an edit script ¯ δ ψ with ¯ δ ψ ( G t ) ∼ = G t +1 , such that for any ¯ δ with ¯ δ ( G t ) ∼ = G t
+1 we obtain | ¯ δ ψ ¯ δ | ≤ | ¯ δ | .
One proof is contained in Bougleux et al.
We provide a more extensive version in Appendix A.1, which also gives more details on the structure of ψ ¯ δ and ¯ δ ψ ¯ δ .
Now, we show that a graph mapping can also be used to construct a teaching signal for a GEN. Even better, the conversion from mapping to teaching signal to edit script yields almost as short scripts as the direct conversion from mappings to edit scripts. Indeed, we can provide a sharp bound for the overhead in terms of the connected components in the target graph.
Theorem 2 (Mapping to teaching signal) .
Let G t and G t +1 be any two graphs with M and N nodes, respectively.
There exists an O ( M 2 + N 2 ) algorithm
(namely Algorithm 2 in the appendix) that translates any graph mapping ψ with | Ins ψ | < N between G t and G t +1 into a teaching signal (ˆ ν 1 , ˆ Y 1 , ˆ e + 1 , ˆ e − 1 , ˆ E 1 ) , . . .
, (ˆ ν K +1 ,
ˆ Y K +1 ,
ˆ e + K +1 ,
ˆ e − K +1 , ˆ E K +1 )
such that the output of Algorithm 1 is a script ¯ δ , where the following holds: 1) ¯ δ ( G t ) ∼ =
G t +1 ; 2) | ¯ δ | ≤ | ¯ δ ψ | + 2 · ( C − 1) , where C is the number of connected components in G t +
(this bound is sharp); 3) the ﬁrst K steps contain only insertions, with ν k,i =
⇒ ν
k +1 ,i
= . . .
=
ν K +1 ,i = 0 ; 4) the last step contains no insertions; 5)
K ≤ | Ins ψ | (this bound is sharp).
Refer to Appendix A.2 for the proof.
So this result tells us that we obtain a (sparse) teaching signal if we have a good graph mapping ψ . But how to obtain ψ ?
In many cases, we can exploit domain knowledge. For example, if we know that the input graphs are trees, we can use the polynomial tree edit distance algorithm to infer mappings that correspond to short edit scripts (Zhang & Shasha, 1989); or, if node IDs are given (like user IDs in social networks), we can set ψ such that it maintains IDs. In our experiments, we follow such domain-speciﬁc schemes to construct the mappings ψ .
But there is also a general strategy connected to the graph edit distance. While computing the graph edit distance itself is NP-hard (Bougleux et al., 2017), one can achieve a good approximation by constructing a graph mapping via the Hungarian algorithm and then converting this mapping to an edit script via Theorem 1 (Riesen & Bunke, 2009; Abu-Aisheh et al., 2017; Blumenthal et al., 2020). For our purposes, we can simply apply such an approximator and then use the graph mapping to construct our teaching signal. Importantly, if the approximator happens to ﬁnd the optimal mapping and if our graph edit network is powerful enough to achieve a zero loss on one graph tuple ( G t , G t +1 ) , then the output of our graph edit network is close to the graph edit distance.
Corollary 1 (Near-Optimality of Graph Edit Network Architecture) .
Let G t and G t +1 be any two non-empty graphs and let C be the number of connected components in G t +1 .
Further, let ψ be a graph mapping between G t and
G t +1 such that | ¯ δ ψ | = d GED ( G t , G t +1 ) .
Finally, let f be a graph edit network that reproduces the teaching signal, i.e. f ( G t )
=
¯ δ with ¯ δ being the same script as the result of Theorem 2 for ψ .
Then, it holds: | ¯ δ | ≤ d GED ( G t , G t +1 ) + 2 · ( C − 1) .
As mentioned before, this corollary only holds if the mapping is optimal and if the GEN can reproduce the teaching signal.
The latter only holds if the node features Φ are rich enough to make each edit classiﬁcation problem linearly separable (because any edit decision is a linear binary classiﬁcation). Typically, this fails if a graph neural net can not distinguish two nodes that would need to be treated differently.
For example, in an unlabeled ring graph G =
, N } , { (1 , 2) , . .
, ( N, 1) } ) ,
Equation 1 assigns the same node embedding to all nodes and, hence, the GEN returns the same edits.
In such cases, distinguishing information must be integrated via an alternative architecture or via node attributes (which is the strategy we take in the experiments).
For further work on the expressiveness of graph neural nets we point the reader to the work of Xu et al.
To summarize: The proposed way to use a GEN is 1) to gather a training time series of graphs
G 1 , . .
, G T +1 ; 2) to set up reference graph mappings ψ t between G t and G t +1 for all t ∈ { 1 , . . .
, T } , e.g. via graph edit distance approximators; 3) to compute teaching signals via Theorem 2; 4) to initialize an appropriately powerful graph neural net with a ﬁnal GEN layer and train it to reproduce the teaching signals on the training data; 5) to use the trained GEN in inference.
E XPERIMENTS
Our experimental evaluation displays the capability of GENs on a set of graph dynamical systems in comparison to baselines from the literature.
Experiments are reported in three groups and cover graph dynamical systems, tree dynamical systems, and a social network dataset.
All experiments require the possibility of changing edges as well as nodes.
The data is discussed in more detail in Appendix D. We perform all experiments on a consumer grade laptop with core i7 CPU.
All experimental code is available in the supplementary material.
First, we consider the following three graph dynamical systems.
Edit Cycles:
A manually deﬁned data set of cycles in the set of undirected graphs with up to four nodes.
The teaching protocol is hand-crafted to perform optimal edits between each graph and its successor.
To sample a time series we let the cycle run for 4 - 12 time steps at random.
The node features φ 0 ( x ) were set to zero.
Degree Rules: A dynamical system on undirected graphs of arbitrary size with the following rules.
First, delete every node with a degree larger than 3.
Second, connect nodes that share at least one common neighbor.
Third, insert a new node at any node with a degree lower than 3.
We used the node index in one-hot coding as node features φ 0 ( x ) .
For every connected component in the input graph, this dynamical system provably converges to a 4 -clique.
We started with a random undirected adjacency matrix of size 8 × 8 and let the system run until convergence.
Refer to Figure 2 for two example time series.
Game of Life: We simulated one of ﬁve oscillatory shapes in Conway’s game of life (Gardner, 1970), namely blinker, glider, beacon, toad, and clock, for 10 time steps, placed on a random location on a 10 × 10 grid and additionally activated 10% of the grid cells at random.
We represented the grid as a graph with 100 nodes and represented the 8 -neighborhood via the adjacency matrix.
The desired edits were node deletions for all nodes that should switch from alive to dead and node insertions for all nodes that should switch from dead to alive.
As node features we used the alive-state of the node.
Note that a single-step teaching signal is sufﬁcient in all cases.
We compare our graph edit network against variational graph autoencoders (VGAE) and variational graph recurrent nets (VGRNN) which predict the adjacency matrix of the next graph via an outer product of the node features, similar to our edge prediction scheme (Kipf & Welling, 2016b; Hajiramezanali et al., 2019).
Note that neither net can predict node changes directly, but we predict a node deletion whenever all edges of a node are deleted.
To train our GEN model, we apply both the hinge loss (GEN; Appendix B) as well as the
ruleˆ ν 1 =ruleˆ (cid:15) 2 , 3 =ruleˆ ν 1 =ruleˆ (cid:15) 2 , 4 =ruleˆ (cid:15) 3 , 4 =   4   4   4   4  3  3ruleˆ (cid:15) 2 , 4 =ruleˆ (cid:15) 3 , 5 =ruleˆ (cid:15) 1 , 4 =ruleˆ ν 1 = −ruleˆ (cid:15) 1 , 4 =
[Table] crossentropy loss (XE-GEN; Appendix C). For all models, we use two graph neural network layers with 64 neurons each, sum as aggregation function and concatenation as merge function (refer to Equation 1).
We train all networks with an Adam optimizer in pyTorch using a learning rate of 10 −and stopping training after 30,000 time series or if the loss dropped below 10 − 3 .
After training, we evaluated the predictive performance on 10 additional time series.
We repeated each experiment ﬁve times.
The recall and precision for all edit types, all models, and all datasets is shown in Table 1.
Node insertion precision, node deletion recall, and edge deletion recall where consistently at 100% for all models, and edge insertion precision as well as edge deletion precision very close to 100%.
This is the case for both hinge and crossentropy loss.
Unsurprisingly, VGAE and [-363 . 
 ± 17 . 22 s-]VGRNN perform poorly on node edits, for which they are not designed, but also underperform on some edge edit scores; especially VGRNN on edge edit precision.
We note that our data sets are strictly Markovian, such that the added recurrent capability of VGRNNs may not provide much value and that, indeed, the difﬁculty of maintaining the state across node set changes may hurt VGRNN in these cases.
We consider the following two tree dynamical systems, where node labels are represented via one-hot coding.
Boolean Formulae: Random Boolean formula with up to three binary operators (e.g. ( x ∨ ¬ y )
∧ x ∧ y ), which get simpliﬁed with rules like x ∧ ¬ x → ⊥ until the formula could not be simpliﬁed anymore.
Peano addition: Random additions of single-digit integers with at most 3 + operators, which get re-written using Peano’s deﬁnition of addition,[-i.e. m + succ( n ) = succ( m ) + n and m + 
-]
i e. m + succ( n ) = succ( m ) + n and m + 0 = m .
The purpose of these data sets is to test whether our GEN is able to correctly predict node attributes.
We compare against a Gaussian process prediction approach for tree time series prediction suggested by Paaßen et al.
(2018) which uses Gaussian process regression with an RBF kernel on the tree edit distance to predict the next tree in kernel space and then solves a kernel pre-image problem to ﬁnd the actual next tree (Paaßen et al., 2018).
We use the same GEN hyper parameters as for the graph dynamical systems.
As results we observe that the GEN is able to achieve perfect predictive accuracy for both data sets on all ﬁve repeats of the experiment.
By contrast, the Gaussian process prediction scheme yields an
RMSE (as measured by the tree edit distance) of 2 . 39 (std.: 0 . 24 ) on Boolean and 4 . 54 (std.: 0 . 77 ) on Peano, indicating that the datasets are not trivial to predict.
We evaluated the runtime of GENs on a variation of the HEP-Th paper data set of Leskovec et al.
In particular, we considered all authors as nodes and included an edge if two authors submitted a joint HEP-Th paper within the last τ month from some month t .
We removed authors without any papers from the graph and resolved duplicates.
We varied t over the entire range between January 1992 and April 2003 in the HEP-Th data set and τ ∈ { 1 , . .
, 12 } , thus obtaining 1554 different graphs of sizes in the range [100 , 2786] .
For all these graphs, we measured the time needed to compute a forward and backward pass with a GEN without edge ﬁltering ( i.e. (cid:126)e + = (cid:126)e − = (cid:126) 1 in all cases) and with edge ﬁltering respectively.
For forward computations, both variants scaled sub-quadratically with empiric exponents of 1 . 65 and 1 . 37 respectively.
For the backward pass, GENs without node ﬁltering scaled with an exponent of 4 . 11 , whereas GENs with edge ﬁltering scaled roughly linearly (exponent 0 . 93 ), yielding faster times by several orders of magnitude.
We emphasize that edge ﬁltering can not be made arbitrarily strict.
As discussed in Section 3.2, the limit on the number of edited nodes must be adjusted to the training data; otherwise accuracy will suffer.
Still, the precise value of the limit only inﬂuences a constant factor in the linear efﬁciency.
The asymptotic complexity remains the same.
C ONCLUSION
We introduced the graph edit network, a simple linear output layer for graph neural networks to predict graph edits.
In contrast to prior work, graph edits cover all possible graph-to-graph transformations, including changes in the node set.
Importantly, graph edits are sparse, reducing the time complexity from quadratic to linear and facilitating interpretation.
Further, graph edits can be locally decided at each node, avoiding the need for pooling layers.
In addition to the novel output layer, we also provided a training scheme which only requires a mapping between nodes as input and then returns target values for all outputs of the linear layer, turning the training into combination of binary classiﬁcation and regression tasks that can be solved with established methods.
We further showed that, if the input node mapping is optimal and the graph neural network layers are expressive enough, a graph edit network can achieve edit scripts almost as short as the graph edit distance.
Empirically, we evaluated graph edit networks against variational graph autoencoders, variational graph recurrent nets, and kernel time series prediction on three graph and two tree dynamical systems, proving the concept of graph edit networks.
We hope that our work is the starting point for exciting further research in the ﬁeld of graph-to-graph learning and time series prediction on graphs, especially in combination with recurrent graph neural networks to go beyond the Markovian setting.
A P ROOFS A. P ROOF OF T HEOREM
We structure our proof into three lemmas.
Lemma 1 translates a graph mapping into a script, Lemmatranslates a script to a graph mapping, and Lemma 3 shows that the length never gets longer by doing so.
This argument is analogous to Proposition 1 by Bougleux et al.
(2017), who show a one-to-one correspondence between bijective mappings and a reduced set of edit scripts, called restricted paths.
In this work, we aim to connect the notion of graph mappings to teaching signals for graph edit networks.
To make this connection, we require stronger statements about the structure of such graph mappings and a different order of operations compared to Bougleux et al.
(2017), such that we provide a full argument here, without relying on Bougleux et al.
(2017) directly.
First, we deﬁne the corresponding script to a graph mapping.
Deﬁnition 2.
Let G =
( V = { 1 , . . .
, M } , E, X ) and H =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) be two nonempty graphs, i.e. M, N > 0 , and let ψ be a graph mapping between G and H .
We then deﬁne the script ¯ δ ψ corresponding to ψ between G and H as follows.
First, we construct a replacement rep i,(cid:126)x (cid:48) ψ
( i ) for all i (in ascending order) where i ≤ M , ψ ( i ) ≤ N and (cid:126)x i (cid:54) =
(cid:126)x (cid:48)
ψ ( i ) .
Let ¯ δ rep ψ be the script of all these replacements.
Next, we construct an insertion ins x (cid:48) ψ
( i ) for all i (in ascending order) where i > M and ψ ( i ) ≤ N .
Let ¯ δ ins ψ be the script of all these insertions.
Next, we construct an edge insertion eins i,j for all ( i, j ) (in lexicographically ascending order) where ( i, j ) / ∈ E
but ( ψ ( i ) , ψ ( j ))
∈ E (cid:48) .
Let ¯ δ eins ψ be the script of all these edge insertions.
Next, we construct an edge deletion edel i,j for all ( i, j ) (in lexicographically ascending order) where ( i, j ) ∈ E but ( ψ ( i ) , ψ ( j )) / ∈ E (cid:48) .
Let ¯ δ edel ψ be the script of all these edge deletions.
Finally, we construct a node deletion del i for all i ≤ M (in descending order) where ψ ( i ) > N .
Let ¯ δ del ψ be the script of all these node deletions.
We then deﬁne the overall script ¯ δ ψ as the concatenation ¯ δ ψ = ¯ δ rep ψ , ¯ δ ins ψ , ¯ δ eins ψ , ¯ δ edel ψ , ¯ δ del ψ .
We next show that the scripts resulting from graph mappings do what they should, i.e. they to indeed convert G to a graph that is isomorphic to H .
Lemma 1.
Let G =
( V = { 1 , . . .
, M } , E, X ) and H =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) be two nonempty graphs, i.e. M, N > 0 , let ψ be a graph mapping between G and H , and let ¯ δ ψ be the corresponding script.
Then, ˜ H :
= ¯ δ ψ ( G ) is isomorphic to H .
Proof.
In particular, by applying ¯ δ rep ψ and ¯ δ ins ψ , to G , we obtain a node set ˜ V and attributes ˜ X with the following properties.
First, consider U :=
{ i ∈ ˜
V | ψ ( i ) ≤ N } .
Due to our construction and
Deﬁnition 1 of a graph mapping, it holds U
=
{ i ≤ M | ψ ( i ) ≤ N } ∪ { M < i ≤ M + | Ins ψ |} and ψ ( U ) =
{ j ≤ N | ψ − 1 ( j ) ≤ M } ∪ Ins ψ = V (cid:48) .
Further, for all i ∈ U we have by construction ˜ x
i = (cid:126)x (cid:48) ψ ( i ) , because either i ≤ M and (cid:126)x i = (cid:126)x (cid:48) ψ ( i ) , in which case this holds trivially, or i ≤ M and (cid:126)x i (cid:54) =
(cid:126)x (cid:48)
ψ ( i ) , in which case a replacement was applied which ensured the condition, or M < i ≤
M + | Ins ψ | in which case an insertion was applied that ensured the condition.
Next, we consider the graph ˜ G =
( ˜ V , ˜ E, ˜ X ) =
¯ δ rep ψ , ¯ δ ins ψ , ¯ δ eins ψ , ¯ δ edel ψ ( G ) , i.e. the graph that results from additionally applying all edge insertions and edge deletions.
For this graph we can show that the subgraph restricted to the node set U is isomorphic to H with the isomorphism ψ restricted to
U .
In particular, we have already shown that ψ ( U ) =
V (cid:48) and that ˜ x i = (cid:126)x (cid:48) ψ
( i ) .
It remains to show that for all i, j ∈ U it holds: ( i, j ) ∈ ˜
E
if and only if ( ψ ( i ) , ψ ( j )) ∈ E (cid:48) .
This, however, is exactly the condition enforced by the edge deletion/insertion construction above.
Accordingly, the subgraph restricted to the nodes U is indeed isomorphic to H .
Additionally, we also obtain that for any node i / ∈ U , there exists no edge ( i, j ) or ( j, i ) in ˜ E , because these would have been deleted by ¯ δ edel ψ .
Finally, ¯ δ del ψ deletes all nodes i / ∈ U (in descending order to prevent interference in node ordering) and the remaining graph ˜ H =
¯ δ ( G ) is isomorphic to H , because it is exactly the subgraph we have analyzed before.
This concludes the proof.
In a next step, we deﬁne the conversion back from a script to a graph mapping.
Deﬁnition 3.
Let G =
( V = { 1 , . . .
, M } , E, X ) and H =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) be two non-empty graphs, i.e. M, N > 0 .
Further, let ˜ H
=
( ˜ V (cid:48)
= { 1 , . . .
, N } , ˜ E (cid:48) , ˜ X (cid:48) ) be a graph that is isomorphic to H via isomorphism ˜ ψ : { 1 , . . .
, N } → { 1 , . .
. , N } from ˜ V (cid:48) to V (cid:48) , i.e. for all i ∈ ˜ V (cid:48) :
˜ x (cid:48)
i =
(cid:126)x (cid:48)
ψ ( i ) , and ( i, j ) ∈
˜ E (cid:48)
if and only if ( ˜ ψ ( i ) , ˜ ψ ( j )) ∈ E (cid:48) .
Finally, let ¯ δ =
δ 1 , . . .
, δ T be an edit script, such that ¯ δ ( G ) =
˜ H .
Then, we deﬁne the mapping ψ ¯ δ : { 1 , . . .
M + N } → { 1 , . .
M + N } recursively as follows.
First, if T = 0 ( i.e. ¯ δ is empty), we set ψ ¯ δ =
˜ ψ , extended by the identity on the inputs N +1 , . .
, M +
N .
Next, if T > 0 , let ψ (cid:48) :
= ψ δ 2 ,...,δ T and consider the ﬁrst edit
δ 1 .
If δ 1 ( G ) = G , i.e. the edit has no effect, we set ψ ¯ δ = ψ (cid:48) .
If δ 1 = del j for some j , we set ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all
i < j , ψ ¯ δ ( i ) = ψ (cid:48)
( i − 1) for all i > j , and ψ ¯ δ ( i ) =
M + N .
If δ 1 = ins (cid:126)x for some (cid:126)x , let i ∗ :
= ψ (cid:48)− 1 ( M + N + 1) and distinguish four cases.
First, if i ∗ ≤ M and ψ (cid:48) ( M + 1) ≤ N , we set ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i (cid:54)
= i ∗ and ψ ¯ δ
( i ∗ ) =
ψ (cid:48)
( M + N + 1) .
Second, if i ∗ ≤ M and ψ (cid:48) ( M +1) >
N , we set ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i (cid:54)
= i ∗ with i ≤ M , ψ ¯ δ ( i ∗ ) =
ψ (cid:48)
( M +1) , and ψ ¯ δ ( i ) = ψ (cid:48)
( i + 1) for all i > M .
Third, if i ∗ =
M + 1 , we set ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i ≤ M and
ψ ¯ δ ( i ) =
ψ (cid:48)
( i + 1) for all i > M .
Fourth, if i ∗ > M + 1 , we set ψ ¯ δ ( i ) =
ψ (cid:48) , restricted to { 1 , . .
M + N } .
Finally, if δ 1 is any other edit, we set ψ ¯ δ = ψ (cid:48) .
We will later prove in Corollary 2 that the resulting mapping ψ ¯ δ is indeed a graph mapping.
Refer to Figure 3 for an example of the construction.
In particular, we consider the script ¯ δ = del 2 , ins (cid:126)x 1 , ins (cid:126)x 2 , del 3 , transforming the graph G =
( V = { 1 , 2 , 3 } , E = ∅ , X ) to the graph ˜ H =
( ˜ V (cid:48)
= { 1 , 2 , 3 } , ˜ E (cid:48)
= ∅ , ˜ X (cid:48) ) , which in turn is isomorphic to the graph
H =
( V (cid:48)
= { 1 , 2 , 3 } , E (cid:48)
= ∅ , X (cid:48) )
for some attributes X , ˜ X (cid:48) , X (cid:48) .
The isomorphism between ˜ H and H is known and it is the mapping ˜ ψ with ˜ ψ (1)
= 3 , ˜ ψ (2)
= 1 , and ˜ ψ (3)
= 2 .
Now, we construct the mapping ψ ¯ δ recursively from the last edit to the ﬁrst.
The initial mapping for the empty script is ψ (cid:15) : { 1 , . .
, 3 + 3 } → { 1 , . . .
, 3 + 3 } with ψ (cid:15) ( i ) =
˜ ψ ( i ) for i ≤ 3 and ψ (cid:15) ( i ) =
i for i > 3 .
Next, we incorporate the last edit of the script del 3 .
Because this is a deletion, the graph before the deletion must have had one node more.
Accordingly, ψ del 3 is now deﬁned on the domain and image { 1 , . . .
, 4 + 3 } .
In more detail, following Deﬁnition 3 we obtain the mapping ψ del 3 (1) = ψ (cid:15) (1) = 3 , ψ del 3 (2) = ψ (cid:15) (2)
= 1 , ψ del 3 (3)
= 4 + 3 = 7 , ψ del 3 (4) =
ψ (cid:15) (4 − 1) = 2 , ψ del 3 (5) = ψ (cid:15) (5 − 1) = 4 , ψ del 3 (6) = ψ (cid:15) (6 − 1)
= 5 , and ψ del 3 (7) =
ψ (cid:15) (7 − 1) = 6 .
In the ﬁgure, this mapping is obtained by following all arrows from the graph right of ˜ H to their end point.
Next, we incorporate the edit ins (cid:126)x 2 .
Because we consider an insertion, the graph before the insertion had one node less.
Accordingly, the mapping ψ ins (cid:126)x 2 , del 3 is now deﬁned on the domain and image { 1 , . . .
, 3 + 3 } ; it is crucial that we remove the entry 3 + 3 + 1 = 7 from the codomain of our mapping.
The pre-image of 7 is i ∗ =
ψ − 1 del 3 (7) = 3 .
Further, we need to consider whether the inserted node 3 + 1 = 4 gets deleted later in the script.
Because ψ del 3 (3 + 1) = 2 ≤ 3 , we know that this is not the case.
Accordingly, the ﬁrst of the four cases in Deﬁnition 3 applies and we obtain ψ ins (cid:126)x 2 , del 3 ( i ) =
ψ del 3 ( i ) for all i (cid:54) =
i ∗ = 3 and ψ ins (cid:126)x 2 , del 3 (3) =
ψ del3 (7) = 6 .
Note that this is still a proper graph mapping, i.e. the bijectivity is never violated and the only node j ∈ Ins ψ ins (cid:126)x 2 , del3 iswith the pre-image ψ ins (cid:126)x 2 , del 3 (2) = 4 = 3 + 1 , as required.
Now, we incorporate another insertion ins (cid:126)x 1 .
We observe that the newly inserted node 2 + 1 = 3 will get deleted later, since we have ψ ins (cid:126)x 2 , del 3 (2 + 1) = 6 > 3 .
Furthermore, the newly inserted nodeis at the same time the pre-image of entry 2 + 3 + 1 = 6 , which we need to delete later.
Accordingly, the third case in Deﬁnition 3 applies and we obtain ψ ins (cid:126)x 1 , ins (cid:126)x 2 , del 3 ( i ) =
ψ ins (cid:126)x 2 , del 3 ( i ) for i ≤ 2 and ψ ins (cid:126)x 1 , ins (cid:126)x 2 , del 3 ( i ) =
ψ ins (cid:126)x 2 , del 3 ( i + 1) for i > 2 .
Because we do not refer to ψ ins (cid:126)x 2 , del 3 (2 + 1) = 6 , we do not leave the desired range { 1 , . . .
, 2 + 3 } .
Also note that Ins ψ ins
[Table]
, ins
2 , del3 still contains only the node 2 , which has the pre-image ψ ins ins del 3 (
= 3 = 2 + as required
H
˜
H       ˜ ψ       del      ins (cid:126)x     ins (cid:126)x
G      del
H      ψ ¯ δ
Finally, we incorporate the deletion del 2 .
As stated in Deﬁnition 3, we thus obtain ψ ¯ δ ( i ) =
ψ ins (cid:126)x 1 , ins (cid:126)x 2 , del 3 ( i ) for i < 2 , ψ ¯ δ (2) = 3 + 3 = 6 , and ψ ¯ δ ( i ) = ψ ins (cid:126)x 1 , ins (cid:126)x 2 , del 3 ( i − 1) for i > 2 .
The ﬁnal mapping is thus ψ ¯ δ (1) = 3 , ψ ¯ δ (2) = 6 , ψ ¯ δ (3) = 1 , ψ ¯ δ (4) = 2 , ψ ¯ δ (5) = 4 , and ψ ¯ δ (6) = 5 .
In
Figure 3, we obtain this mapping by starting at G and following the arrows to their end points.
Our next step is to show that the mapping constructed from a script is indeed a graph mapping and that additional structure applies, which we can exploit later on.
Lemma 2.
Let G , ˜ H , H be graphs as in the previous deﬁnition with isomorphism ˜ ψ between ˜
H and H , let ¯ δ =
δ 1 , . . .
, δ T be a script, such that ¯ δ ( G ) =
˜ H , let ψ ¯ δ be the corresponding mapping, and let ψ : { 1 , . . .
M + N } → { 1 , . .
, M + N } be deﬁned as ψ ( i ) =
˜ ψ − 1 ( ψ ¯ δ ( i ))
if ψ ¯ δ ( i ) ≤ N and ψ ( i ) =
ψ ¯ δ ( i ) otherwise, i.e. the mapping composed with ˜ ψ − 1 .
Further, let
Del ψ := { i ≤ M | ψ ( i ) > N } .
Then, ψ is bijective.
Further, for all i / ∈ Del ψ , ψ is monotonously increasing (constraint 1), and the image of ψ on Del ψ is { M + N + 1 − | Del ψ | , . . .
, M + N } (constraint 2).
Proof.
We perform this proof via induction over the length T of the script ¯ δ =
δ 1 , . . .
, δ T .
If T = 0 , ψ is the identity, which is obviously bijective, yields Del ψ = ∅ (such that constraint 2 is fulﬁlled), and is monotonously increasing (such that constraint 1 is fulﬁlled).
Now, if T > 1 , let ψ (cid:48) be deﬁned as ψ above, but between the graphs δ 1 ( G ) and H .
Accordingly, ψ (cid:48) is a bjective mapping from and to { 1 , . . .
, M (cid:48)
+ N } by induction, where M (cid:48) is the size of the node set of δ 1 ( G ) .
Further, by induction we also know that ψ (cid:48) is monotonously increasing on all inputs except on Del ψ (cid:48) :
= { i ≤ M (cid:48) | ψ (cid:48) ( i ) >
N } (constraint 1) and that the image of ψ (cid:48) on Del ψ (cid:48) is precisely { M (cid:48)
+ N + 1 − | Del ψ (cid:48) | , . .
, M (cid:48)
+ N } (constraint 2).
Now, consider the ﬁrst edit δ 1 .
If δleaves the node set as-is, we obtain M = M (cid:48) , ψ = ψ (cid:48) , and both constraints hold by induction.
If δ 1 = del j for some j ≤ M , we obtain M (cid:48)
=
M − 1 .
Further, by the deﬁnition of ψ ¯ δ , we obtain ψ ( i ) =
ψ (cid:48)
( i ) for i < j , ψ ( i ) =
ψ (cid:48)
( i − 1) for i > j , and ψ ( j ) =
M + N .
Accordingly, ψ maps the set { 1 , . . .
, j − 1 } ∪ { j + 1 , . . .
M + N } bijectively to { 1 , . . .
M + N − 1 } and the setting ψ ( j )
=
M + N completes the bijective map.
Further, j ∈ Del ψ and is mapped to M + N , conforming to constraint 2.
Finally, for all other inputs both constraints hold by induction.
If δ 1 = ins (cid:126)x for some (cid:126)x , we obtain M (cid:48)
=
M + 1 and thus ψ (cid:48) is a bijective map from and to { 1 , . . .
M + N + 1 } .
Now, let i ∗ = ψ (cid:48)− 1 ( M + N + 1) and distinguish four cases.
First, if i ∗ ≤ M and ψ (cid:48) ( M + 1) ≤ N we obtain ψ ( i ) =
ψ (cid:48)
( i ) for all i (cid:54)
= i ∗ and ψ ( i ∗ ) =
ψ (cid:48)
( M +
N +1) .
First, observe that ψ (cid:48) ( M + N +1) <
M + N +1 , otherwise ψ (cid:48)
( M + N +1)
=
M + N +
and i ∗ =
M + N + 1 > M , which is a contradiction.
Accordingly, ψ is a bijective map from and to { 1 , . . .
M + N } because by deﬁnition ψ maps the set { 1 , . .
, i ∗ − 1 } ∪ { i ∗ + 1 , . . .
, M + N } to { 1 , . .
, M + N }\{ ψ (cid:48)
( M + N +1) } and the setting ψ ( i ∗ ) =
ψ (cid:48)
( M + N +1) completes the bijective map.
Furthermore, we obtain ψ (cid:48)
( M + N + 1) > N .
Otherwise, the monotonicity of ψ (cid:48) would require all values M + 2 , . . .
, M + N to be mapped to values ≤ N as well.
However, there exist only N such values and one is already blocked by ψ (cid:48)
( M + 1) , which is a contradiction.
Accordingly, ψ (cid:48)
( M + N + 1) > N and thus i ∗ ∈
Del ψ .
Both constraints hold by induction.
Second, if i ∗ ≤ M and ψ (cid:48) ( M + 1) > N we obtain ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i (cid:54)
= i ∗ with i ≤ M , ψ ¯ δ ( i ∗ ) =
ψ (cid:48)
( M + 1) , and ψ ¯ δ ( i ) =
ψ (cid:48)
( i + 1) for all i > M .
Accordingly, ψ is a bijective map from and to { 1 , . . .
M + N } because by deﬁnition ψ maps the set { 1 , . .
, i ∗ − 1 , i ∗ + 1 . . .
M + N } to the image of ψ (cid:48) for the inputs { 1 , . .
, i ∗ − 1 , i ∗ + 1 . . .
, M, M + 2 , . .
, M + N + 1 } , which is exactly { 1 , . .
, M + N } \ { ψ (cid:48)
( M + 1) } .
Setting ψ ¯ δ ( i ∗ ) =
ψ (cid:48)
( M + 1) then completes the bijective map.
Further, on all inputs except i ∗ both constraints still hold due to induction.
For i ∗ , we obtain i ∗ ∈
Del ψ because ψ ( i ∗ ) =
ψ (cid:48)
( M + 1) > N and because M + 1 ∈ Del ψ (cid:48) constraint 2 also holds for i ∗ due to induction.
Third, if i ∗ =
M + 1 , we obtain ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i ≤ M , ψ ¯ δ ( i ) =
ψ (cid:48)
( i + 1) for all i > M .
This is a bijective map from and to { 1 , . . .
M + N } because by deﬁnition ψ maps { i, .
M + N } to the image of ψ (cid:48) for { 1 , . . .
, M, M + 2 , . .
, M + N + 1 } , which is exactly { 1 , . .
M + N } .
Further, the constraints hold due to induction.
Fourth, if i ∗ > M + 1 , we obtain ψ ¯ δ ( i ) =
ψ (cid:48) restricted to { 1 , . .
M + N } .
In this case, we observe that i ∗ must be M + N + 1 .
Otherwise, we would obtain ψ (cid:48)
( i ∗ + 1) <
M + N + 1 = ψ (cid:48)
( i ∗ ) , which contradicts monotonicity of ψ (cid:48) .
Accordingly, restricting ψ (cid:48) to { 1 , . . .
, M + N } does indeed yield a bijective map to { 1 , . . .
M + N } which conforms to both constraints due to induction.
Because this covers all possible edits, this concludes our proof.
Corollary 2.
Let G , H , ˜ H , ˜ ψ , ¯ δ , ψ ¯ δ , and ψ be deﬁned as in the previous Lemma.
then, ψ ¯ δ is a graph mapping between G and H .
Proof.
First, observe that ψ ¯ δ ( i ) =
˜ ψ ( ψ ( i )) for all i with ψ ¯ δ ( i ) ≤ N , and ψ ¯ δ ( i ) =
ψ ( i ) otherwise.
Further, observe that ψ ¯ δ must thus be bijective.
Otherwise, ψ or ˜ ψ could not be bijective.
Next, assume that there exists some j ∈ Ins ψ ¯ δ such that ψ − 1 ¯ δ ( j ) >
M + | Ins ψ ¯ δ | .
Then, because ψ ¯ δ is bijective, there also exists some i with M < i ≤ M + | Ins ψ ¯ δ | with ψ ¯ δ ( i ) / ∈
Ins ψ ¯ δ .
This implies that ψ ¯ δ ( i ) > N ≥ j , even though ψ − 1 ¯ δ ( j ) >
i , which contradicts the monotonicity constraint on ψ .
Accordingly, ψ ¯ δ is indeed a graph mapping between G and H .
Lemma 3.
Let G =
( V = { 1 , . . .
, M } , E, X ) and H =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) be two nonempty graphs, i.e. M, N > 0 .
Further, let ˜ H
=
( ˜ V (cid:48)
= { 1 , . . .
, N } , ˜ E (cid:48) , ˜ X (cid:48) ) be a graph that is isomorphic to H via isomorphism ˜ ψ : { 1 , . . .
, N } → { 1 , . .
. , N } , and let ¯ δ be an edit script with ¯ δ ( G ) =
˜ H .
Finally, let ψ ¯ δ be the corresponding graph mapping between G and H and let ¯ δ ψ ¯ δ be the edit script corresponding to that graph mapping.
Then, it holds: | ¯ δ ψ ¯ δ | ≤ | ¯ δ | .
Proof.
We again prove this claim via induction over the length T of the script ¯ δ =
δ 1 , . . .
, δ T .
First, if T = 0 , G = ¯ δ ( G ) =
˜ H .
Accordingly, ψ ¯ δ is ˜ ψ
(extended with the identity on M +1 , . . .
, M +
N ).
It then follows that ¯ δ ψ ¯ δ is empty.
In particular, there can not exist any i ≤ M with (cid:126)x i (cid:54) =
(cid:126)x (cid:48)
ψ ¯ δ ( i ) =
(cid:126)x (cid:48)
˜ ψ ( i ) , otherwise ˜ ψ would not be an isomorphism between ˜ H and H .
Accordingly, ¯ δ rep ψ ¯ δ is empty.
Further, there can not exist any i > M with ψ ¯ δ ( i ) ≤ N , because ψ ¯ δ ( i ) =
i > M = N .
Accordingly, ¯ δ ins ψ ¯ δ is empty.
Next, for all i, j ≤ M it holds ( i,
j ) ∈
E ⇐⇒ ( ψ ¯ δ ( i ) , ψ ¯ δ ( j )) =
( ˜ ψ ( i ) , ˜ ψ ( j ))
∈ E (cid:48) , otherwise ˜ ψ would not be an isomorphism between ˜ H and H ; and for all i, j > M = N it holds ( i, j ) / ∈ E and
( ψ ¯ δ ( i ) , ψ ¯ δ ( j )) =
( i, j ) / ∈ E (cid:48) per deﬁnition.
Accordingly, both ¯ δ eins ψ ¯ δ and ¯ δ edel ψ ¯ δ are empty.
Finally, there can not exist an i ≤ M with ψ ¯ δ ( i ) =
˜ ψ ( i ) > N because the image of ˜ ψ is
, N } .
Accordingly, ¯ δ del ψ ¯ δ is empty and thus ¯ δ ψ ¯ δ =
¯
δ rep ψ ¯ δ ¯ δ ins ψ ¯ δ ¯ δ eins ψ ¯ δ ¯ δ edel ψ ¯ δ ¯ δ del ψ ¯ δ is overall empty as well, i.e. | ¯ δ ψ ¯ δ | = 0 ≤ 0 = | ¯ δ | , as claimed.
Now, consider the case T > 0 , let ψ (cid:48) :
= ψ δ 2 ,...,δ T , and let ˜ G =
( ˜ V , ˜ E, ˜ X ) :
= δ 1 ( G ) .
Further, let ¯ δ ψ (cid:48) be the script that ψ (cid:48) is transformed into based on ˜ G and H .
By induction, | ¯ δ ψ (cid:48)
| ≤ T − 1 .
We now consider the ﬁrst edit δ 1 .
If δ 1 has no effect on G , we obtain ψ ¯ δ = ψ (cid:48) and by deﬁnition ¯ δ ψ ¯ δ =
¯ δ ψ (cid:48) , which in turn yields | ¯ δ ψ ¯ δ | =
| ¯ δ ψ (cid:48)
| ≤ T − 1 < T as claimed.
If δ 1 = rep i,(cid:126)x for some i ≤ M and some (cid:126)x , we obtain ψ ¯ δ = ψ (cid:48) , V = ˜
V , E =
˜ E , (cid:126)x j = ˜ x j for j (cid:54) = i , and ˜ x i = (cid:126)x (cid:54) =
(cid:126)x i .
Now, distinguish two cases.
If (cid:126)x = (cid:126)x (cid:48) ψ (cid:48)
( i ) , i.e. ˜ x i = (cid:126)x (cid:48) ψ (cid:48)
( i ) (cid:54) =
(cid:126)x i , ¯ δ ψ ¯ δ contains by construction an edit rep i,(cid:126)x and otherwise the same edits as ¯ δ ψ (cid:48) , such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | + 1 ≤ T − 1 + 1 = T as claimed.
If (cid:126)x (cid:54) =
(cid:126)x (cid:48) ψ (cid:48)
( i ) , i.e. δ 1 sets ˜ x
i to a value which is temporary and not equal to the ﬁnal value of (cid:126)x (cid:48) ψ ( i ) , we obtain ¯ δ ψ ¯ δ =
¯ δ ψ (cid:48) , because ¯ δ ψ (cid:48) by construction already contains an edit rep i,(cid:126)x (cid:48) ψ (cid:48)
( i ) .
Accordingly, we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48)
| ≤ T − 1 < T as claimed.
If δ 1 = ins (cid:126)x for some (cid:126)x , we obtain ˜ V
= V ∪ { M + 1 } , ˜ E
= E , ˜ x i = (cid:126)x i for i ≤ M , and ˜ x M +1 = (cid:126)x .
Now, let let i ∗ :
= ψ (cid:48)− 1 ( M + N + 1) and distinguish four cases.
First, if i ∗ ≤ M and ψ (cid:48) ( M + 1) ≤ N , we obtain ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for i (cid:54)
= i ∗ and ψ ¯ δ
( i ∗ ) =
ψ (cid:48)
( M +
N + 1) .
As argued in the proof of the previous lemma, ψ (cid:48) ( M + N + 1) > N due to monotonicity of ψ (cid:48) .
Accordingly, i ∗ is deleted both in ¯ δ ψ (cid:48) and in ¯ δ ψ ¯ δ .
Further, M + 1 is inserted in ¯ δ ψ ¯ δ but not in ¯ δ ψ (cid:48) , while all other edits remain the same such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | + 1 ≤ T − 1 + 1 = T as claimed.
Second, if i ∗ ≤ M and ψ (cid:48) ( M + 1) > N , we obtain ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i with i ≤ M and i (cid:54)
= i ∗ , ψ ¯ δ ( i ∗ ) =
ψ (cid:48)
( M + 1) , and ψ ¯ δ ( i ) =
ψ (cid:48)
( i + 1) for all i > M .
Because ψ (cid:48)
( M + 1) > N , i ∗ is deleted both in ¯ δ ψ (cid:48) and in ¯ δ ψ ¯ δ .
Further, M + 1 is deleted in ¯ δ ψ (cid:48) but not in ¯ δ ψ ¯ δ , while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | − 1 ≤ T − 2 < T as claimed.
Third, if i ∗ =
M + 1 , we obtain ψ ¯ δ ( i ) =
ψ (cid:48)
( i ) for all i ≤ M and
ψ ¯ δ ( i ) =
ψ (cid:48)
( i + 1) otherwise.
Again, M + 1 is deleted in ¯ δ ψ (cid:48) but not in ¯ δ ψ ¯ δ , while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | − 1 ≤ T − 2 < T as claimed.
Fourth, if i ∗ > M + 1 , we obtain ψ ¯ δ = ψ (cid:48) restricted to { 1 , . . .
M + N } .
Further, i ∗ =
M + N +as argued in the proof of the previous lemma.
Accordingly, M + 1 is inserted in ¯ δ ψ ¯ δ but not in ¯ δ ψ (cid:48) , while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | + 1 ≤ T − 1 + 1 = T as claimed.
Next, if δ 1 = eins i,j , we obtain ψ ¯ δ = ψ (cid:48) as well as ˜ V = V , ˜ X
= X (cid:48) , and ˜ E
= E ∪ { ( i, j ) } .
Now, distinguish two cases.
If ( ψ (cid:48) ( i ) , ψ (cid:48) ( j )) ∈ E (cid:48) , ¯ δ ψ ¯ δ inserts ( i, j ) whereas ¯ δ ψ (cid:48) does not, while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | +1 ≤ T − 1+1 = T as claimed.
Conversely, if ( ψ (cid:48) ( i ) , ψ (cid:48)
( j )) / ∈ E (cid:48) , ¯ δ ψ (cid:48) deletes ( i, j ) whereas ¯ δ ψ ¯ δ does not, while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | − 1 ≤ T − 2 < T as claimed.
Next, if δ 1 = edel i,j , we obtain ψ ¯ δ = ψ (cid:48) as well as ˜ V = V , ˜ X
= X (cid:48) , and ˜ E
= E \ { ( i, j ) } .
Now, distinguish two cases.
If ( ψ (cid:48) ( i ) , ψ (cid:48) ( j )) / ∈ E (cid:48) , ¯ δ ψ ¯ δ deletes ( i, j ) whereas ¯ δ ψ (cid:48) does not, while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | +1 ≤ T − 1+1 = T as claimed.
Conversely, if ( ψ (cid:48) ( i ) , ψ (cid:48)
( j ))
∈ E (cid:48) , ¯ δ ψ (cid:48) inserts ( i, j ) whereas ¯ δ ψ ¯ δ does not, while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | − 1 ≤ T − 2 < T as claimed.
Finally, if δ 1 = del i , we obtain ψ ¯ δ ( j ) =
ψ (cid:48)
( j ) for all j < i , ψ ¯ δ ( j ) = ψ (cid:48)
( j − 1) for all j > i , and ψ ¯ δ ( j ) =
M + N , as well as ˜ V = { 1 , . .
, M − 1 } , ˜ x
j = (cid:126)x j for all j ∈ ˜ V , and ˜ E
= E .
Accordingly, ¯ δ ψ ¯ δ deletes i whereas ¯ δ ψ (cid:48) does not, while all other edits remain the same, such that we obtain | ¯ δ ψ ¯ δ | = | ¯ δ ψ (cid:48) | + 1 ≤ T − 1 + 1 = T as claimed.
Because this covers all possible edits, this concludes our proof.
We note again that the entire argument up to this point is analogous to Proposition 1 of Bougleux et al.
However, in contrast to Bougleux et al.
(2017), we do not rely on a notion of restricted edit scripts, instead comparing to all possible edit scripts, and we provide stronger claims regarding the structure of our graph mappings via Lemma 2.
We also slightly change the order of operations for consistency with Algorithm 1.
A. P ROOF OF T HEOREM
The heart of our proof is Algorithm 2, which translates a graph mapping to a corresponding teaching signal for a graph edit network.
We prove the correctness of this algorithm with the following Lemma.
Refer to Figure 4 for a graphical intuition.
In particular we consider in this example the graphs G = ( { 1 , 2 , 3 } , { (1 , 2) , (1 , 3) , (3 , 1) } , X ) and
H =
( { 1 , 2 , 3 , 4 , 5 , 6 } , { (1 , 2) , (2 , 3) , (3 , 1) , (4 , 5) , (5 , 4) } , X (cid:48) ) as well as the graph mapping ψ with π (1) = 3 , π (2) = 2 , and π (3) = 1 .
Note that H is not fully connected.
In particular, we have the connected components { 1 , 2 , 3 } , { 4 , 5 } , and { 6 } .
In itself, this would not be a problem, but note that
Algorithm 1 can only insert a new node that is connected to an existing node.
Accordingly, we can not insert node without any connection to the pre-existing graph.
However, this would be required for the insertion of nodes 4 , 5 , and 6 .
To manage this, Algorithm 2 ﬁrst constructs auxiliary edges (in lines 2-5) connecting the new nodes to the already existing part of the graph, in particular the edges (3 , 4) and (3 , 6) .
Then, the algorithm computes (in lines 6-9) the shortest path to any inserted node from any already existing node, yielding the paths π 4 = (3 , 4) , π 5 = (3 , 4 , 5) , and π 6 = (3 , 6) .
Line 13 then re-deﬁnes the shortest paths as a shortest-path tree with children ch(3)
=
(4 , 6) and ch(4) = (5) .
Lines 14-22 then take care of performing the actual node insertions, where insertions are put into different steps of the teaching signal if they can not be performed at the same time.
In particular, we need to use multiple steps whenever a single node has multiple children in the shortest-path tree and whenever a node that does not yet exist needs to make an insertion.
Both is covered by the depth-ﬁrst-search in lines 14-23.
In particular, we ﬁrst insert parents, then children, and we insert children in succession.
In our example, this results in node 4 being inserted in the ﬁrst step (by node 1 ) and nodes 5 and 6 being inserted in the second step (by nodes 1 and 4 , respectively).
Then, line 24 initializes the third and ﬁnal step of our teaching signal which performs all remaining edits.
In particular, line 25 sets up all replacements (irrelevant in this case), line 26 all edge insertions ( (2 , 1) , (3 , 2) , and (5 , 4) in this case), line 27 all edge deletions ( (1 , 2) , (3 , 1) , (1 , 4) , and (1 , 6) in this case), and line 28 all node deletions (none in this case).
Lines 29-30 ensure that the edge ﬁlter scores (cid:126)e + K +
and (cid:126)e − K +1 are consistent with the edge edit scores
E K +1 .
Finally, we return the result.
The resulting script is shown in the bottom of the ﬁgure.
Note that this script is not as short as possible because it contains four additional auxiliary edits, namely the edge insertions (1 , 4) and (1 , 6) , which are then deleted in the end.
This is because a graph edit network connects any newly inserted node to an existing node and, thus, can not by itself handle entirely inserted connected components C 1 and C 2 .
Both components are ﬁrst connected to the existing graph and then disconnected again afterwards, yielding the desired graph.
We ﬁrst consider the time complexity of the algorithm.
First, note that computing connected components in line 2 is possible in O ( N ) .
Similarly, the minimum computations in lines 3-4 are possible in O ( N ) .
Constructing the auxiliary graph in line 5 may need O ( N 2 ) for a dense graph.
Because we have unit edge weights for the shortest path computation, a simple breadth-ﬁrst-search sufﬁces, making the computation in line 7 O ( N ) .
Because we need to repeat this computation for each insertion, lines 6-9 are overall in O ( N 2 ) .
Lines 10-12 are slightly implementation dependent.
In principle, constructing E k for each step would require O (( M + N ) 2 ) .
But because this matrix is always zero, we can construct it once and re-use it for every step.
All other operations are linear, yielding O (( M + N ) 2 ) overall.
The re-ordering of the shortest-path tree in lines 13 is linear in the number of insertions, which is in
O ( N ) .
Lines 14-22 perform a depth ﬁrst search through the shortest-path trees, which is in O ( N ) again.
This also includes recording the inserted edges for line 23.
G
H  3 r
C
Cψ shortest paths (lines 6-9): π 4 = (3 , 4) , π 5 = (3 , 4 , 5) , π 6 = (3 , 6)
Shortest path tree (line 13): ch(3) = (4 , 6) , ch(4) = (5) insertions (lines 14-22): ν 1 , 1 = +1 , ν 2 , 1 = +1 , ν 2 , 4 = + edge insertions (line 26): (cid:15) 3 , 2 , 1 = (cid:15) 3 , 3 , 2 = (cid:15) 3 , 5 , 4 = + edge deletions (line 27): (cid:15) 3 , 1 , 2 = (cid:15) 3 , 3 , 1 = (cid:15) 3 , 1 , 4 = (cid:15) 3 , 1 , 6 = −
[Figure]
G = ( { 1 , 2 , 3 } , { (1 , 2) , (1 , 3) , (3 , 1) }
X each node in C 1 and C 2 (top right).
This deﬁnes the shortest path tree with children ch(3) =
(4 , 6) and ch(4) = 5 .
Accordingly, node ψ − 1 (3) = 1 needs to insert two nodes ( 4 and 6 ), and node ψ − 1 (4) = 4 needs to insert one node ( 5 ).
Since this is not possible in one step, the ﬁrst step inserts only node 4 ( ν 1 , 1 = +1 ) and the second step nodes 5 and 6 ( ν 2 , 1 = +1 , ν 2 , 4 = +1 ).
The remaining edit scores ensure that the correct edges are inserted and deleted, yielding the ﬁnal script at the bottom.
This is exactly the script generated by ψ , except for four superﬂuous auxiliary edits, namely eins 1 , 4 , eins 1 , 6 , edel 1 , 4 , and edel 1 , 6 .
· ( C − auxiliary edits, where is the number of connected components in
1: function MAP - TO - SIGNAL (Two non-empty graphs G =
( V = { 1 , . . .
, M } , E, X ) and H =
( V (cid:48)
= { 1 , . . .
, N } , E (cid:48) , X (cid:48) ) , a graph mapping ψ between them) 2:
Compute the connected components of H C 1 , . . .
, C L where C l ⊆
Ins ψ .
Set c l ← min j ∈C l j for all l ∈ { 1 , . . .
, L } .
Set r ← min i ≤ M : ψ ( i ) ≤ N i .
Construct ˜ H
=
( V (cid:48) , E (cid:48) ∪ { ( ψ ( r ) , c 1 ) , . . .
, ( ψ ( r ) , c L ) } ) , X (cid:48) ) .
6: for j ∈ Ins ψ do 7:
Compute a shortest path π j 1 , . . .
, π jR j from the closest node 8: π j 1 ∈ { 1 , . . .
, N } \ Ins ψ to π jR j = j in ˜ H .
9: end for 10: for k ∈ { 1 , . .
, | Ins ψ |} do 11:
Initialize (cid:126)ν k ← (cid:126) 0 , Y k ← X , (cid:126)e − k +1 ← − (cid:126) 1 , (cid:126)e + k +1 ← − (cid:126) 1 , E k +1 ← 0 .
12: end for 13:
Let ch( j ) be the children of node j in the shortest path trees from roots π j 1 to inserted nodes.
Initialize a stack S with entries ( π j 1 , 0) for all j ∈ Ins ψ .
Set K ← 0 .
15: while S is not empty do 16:
Pop ( j, k ) from S .
Set c ← 1 .
Set i ← ψ − 1 ( j ) .
17: for j (cid:48) ∈ ch( j ) do 18:
Set ν k
+ c
,i ← +1 .
(cid:126)y k,i ← (cid:126)x (cid:48) j (cid:48) .
Add ( j (cid:48) , k + c ) to S .
20: c ← c + 1 .
K ← max { K, k + c } .
21: end for 22: end while 23:
Let E (cid:48)(cid:48) be the set of inserted edges ( i, j ) due to line 18.
Initialize (cid:126)ν K +1 ← (cid:126) 0 , Y K +1 ← 0 , (cid:126)e − K +1 ← − (cid:126) 1 , (cid:126)e + K +1 ← − (cid:126) 1 , E K +1 ← 0 , 25:
Set (cid:126)y K +1 ,i ← (cid:126)x (cid:48) ψ
( i ) if ψ ( i ) ≤ N .
(cid:46) performs replacements 26:
Set (cid:15) i,j ← +1 if ( i, j )
/ ∈ E ∪ E (cid:48)(cid:48) and ( ψ ( i ) , ψ ( j ))
∈ E (cid:48) .
(cid:46) performs edge insertions 27:
Set (cid:15) K
+1 ,i,j ← − 1 if ( i, j
) ∈ E ∪ E (cid:48)(cid:48) and ( ψ ( i ) , ψ ( j )) / ∈ E (cid:48) .
(cid:46) performs edge deletions 28:
Set ν
i ← − 1 if ψ ( i ) > N .
(cid:46) performs node deletions 29:
Set e
+ K +1 ,i ← +
if (cid:15) K +1 ,i,j (cid:54) = 0 for any j .
Set e − K +1 ,j ← +
if (cid:15) K +1 ,i,j (cid:54) = 0 for any i .
31: return ( (cid:126)ν 1 , X 1 ,(cid:126)e +1 ,(cid:126)e − 1 , E 1 ) , . . .
, ( (cid:126)ν K +1 , X K +1 ,(cid:126)e + K +1 ,(cid:126)e − K +1 , E K +1 ) .
32: end function
Lines 24-30 require only matrix and set lookups, making them overall O (( M + N ) 2 ) .
In summary, we obtain the claimed efﬁciency class of O ( M 2 + N 2 ) .
Now, let G and H be any two graphs, let C be the number of connected components in H , and let ψ be a graph mapping between them with | Ins ψ | < N , i.e. at least one node is not inserted.
Further, let ¯ s =
(ˆ ν 1 , ˆ X 1 , ˆ e +1 , ˆ e − 1 , ˆ E 1 ) , . .
, (ˆ ν K +1 , ˆ X K
+1 ,
ˆ e + K +1 ,
ˆ e − K +1 , ˆ E K +1 ) be the teaching signal returned by Algorithm 2 for mapping ψ , and let ¯ δ be the output of Algorithm 1 for input
¯ s .
Then, we wish to prove the following properties for ¯ δ .
¯ δ ( G ) ∼ = H .
| ¯ δ | ≤ | ¯ δ ψ | + 2 · ( C − 1) .
The ﬁrst K steps of ¯ s contain only insertions with ν k,i =
⇒ ν
k +1 ,i
= . . .
ν K +1 ,i = 0 .
The K + 1 th step contains no insertions.
K ≤ | Ins ψ | .
First, observe that lines 1-3 of Algorithm 2 are guaranteed to work because H is non-empty and thus at least one connected component exists, and that each connected component is per deﬁnition non-empty.
Further, line 4 works because we restricted ψ such that at least one i exists with ψ ( i ) ≤ N , which means that the minimum is well-deﬁned.
Accordingly, the graph ˜ H in line 5 is well-deﬁned as well.
This preparation was necessary to ensure that the shortest-path computations in lines 6-9 are valid.
In particular, assume that there exists some j ∈ Ins ψ such that j is disconnected in ˜ H from any node i / ∈
Ins ψ .
Now, distinguish two cases.
First, if j lies in a connected component of H which contains some node i with i / ∈
Ins ψ , then j is connected to i , which directly yields a contradiction.
Otherwise, j lies in one of the connected components C l .
Accordingly, j is connected to c l .
However, then j is also connected to ψ ( r ) in ˜ H by construction, where r / ∈
Ins ψ , which is also a contradiction.
Thus, the shortest path required in lines 6-9 is well-deﬁned.
Next, observe that any shortest path computation gives rise to shortest path trees as required by line 13.
If multiple shortest paths overlap, we obtain proper trees, otherwise trivial trees which are just copies of the shortest paths.
Lines 14 to 22 now insert all nodes in the shortest paths trees according to a particular ordering, namely that any parent is inserted at least one step before its child and each child is inserted one step before its right sibling.
By using this ordering we ensure that no node makes more than one insertion per step, that whenever a node stops to do insertions, it never needs to start again, and that all nodes are reached (because the depth-ﬁrst-search enumerates all nodes in the shortest path trees).
Accordingly, note that the K
ﬁrst steps of the generates script, when plugged into Algorithm 1, yield exactly the insertions in ¯ δ ins ψ as given in Deﬁnition 2 (up to reordering), in addition to edge insertions between an inserted node and its predecessor in the shortest paths tree.
These inserted edges are stored in E (cid:48)(cid:48) in line 23.
The remainder of the algorithm takes care of all remaining edits.
In particular, line 24 initializes a trivial teaching signal with zero node edit scores, zero attribute matrix, negative edge ﬁlter scores, and zero edit score matrix.
Then, line 25 sets all attributes to the target attributes, which yields all desired replacements of already existing nodes and leaves the attributes of inserted nodes as they were.
In other words, line 25 yields, via Algorithm 1, exactly the script ¯ δ rep ψ as given in Deﬁnition
Line 26 next sets edge insertion scores (cid:15) k,i,j = 1 for all edges ( i, j ) such that ( ψ ( i ) , ψ ( j )) is in E (cid:48) but not already in E ∪ E (cid:48)(cid:48) .
In effect, after line 26 we have accumulated all edge insertions in ¯ δ eins ψ as given in Deﬁnition 2, plus exactly L edge insertions eins r,ψ − 1 ( c l ) .
This is the case because the shortest path to any node c l is necessarily π c l 1 = r and π c l 2 = c l .
If any other, equally short path would exist, c l would be in a connected component with some node i / ∈
Ins ψ , which is a contradiction.
Accordingly, lines 14-22 have ensured that node r inserts node ψ − 1 ( c l ) at some point.
Next, line 27 sets edge deletion scores (cid:15) k,i,j = − 1 for all edges ( i, j ) that are in E ∪ E (cid:48)(cid:48) but where ( ψ ( i ) , ψ ( j )) is not in E (cid:48) anymore.
Note that there is no overlap between these edges and the edges considered in line 26, such that we can handle both cases within the same step.
Also note that this step yields all edge deletions from from ¯ δ edel ψ as given in Deﬁnition 2, plus exactly L edge deletions edel r,ψ − 1 ( c l ) due to our previous argument.
Finally, line 28 sets node edit scores ν i = − 1 for all nodes i with ψ ( i ) > N .
This yields exactly the node deletions from ¯ δ del ψ as given in Deﬁnition 2.
Lines 39-30 merely ensure that the edge ﬁlter scores are consistent with E k .
In summary, when we plug the teaching signal returned by Algorithm 2 into Algorithm 1, the resulting script ¯ δ contains exactly the same edits as ¯ δ ψ from Deﬁnition 2, up to reordering inserted nodes, plus L edge insertions eins r,ψ − 1 ( c l ) and L edge deletions edel r,ψ − 1 ( c l ) .
Because the edge deletions remove precisely the edges which have been additionally inserted before, we obtain ¯ δ ( G ) ∼ = ¯ δ ψ ( G ) .
Further, Lemma 1 shows that ¯ δ ψ ( G ) ∼ = H , which implies property 1 above.
Next, observe that L is exactly the number of connected components of H which are subsets of Ins ψ .
Because we required that ψ does not insert all nodes of H , there must exist each least one connected component of H which is not a subset of Ins ψ .
Accordingly, L is upper-bounded by C − 1 and we obtain the bound required in the second property.
For the third property, observe that the ﬁrst K steps do indeed only insert nodes.
Further, a node i only stops insertions when all its children in the shortest path tree are inserted.
Once that is done, it does not start inserting anymore, implying the desired property.
For the fourth property holds trivially by noting that lines 24-30 never set a node score to a value > 12 .
Finally, the ﬁfth property holds because each insertion step in lines 14-22 contains at least one insertion.
This is because K is set via line 20 exactly to a step in which the last insertion occurs and in insertion occuring in step K implies that either a left sibling insertion or the parent insertion had to occur in step K − 1 .
However, if at least one insertion occurs in each step, there can be at most
K ≤ | Ins ψ | steps, as claimed.
It only remains to show that the bounds in properties 2 and 5 are sharp.
To do so, consider the example graphs G = ( { 1 } , ∅ , 0 ) and
H =
, C } , ∅ , 0 ) .
Note that all nodes in H are isolated, such that they form trivial connected components.
We note in passing that it is also possible to construct an example for non-trivial connected components, e.g. by constructing H as C copies of G , where G can be arbitrarily shaped.
Here, we consider the simplest case.
Now, let ψ be any mapping between G and H such that | Ins ψ | < C .
In other words, ψ (1) ≤ C .
Then, line 2 of Algorithm 2 yields C l = { l } for l < ψ (1) , and C l = { l + 1 } for l ≥ ψ (1) with l ∈ { 1 , . .
, C − 1 } and c l becomes the only element of C l in line 3.
Line 4 yields r = 1 .
Accordingly, ˜
H =
, C } , { ( ψ (1) , c 1 ) , . . .
, ( ψ (1) , c C − 1 ) } , X (cid:48) ) .
Following the arguments above, the script resulting via Algorithm 1 from the output of Algorithm 2 then includes one edge insertion and one edge deletion for each edge in ˜ H , in addition to the C − 1 insertions that are contained in ¯ δ ψ .
Accordingly, we obtain | ¯ δ | = | ¯ δ ψ | + 2 · ( C − 1) , which is precisely the bound.
Further, becausehas to perform all the insertions, every step in lines 14-22 can only perform a single insertion, such that K = C − 1 = | Ins ψ | .
B A N EXAMPLE LOSS FUNCTION
For training, we propose a simple loss inspired by the margin hinge loss of the support vector machine (Suykens et al., 2002).
In more detail, let A be the adjacency matrix of the input graph, let (cid:126)ν, X ,(cid:126)e + ,(cid:126)e − , E be the GEN layer output, and let ˆ ν, ˆ X , ˆ e
+ , ˆ e − , ˆ E be the scores of our teaching signal.
Then, we deﬁne the loss (cid:96) GEN as:
[Equation]
where (cid:96) node ( ν, ˆ ν ) is deﬁned as [ ν + 1] 2+ for ˆ ν < − 12 , as [ − ν + 1] 2+ for ˆ ν > + 12 , and as [ | ν | − 14 ] 2+ otherwise, with [ x ] + = max { 0 , x } being the rectiﬁed linear unit; where (cid:96) ﬁlter ( e, ˆ e ) is deﬁned as
M · [ e + 12 ] 2+ if ˆ e ≤ 0 and as M · [ − e + 12 ] 2+ otherwise; where (cid:96) attr is the squared Euclidean distance for continuous attributes and crossentropy for discrete attributes; and where (cid:96) edge ( (cid:15), ˆ (cid:15), a ) is deﬁned as [ (cid:15) + 1] 2+ if a = 1 and ˆ (cid:15) <
− 12 , as [ − (cid:15) ]
2+ if a = 1 and ˆ (cid:15) ≥ − 12 , as [ (cid:15) ]
2+ if a = 0 and ˆ (cid:15) ≤ 12 , and as [ − (cid:15) + 1] 2 if a = 0 and ˆ (cid:15) > 12 .
We can show that this loss is zero if and only if the scripts of the teaching signal and the GEN output are equal (plus a loss for margin violations).
Theorem 3.
Let A ∈ { 0 , 1 } N × N be an adjacency matrix and (cid:126)ν, X ,(cid:126)e + ,(cid:126)e − , E as well as ˆ ν, ˆ X , ˆ e
+ , ˆ e − , ˆ E be two sets of edit scores.
Then, loss 2 is zero if and only if the following conditions hold.
For all i : If ˆ ν i > + 12 , ν i is at least 1 , 2.
for all i : if | ˆ ν i | ≤ 12 , | ν i | is at most 14 , 3.
for all i : if ˆ ν i < − 12 , ν i is at most − 1 , 4.
for all i
If ˆ ν i ≥ − 12 , (cid:96) attr ( (cid:126)x i , ˆ x i )
= 0 , 5.
for all i : If ˆ e + i > 0 , e + i is at least 12 , 6.
for all i : If ˆ e + i ≤ 0 , e + i is at most − 12 , 7.
for all i : If ˆ e − i > 0 , e − i is at least 12 , 8.
for all i : If ˆ e − i ≤ 0 , e − i is at most − 12 , 9.
for all i, j : If ˆ e + i > 0 , ˆ e − j > 0 , ˆ (cid:15) i,j > + 12 , and a i,j = 0 , (cid:15) i,j is at least 1 , 10.
for all i, j : If ˆ e + i > 0 , ˆ e − j > 0 , ˆ (cid:15) i,j ≤ 12 , and a i,j = 0 , (cid:15) i,j is at most 0 , 11.
for all i, j : If ˆ e + i > 0 , ˆ e − j > 0 , ˆ (cid:15) i,j ≥ − 12 , and a i,j = 1 , (cid:15) i,j is at least 0 , and 12.
for all i, j : If ˆ e + i > 0 , ˆ e − j > 0 , ˆ (cid:15) i,j < − 12 , and a i,j = 1 , (cid:15) i,j is at most − 1 .
Proof.
We ﬁrst re-frame all conditions in terms of the component losses (cid:96) node , (cid:96) attr , (cid:96) ﬁlter , and (cid:96) edge .
In this case, the node loss is (cid:96) node ( ν i , ˆ ν i ) = (cid:2) − ν
i + 1 (cid:3) 2 + .
Accordingly, the loss is zero iff − ν i + 1 ≤ 0 ⇐⇒ ν
i ≥ 1 , as claimed.
In this case, the node loss is (cid:96) node ( ν i , ˆ ν i ) = (cid:2) | ν i | − 14 (cid:3) 2 + .
Accordingly, the loss is zero iff | ν i | − 14 ≤ 0 ⇐⇒ | ν i | ≤ 14 , as claimed.
In this case, the node loss is (cid:96) node ( ν i , ˆ ν i ) = (cid:2)
ν i + 1 (cid:3) 2 + .
Accordingly, the loss is zero iff ν i + 1 ≤ 0 ⇐⇒ ν
i ≤ − 1 , as claimed.
This condition directly refers to the attribute loss and is obvious.
In this case, the ﬁlter loss is (cid:96) ﬁlter ( e + i , ˆ e + i ) = (cid:2) − e
+ i + 12 (cid:3) 2 + .
Accordingly, the loss is zero iff − e
+ i + 12 ≤ 0 ⇐⇒ e
+ i ≥ 12 , as claimed.
In this case, the ﬁlter loss is (cid:96) ﬁlter ( e + i , ˆ e + i ) = (cid:2) e
+ i + 12 (cid:3) 2 + .
Accordingly, the loss is zero iff e + i + 12 ≤ 0 ⇐⇒ e + i ≤ − 12 , as claimed.
In this case, the ﬁlter loss is (cid:96) ﬁlter ( e − i , ˆ e − i ) = (cid:2) − e − i + 12 (cid:3) 2 + .
Accordingly, the loss is zero iff − e − i + 12 ≤ 0 ⇐⇒ e − i ≥ 12 , as claimed.
In this case, the ﬁlter loss is (cid:96) ﬁlter ( e − i , ˆ e − i ) = (cid:2) e − i + 12 (cid:3) 2 + .
Accordingly, the loss is zero iff e − i + 12 ≤ 0 ⇐⇒ e − i ≤ − 12 , as claimed.
In this case, the edge loss is (cid:96) edge ( (cid:15) i,j , ˆ (cid:15)
i,j , a i,j ) = (cid:2) − (cid:15) i,j + 1 (cid:3) 2 + .
Accordingly, the loss is zero iff − (cid:15) i,j + 1 ≤ 0 ⇐⇒ (cid:15) i,j ≥ 1 , as claimed.
In this case, the edge loss is (cid:96) edge ( (cid:15) i,j , ˆ (cid:15)
i,j , a i,j ) = (cid:2) (cid:15) i,j (cid:3) 2 + .
Accordingly, the loss is zero iff (cid:15) i,j ≤ 0 , as claimed.
In this case, the edge loss is (cid:96) edge ( (cid:15) i,j , ˆ (cid:15)
i,j , a i,j ) = (cid:2) − (cid:15) i,j (cid:3) 2 + .
Accordingly, the loss is zero iff − (cid:15) i,j ≤ 0 ⇐⇒ (cid:15) i,j ≥ 0 , as claimed.
In this case, the edge loss is (cid:96) edge ( (cid:15) i,j , ˆ (cid:15)
i,j , a i,j ) = (cid:2) (cid:15) i,j + 1 (cid:3) 2 + .
Accordingly, the loss is zero iff (cid:15) i,j + 1 ≤ 0 ⇐⇒ (cid:15) i,j ≤ − 1 , as claimed.
Accordingly, we found that all component losses are zero if and only if the aforementioned margin conditions holds.
Since the entire loss 2 is a sum of these component losses and no contribution can be negative in this case, the entire sum is zero if and only if all contributions are zero, which proves the claim.
Also refer to Figure 5 for a graphical illustration of the component losses (cid:96) node and (cid:96) edge .
This directly yields the second part of Theorem 3.
The ﬁrst claim we obtain as a direct consequence of our margin conditions.
In particular, if conditions 5-8 hold, the loops in lines 3-8 of Algorithmiterate over the same elements ( i, j ) .
Further, due to conditions 11-12, Algorithm 1 appends the same edge deletions in line 5, and due to conditions 9-10, Algorithm 1 appends the same edge insertions in line 6.
The replacements in line 9 are the same due to conditions 2 and 4, as well as the fact that (cid:96) attr being zero implies equal inputs by deﬁnition.
The loop in lines 11-14 now iterates over the same elements due to condition 1, and the same node/edge insertions are appended in line 12 due to condition 4 and the fact that (cid:96) attr being zero implies equal inputs by deﬁnition.
Finally, the same node deletions are generated in line 15 due to condition 3.
Thus, the output of Algorithm 1 is the same for both inputs.
Also note that we used all conditions, such that the condition set is minimal.
[Figure]
p (ins | ν ) p (del | ν )
[Figure]
(rep | ν ) − 1 − 0 . 0 .
ν l o ss ˆ ν =
+
ˆ ν = −ˆ ν =
Further note the similarity to the least-squares support vector machine loss (Suykens et al., 2002) which can be written as
[Equation]
where ˆ y ∈ {− 1 , 1 } is the desired label and
y =
(cid:126)w T · (cid:126)x is the predicted label.
This mirrors the terms in our loss 2.
C P ROBABILISTIC I NTERPRETATION OF THE GEN
Given the node edit scores ν i , the edge ﬁlter scores e + i and e − i as well as the edge edit scores (cid:15) i,j as returned by a GEN layer, we can deﬁne the following probabilities over edits.
The probability of a node insertion at node i is the logistic distribution p (ins | ν i ) =
Z β / (1 + exp[ − β · ( ν i − 12 )]) ; the probability of a deletion of node i is the logistic distribution p (del | ν i ) =
Z β / (1+exp[ − β · ( − ν
i − 12 )]) ; and the probability of a replacement is p (rep | ν i )
= 1 − p (ins | ν i ) − p (del | ν i ) .
In all cases, β > 0 is a hyper-parameter regulating the slope of the distribution with respect to ν i and Z β =
(1+ e β ) /
(2+ e β ) is chosen to ensure that p (ins | 12 ) =
p (rep | 12 ) = p (del | − 12 ) =
p (rep | − 12 ) , i.e. 12 is the decision boundary between insertion and replacement and − 12 is the decision boundary between deletion and replacement, just as in Algorithm 1.
For sufﬁciently high β , e.g. β ≥ 10 , we obtain p (ins | ν i ) ≈for ν
i < 0 and p (del | ν i )
≈
for ν i > 0 , such that the distribution becomes equivalent to two binary logistic distributions ’glued together’.
Also refer to Figure 6 (left).
A straightforward loss based on this probability distribution is the crossentropy between p and the strict teaching distribution q (ins | ˆ ν i )
=
if ˆ ν i > 12 , q (del | ˆ ν i ) if ˆ ν i < − 12 , and q (rep | ˆ ν i )
=otherwise.
The loss for varying ν and ˆ ν and β = 10 is shown in Figure 6 (right).
As we can see, the behavior is qualitatively very similar to the GEN loss from Equation 2, shown in dashed lines.
The most noteable differences are that the crossentropy behaves linearly for sufﬁciently extreme ν , whereas the GEN loss behaves quadratic, and that the GEN loss is strictly zero when the margin is not violated, whereas the crossentropy still remains strictly larger than zero.
This can lead to empiric problems during learning, as we see in the experiments.
The quadratic behavior emphasizes large margin violations whereas small margin violations are less emphasized compared to the crossentropy loss, which yields slightly favorable properties in our experiments.
To sample edge edits we perform a three-step process.
First, for each node we sample whether outgoing edges or incoming edges are edited with the logistic distribution p ( (cid:62)| e + i )
=
1 / (1 + exp
[ − β · e + i ]) and p ( (cid:62)| e − i )
=
1 / (1 + exp[ − β · e − i ]) .
Then, we only consider edges ( i, j ) where (cid:62) has been sampled for both i and j , and we sample an edge insertion with probability p (eins | (cid:15) i,j )
= 1 / (1 + exp
− β · ( (cid:15) i,j − 12 )]) if a i,j = 0 and p (eins | (cid:15) i,j ) =
if a i,j = 1 , and we sample an egde deletion with probability p (edel | (cid:15) i,j ) = 1 / (1+exp[ − β · ( − (cid:15) i,j − 12 )]) if a i,j = 1 and p (eins | (cid:15) i,j ) =if a i,j = 0 .
Also refer to Figure 7 (left).
The crossentropy loss compared to the strict distribution q (eins | ˆ (cid:15) i,j ) =
if ˆ (cid:15) i,j > 12 , q (edel | ˆ (cid:15) i,j ) =
if ˆ (cid:15) i,j < − 1 2 , and q (eins | ˆ (cid:15) i,j ) =
q (edel | ˆ (cid:15) i,j )
= 0 is shown in Figure 7 (right).
Again, we observe
− 1 − 0 .
(cid:15) p ( e i n s | (cid:15) ) a =− 1 − 0 .
(cid:15) l o ss a =ˆ (cid:15) =
+ ˆ (cid:15) =
− 1 − 0 .
(cid:15) p ( e d e l | (cid:15) )
a =− 1 − 0 . 0 .
(cid:15) l o ss a =ˆ (cid:15) =
+ ˆ (cid:15) = that the loss behaves qualitatively very similar to the GEN edge loss, with the striking difference being the square.
[Table]
D D ATA IN DETAIL
In this section, we discuss the graph dynamical systems of Section 4 in more detail and also discuss how graph edit networks can realize a solution.
The summary statistics are shown in Table 2.
Edit Cycles:
The edit cycles data set is illustrated in Figure 8.
Colored, thick arrows indicate the simulated system dynamics.
Each arrow is labelled with the corresponding teaching protocol.
The reference solution to this task is to uniquely identify at each node to which graph it belongs and then decide on the edit.
This requires a number of layers equal to the graph diameter, in this case two graph neural network layers.
Degree Rules: The degree rules data set is illustrated for two example graphs in Figure 2.
The teaching protocol implements the rules of the data set as follows.
First, for any node i with degree larger than 3 we expect ˆ ν i < − 12 , i.e. the node should get deleted.
Second, for any pair of nodes i and j which share at least one neighbor, we expect ˆ (cid:15) i,j = ˆ (cid:15)
j,i = 1 , i.e. an edge should be inserted between the nodes.
Third, for any node i with degree smaller than 3 we expect ˆ
ν i > 12 , i.e. a node should get inserted.
To generate the actual dynamics we limit the process to apply only one rule per connected component to avoid degeneracies (for example, for simultaneous execution, a 5 -clique would be deleted entirely).
In particular, we ﬁrst apply rule 1 to the node with highest degree.
If rule 1 applies to no node, we apply rule 2 to the node pair with lowest degree.
If rule 2 does not apply, we apply rule 3 to the node with lowest degree.
If multiple nodes have the same degree, nodes with lower index take precedence.
If no rule applies, we perform no edit and the process has converged.
It is easy to show that each connected component converges to a 4 -clique in this scheme.
To see this, consider that rule 2 ensures that every connected component becomes fully connected, provided that rule 1 does not interfere.
Rule 1 interferes if a node degree rises above 3, which will be the case whenever a connected component contains more than 4 nodes.
Accordingly, every connected component with more than 4 nodes must converge to a 4 -clique.
For smaller connected components, rule 3 kicks in once rule 2 has fully connected the existing component, which raises the number of nodes in the component until we obtain a 4 -clique as well.
Further, a 4 -clique is the only graph which is stable under our rules, such that the system stops.
The reference solution for this task is to use n + 2 neurons in one layer as follows.
Recall that each node’s initial representation is a one-hot vector representing the node index.
Accordingly, we can represent a set of neighbors for each node by adding all neighboring one-hot codes, i.e.
(cid:126)φ ( i ) 1: n = ReLU( (cid:80) ( j,i )
∈ E (cid:126)x j ) , where (cid:126)x j is the one-hot coding vector for node j , and where 1 : n denotes a subselection of the ﬁrst n dimensions of a vector.
This function can be implemented via
Equation ??
by setting U 1: n, : =
I , V 1: n, : = W 1: n, : = 0 , and (cid:126)b 1: n = (cid:126) 0 .
Next, we can compute the degree of node i via the formula (cid:80) ( j,i )
∈ E (cid:126) 1 T · (cid:126)x j and the need for applying rule 1 or 3 respectively via the two formulae
[Equation]
Note that a positive value is obtained if the degree is larger than 3 or 2 respectively.
We can achieve this representation by setting U n +1 , : = (cid:126) 1 , U n +2 , : = − (cid:126) 1 , V = W = 0 , b n +1 = − 3 . 5 , and b n +2 = 2 . 5 .
Next, note that rule 2 is almost obtained for (cid:126)u edge = (cid:126)v edge =
(cid:126) 0 and w edge = 1 because the inner product of the ﬁrst n dimensions of (cid:126)φ ( i ) and (cid:126)φ ( j ) computes the set intersection of the neighbors of node i and node j .
However, our last two dimensions interfere with this plan.
Fortunately, we can circumvent this issue by multiplying all parameters in the last two dimensions with some small number 1 β for β (cid:29) 1 and setting (cid:126)w node: n = (cid:126) 0 , w node n +1 = − 2 · β , and w node n +2 = 2 · β .
Accordingly, we obtain, (cid:126) φ ( i ) T · (cid:126) φ ( j )
≈ (cid:126) φ 1: n ( i ) T · (cid:126) φ 1: n ( j ) ≥ 1 if i and j share a neighbor and 0 otherwise, as well as ν i = − β · φ ( i ) n +1 + β · φ ( i ) n +2 ≤ − 1 if the degree of node i is larger than 3, ≥ 1 if the degree if node i is smaller than 3, and 0 otherwise.
Note that this is difﬁcult to learn for a neural net because it requires to set parameters to rather extreme values.
Hence the long experimental learning times.
Game of life: Conway’s game of life is a 2D cellular automaton with the following rules.
Cells can be either alive ( x ti = 1 ) or dead ( x ti = 0 ) at time t .
The state in time t + 1 is given by the equation
[Equation]
0 otherwise where E contains bidirectional edges between a cell and its 8 -neighborhood in the grid.
Figureshows the development of an example grid.
Our teaching protocol imposes ˆ
ν ti = x
t +1 i − x ti for all nodes i and all times t ≥ 1 , i.e. the node edit score ν ti should model the change in ’aliveness’.
This is easy to implement in a GEN with a single layer, sigmoid nonlinearity, and three neurons, by setting the parameters U = β · (2 , 2 , 0) T , V = (0 , 0 , 0) T , W = β · (1 , 1 , 1) T , (cid:126) b
= β · ( − 4 .
5 , − 7 . 5 , − 0 .
5) T for β (cid:29) 1 , and (cid:126)w node =
(1 , − 1 , − 1) T , which yields:
[Equation]
where 1 is the indicator function.
Boolean Formulae: We ﬁrst generate a random Boolean formula using the following stochastic process: Let Σ = {∧ , ∨ , x, y, ¬ x, ¬ y, (cid:62) , ⊥ , root } be our alphabet of symbols.
Then, we initialize a counter ops ← 0 , a graph G =
( { 1 } , ∅ , X ) with (cid:126)x 1 = root , and a stack with 1 as single element.
Next, as long as the stack is not empty, we pop the top node i from the stack and sample a new symbol from Σ with probabilities P ( ∧ ) =
P ( ∨ ) = 0 .
3 , P ( x ) =
P ( y ) =
P ( ¬ x ) = P ( ¬ y )
= 0 .
1 , and P (root) =
P ( (cid:62) )
=
P ( ⊥ )
= 0 .
Then, we add a new node M + 1 to the graph with (cid:126)x M +1 being the one-hot-code of the samples symbol, and add the edge ( i, M + 1) .
Further, if we have sampled ∧ or ∨ , we push i onto the stack two times and increment the ops counter.
If it reaches 3 , we adjust the sampling probabilities to P ( x ) =
P ( y ) =
P ( ¬ x ) = P ( ¬ y )
= 14 and P ( ∧ ) =
P ( ∨ ) = P (root)
=
P ( (cid:62) )
=
P ( ⊥ )
= 0 .
Once the initial graph is sampled, the teaching protocol implements eight simpliﬁcation rules for
Boolean formulae.
In particular, we implement the following rules.
F ∧ ⊥ ⇐⇒ ⊥ for any formula F .
Accordingly, if for two nodes i, j we have (cid:126)x i = ∧ , (cid:126)x j = ⊥ and ( i, j
) ∈ E , we impose ˆ
ν
i = − 1 and ˆ ν k
= − 1 for any node k (cid:54) =
j with ( i, k ) ∈ E .
As a minor side note, we mention that we consider tree edits according to Zhang & Shasha (1989) for this data set instead of graph edits, in which case the children of any deleted node are connected to its parent.
Accordingly, we do not delete i as long as i still has grandchildren.
F ∧ (cid:62) ⇐⇒ F for any F .
Accordingly, if for two nodes i, j we have (cid:126)x i = ∧ , (cid:126)x j = (cid:62) and ( i, j
) ∈ E , we impose ˆ ν i
= ˆ ν j = − 1 . 3.
F ∨ (cid:62) ⇐⇒ (cid:62) for any F .
Accordingly, we apply the same scheme as in rule 1, just with the condition (cid:126)x i = ∨ and (cid:126)x j = (cid:62) .
F ∨ ⊥ ⇐⇒ F for any F .
Accordingly, if for two nodes i, j we have (cid:126)x i = ∨ , (cid:126)x j = ⊥ and ( i, j
) ∈ E , we impose ˆ ν i
= ˆ ν j = − 1 .
x ∧ x ⇐⇒ x and y ∧
y ⇐⇒
y .
Accordingly, if we ﬁnd three nodes i, j, k , such that (cid:126)x i = ∧ , (cid:126)x j = (cid:126)x k ∈ { x, y } , and ( i, j ) , ( i, k ) ∈ E , we impose ˆ
ν i
= ˆ ν j = − 1 . 6.
x ∨ x ⇐⇒ x
and y ∨ y ⇐⇒
y .
Accordingly, if we ﬁnd three nodes i, j, k , such that (cid:126)x i = ∨ , (cid:126)x j = (cid:126)x k ∈ { x, y } , and ( i, j ) , ( i, k ) ∈ E , we impose ˆ
ν i
= ˆ ν j = − 1 .
x ∧ ¬ x ⇐⇒ ⊥ and y ∧ ¬ y ⇐⇒ ⊥ y .
Accordingly, if we ﬁnd three nodes i, j, k , such that (cid:126)x i = ∧ , ( i, j ) , ( i, k ) ∈ E , and (cid:126)x j = x as well as (cid:126)x k = ¬ x , or (cid:126)x j = y as well as (cid:126)x k = ¬
y , we impose ˆ ν j = ˆ ν k
= − 1 and (cid:126)x i coding the ⊥ symbol in one-hot coding.
x ∨ ¬ x ⇐⇒ (cid:62) and y ∨ ¬ y ⇐⇒ (cid:62) .
Accordingly, if we ﬁnd three nodes i, j, k , such that (cid:126)x i = ∨ , ( i, j ) , ( i, k ) ∈ E , and (cid:126)x j = x as well as (cid:126)x k = ¬ x , or (cid:126)x j = y as well as (cid:126)x k = ¬
y , we impose ˆ ν j = ˆ ν k
= − 1 and (cid:126)x i coding the (cid:62) symbol in one-hot coding.
The next step in the dynamic is the graph that results from applying all edits imposed by the teaching protocol.
The dynamic process ends once no rules apply anymore.
An example simpliﬁcation process is shown in Figure 10.
The reference solution for all rules is structurally similar, such that we only discuss the implementation of rule 2 here for simplicity.
In particular, let (cid:126)x i be the one-hot code of the symbol at the i th node and set φ 0 ( i ) =
(cid:126)x i for all nodes.
Then, we can implement rule 2 with a single-layer GEN with two neurons, which is parametrized as
[Equation]
[Figure]
as well as (cid:126)w node = − (1 , 1) , and b node = 0 , where β > 1 is a hyper-parameter.
Accordingly, we obtain
[Equation]
which, for sigmoid σ and sufﬁciently high β is − 1 if (cid:126)x i =
∧
and i has a (cid:62) node as child, or if (cid:126)x i = (cid:62) and i has a (cid:62) node as parent, and 0 otherwise, as required.
Peano addition:
With the same scheme as for the Boolean data set we ﬁrst generate a random addition with at most 3 plus operators.
Just in this case we have the alphabet Σ
= { + , 0 , 1 , . .
, 9 , succ , root } and the sampling probabilities P (+)
= 12 and P (1)
= . . .
= P (9) = 118 , which are changed to P (1)
= . . .
= P (9) = 19 once 3 plus operators are generated.
Once the initial graph is generated, we apply Peano’s addition axiom until the addition is resolved.
In more detail, we apply the following rules.
F + 0 = F for any formula F .
Accordingly, if we ﬁnd two nodes i, j with (cid:126)x i = + and (cid:126)x j = 0 such that j is the second child of i , we impose ˆ
ν i
= ˆ ν j = − 1 .
F + succ( G ) =
succ( F ) + G for any formulae F and G .
Accordingly, if we ﬁnd two nodes i, j with (cid:126)x i = + and (cid:126)x j = succ such that j is the second child of i , we impose ˆ ν i
= +1 , (cid:126)x i = succ in one-hot coding, and ˆ ν k = − 1 .
Again, notice that we use tree edits (Zhang & Shasha, 1989) instead of graph edits in this case, such that an insertion at node i automatically establishes an edge between i and the newly inserted node as well as between the newly inserted node and the ﬁrst child of i , while cutting the direct connection between i and its ﬁrst child, i.e. the new child is inserted in between i and its current ﬁrst child.
F + n = F + succ( n − 1) for any number n ∈ { 1 , . .
Accordingly, if we ﬁnd two nodes i, j with (cid:126)x i = + and (cid:126)x j ∈ { 1 , . .
, 9 } , such that j is the second child of i , we impose ˆ
ν
i = +1 , (cid:126)x i = succ in one-hot coding, and (cid:126)x j = n − 1 in one-hot coding.
succ( n ) = n + 1 for any number n ∈ { 0 , . .
, 9 } If n = 9 , we deﬁne n + 1 = 0 to remain in the alphabet.
Accordingly, if we ﬁnd two nodes i, j with (cid:126)x i = succ , (cid:126)x j ∈ { 0 , . .
, 9 } , and ( i, j
) ∈ E , we impose ν i = − 1 and (cid:126)x j = n + 1 in one-hot coding.
The next step in the dynamic is the graph that results from applying all edits imposed by the teaching protocol.
The dynamic process ends once no rules apply anymore.
An example time series is shown in Figure 11.
The reference solution works similar as for the Boolean data set.
As an example, we show here how rule 2 can be realized by a two-layer GEN with two neurons in each layer.
More speciﬁcally, let φ ( x )
[Equation]
rule
[Equation]
rule
[Equation]
rule
[Equation]
be the one-hot coding of symbol x ∈ Σ and let the features φ
( i ) for each node be its one-hot coding concatenated with a feature that is 1 if i is the second child of its parent.
Then, we can parametrize the GEN as follows.
[Equation]
where β > 1 is a hyperparameter.
Accordingly
[Equation]
the ﬁrst layer computes the following features.
[Equation]
For sufﬁciently high β and sigmoid nonlinearity, the ﬁrst feature is ≈ 1 if i is labeled with + (otherwise, the feature is ≈ 0 ), whereas the second feature is ≈ 1 if i is labeled with succ and is the second child of its parent (otherwise, the feature is ≈ 0 ).
In turn, the features in the second layer resolve to:
[Equation]
For sufﬁciently high β and sigmoid nonlinearity, the ﬁrst feature is ≈ 1 if i is labelled with + and has a second child that is labeled succ (otherwise, the feature is ≈ 0 ), whereas the second feature is ≈ 1 if i is labeled with succ and is the second child of a parent that is labelled with + (otherwise, the feature is ≈ 0 ).
Accordingly, ν i
[Equation]
+1 if the ﬁrst feature is 1 , − 1 if the second feature is 1 , and 0 otherwise, which exactly implements rule 2.
[Table]
E A DDITIONAL E XPERIMENTS ON S YNTAX T REES
We additionally evaluated graph edit networks on six data sets of Python syntax trees, where students iteratively solve a Python programming task, in particular implementing the mathematical function f ( x ) =
x 4 − x 2 + x 4 in Python (fun), plotting the function (plt), implementing its gradient (grad), implementing gradient descent on it (desc), and ﬁnding optimal starting values (ﬁn), as well as writing a sorting program (pysort).
While the latter data set is synthetic, the former ﬁve are recordings of ﬁfteen students.
In all cases, our task is to predict the next state of the student’s program, represented by its abstract syntax tree.
For all data sets we used a graph edit network with four layers,neurons per layer, residual connections, and tanh nonlinearity, which we optimized using Adam with a learning rate of 10 − 3 and weight decay of 10 − 3 for 10 k epochs.
In each epoch we computed the loss for one randomly sampled time series.
To obtain statistics we performed a 5 -fold crossvalidation on all datasets.
Table 3 shows the average root mean square tree edit distance between the predicted tree and the actual next syntax tree on all data sets, for graph edit networks (GENs, last row), as well as two baselines, namely the constant prediction (const.), i.e. predicting no change, and the Gaussian process scheme (GP) of Paaßen et al.
We observe that both the synthetic syntax trees as well as the actual student data are hard to predict, as neither GP nor GEN outperforms the constant baseline.
Further, we observe that GEN performs slightly better than GP on plt, grad, and desc, clearly better on pysort (by more than four standard deviations) and slightly worse on fun and ﬁn.
Overall, we can not observe a clear advantage of GEN on these data in terms of RMSE, which is likely due to the small set of training data (only 15 different time series).
Still, in terms of inference time GENs (below 100 ms on all datasets) clearly outperform the expensive kernel-to-tree translation approach of Paaßen et al.
(2018) (ranging from below 100 ms to over 2 minutes per prediction on pysort).
F P ROMOTING SHORTER EDIT PATHS IN GEN’ S TRAINING
Denote with C (del) , C (ins) , C (edel) and C (eins) the edit costs associated with node deletion, node insertion, edge deletion and edge insertion.
Deﬁne
[Equation] [Equation]
where (cid:126) 1 , 1 are a n -dimensional vector and n × n matrix of all ones.
Assuming the edge and node scores have been passed through a squashing function in (0, 1), then adding term (cid:96) sp to the GEN’s training loss will penalize costly edit paths, hence promoting shorter ones.
The total cost derived by constructing edits in E is, in fact, given by
[Equation]
We can rewrite it in matrix form.
Deﬁne for convenience
[Equation]
where the operators > and < are applied component wise and return 1 if "true" and 0 if "false".
The matrix form becomes
[Equation]
where (cid:12) is the element-wise product.
Conversely, the cost associated with vector (cid:126)ν is n (cid:88)
[Equation]
Assuming that both edge and node scores are bounded by 1, adding the following term to the loss will promote shorter edit path
[Equation] [Table]