Abstract
Among various distance functions for graphs, graph and subgraph edit distances (GED and SED respectively) are two of the most popular and expressive measures. Unfortunately, exact computations for both are NP-hard. To overcome this computational bottleneck, neural approaches to learn and predict edit distance in polynomial time have received much interest. While considerable progress has been made, there exist limitations that need to be addressed. First, the efficacy of an approximate distance function lies not only in its approximation accuracy, but also in the preservation of its properties. To elaborate, although GED is a metric, its neural approximations do not provide such a guarantee. This prohibits their usage in higher order tasks that rely on metric distance functions, such as clustering or indexing. Second, several existing frameworks for GED do not extend to SED due to SED being asymmetric. In this work, we design a novel siamese graph neural network called GREED, which through a carefully crafted inductive bias, learns GED and SED in a property-preserving manner. Through extensive experiments across 10 real graph datasets containing up to 7 million edges, we establish that GREED is not only more accurate than the state of the art, but also up to 3 orders of magnitude faster. Even more significantly, due to preserving the triangle inequality, the generated embeddings are indexable and consequently, even in a CPU-only environment, GREED is up to 50 times faster than GPU-powered baselines for graph / subgraph retrieval.
Introduction and Problem Statement
Graph Edit Distance (GED) and Subgraph Edit Distance (SED) are fundamental metrics for comparing graphs, essential for tasks like finding similar molecules in a database or identifying functional motifs in a protein network. However, computing these distances exactly is an NP-hard problem, meaning it scales poorly as graphs grow in size and complexity.
Existing neural approximations, while faster, often suffer from three major flaws:
- Loss of Metric Properties: They do not guarantee the triangle inequality, which prevents the use of efficient database indexing structures like metric trees.
- Pair-Dependent Embeddings: Many models require both graphs to be processed together to compute a distance, making offline pre-computation of a database impossible.
- Ignoring Asymmetry: SED is inherently asymmetric (Graph A can be a subgraph of B, but not vice versa), yet most neural GED frameworks assume symmetry and cannot be easily adapted.
The GREED Framework
To address these limitations, we introduce GREED (GRaph Embeddings for Edit Distances). GREED utilizes a Siamese Graph Isomorphism Network (GIN) to generate pair-independent embeddings. This allows each graph to be embedded into a vector space independently, enabling the offline processing and storage of database graph embeddings.
The core innovation of GREED lies in its carefully crafted inductive biases. Instead of using a generic Multi-Layer Perceptron (MLP) to predict distances, GREED employs specific mathematical functions designed to enforce metric properties:
- For GED: It uses the $L_2$ norm (Euclidean distance) between the two embeddings.
- For SED: It uses a custom ReLU-based norm: $||ReLU(Z_{Query} - Z_{Target})||_2$. This captures asymmetry by only penalizing features present in the query graph that are missing in the target graph.
Because these prediction functions mathematically guarantee the triangle inequality, the resulting embeddings are indexable. For massive target graphs, GREED employs a "neighborhood decomposition" strategy, breaking large graphs into overlapping $k$-hop neighborhoods and indexing them individually.
Experimental Evaluation
GREED was evaluated across 10 real-world graph datasets, including million-scale graphs such as Dblp (7.2M edges) and Amazon. This marks the first study to evaluate neural graph distance approaches at such a scale.
Key experimental results include:
- Accuracy: GREED outperformed state-of-the-art neural baselines (e.g., $H^2MN$, SimGNN) in 9 out of 10 settings for both GED and SED, as measured by Root Mean Square Error (RMSE).
- Efficiency: GREED is up to 1800x faster than non-neural exact solvers and 10-20x faster than the best neural baselines in raw inference time.
- Scalability: By utilizing indexable embeddings, GREED running on a CPU is approximately 50x faster than GPU-powered baselines for retrieval tasks. When both use GPUs, GREED is over 1000x faster.
Conclusion
By integrating strict mathematical distance metrics into a deep learning framework, GREED achieves a superior balance of accuracy and computational efficiency. While the model faces challenges in generalizing to query sizes significantly larger than those seen during training, its ability to provide indexable, property-preserving embeddings represents a significant advancement for large-scale graph similarity search.
Summary updated