GREED: A Neural Framework for Learning Graph Distance Functions

Rishabh Ranjan, Siddharth Grover, Sourav Medya, Venkatesan T. Chakaravarthy, Yogish Sabharwal, Sayan Ranu

TL;DR

GREED (GRaph Embeddings for Edit Distances) is a neural framework that learns to predict graph and subgraph similarity while strictly preserving essential geometric properties like the triangle inequality. By shifting from "pair-dependent" computations to "pair-independent" embeddings, GREED enables efficient indexing, allowing a standard CPU to outperform GPU-powered state-of-the-art models by up to 50x in retrieval speed.

The Challenge of Graph Similarity

Measuring the similarity between two graphs is a cornerstone of tasks like drug discovery (finding similar molecules) and social network analysis. The gold standards for this are Graph Edit Distance (GED)—the cost to transform one graph into another—and Subgraph Edit Distance (SED)—the cost to make one graph a subgraph of another.

Graph mapping illustrating the edit distance between two graphs.

The catch? Both are NP-hard to compute exactly. While researchers have turned to Graph Neural Networks (GNNs) to approximate these distances quickly, existing models suffer from three major flaws:

  1. Lack of Mathematical Rigor: They don't guarantee metric properties (like the triangle inequality). This means you cannot use them for reliable clustering or efficient searching.
  2. The "Pair-Dependent" Bottleneck: Most models require both graphs as input simultaneously to predict a distance. If you have a database of a million graphs, you have to run the neural network a million times for every single query to build a distance matrix.
A Graph Edit Distance (GED) matrix showing pairwise distances.
  1. Asymmetry: SED is inherently asymmetric (Graph A being a subgraph of B is not the same as B being a subgraph of A), a property most symmetric GNN architectures struggle to model.

The GREED Architecture

The authors introduce GREED, a Siamese GNN architecture designed with a specific "inductive bias" to solve these issues.

  • Siamese GIN: It uses a shared Graph Isomorphism Network (GIN) to embed each graph into a vector space independently. Because the embedding of a graph doesn't depend on what it's being compared to, these vectors can be pre-computed and stored.
  • Property-Preserving Distance Functions: Instead of using a "black box" Multi-Layer Perceptron (MLP) to predict distance from embeddings, GREED uses specific mathematical forms:
  • For GED: It uses the $L_2$ norm (Euclidean distance). This ensures the learned space is a true metric space.
  • For SED: It uses a novel ReLU-based distance: $F_s(z_Q, z_T) = \|\text{ReLU}(z_Q - z_T)\|_2$. This clever trick captures asymmetry—it only penalizes features present in the query ($z_Q$) that are missing in the target ($z_T$), while ignoring "extra" features in the target.
  • Indexing: Because the embeddings satisfy the triangle inequality, the authors can use traditional metric tree indexes (like M-trees). This allows the system to prune the search space and find similar graphs without checking every single entry in the database.

Key Insights and Ideas

  • Structure over Complexity: The "aha moment" of this research is that forcing a neural network to obey geometric constraints (like the triangle inequality) actually makes it better at learning, especially when training data is scarce.
  • ReLU as a Subgraph Filter: Using ReLU in the distance function is a brilliant way to model the "one-way" nature of subgraph isomorphism. It mathematically represents the idea that "having more than enough" is fine, but "having less than required" is a penalty.
  • CPU > GPU (Sometimes): By making embeddings indexable, the authors prove that algorithmic efficiency (sub-linear search) can beat raw hardware power (brute-force GPU parallelization).

Key Results

The researchers evaluated GREED across 10 diverse real-world datasets, ranging from standard graph databases (AIDS', Linux, IMDB) to large single graphs representing "million-scale" challenges (Dblp, Amazon, PubMed, CiteSeer, Cora_ML, Protein).

  • Accuracy: GREED outperformed state-of-the-art neural models (like H2MN and SimGNN) in 9 out of 10 experimental settings, often by significant margins.
  • Raw Speed: In terms of simple inference (predicting distance for a pair), GREED is up to 3 orders of magnitude faster than non-neural baselines.
  • Retrieval Scalability: When searching large databases, GREED’s indexing allows it to be 50x faster on a CPU than its closest competitor running on a high-end GPU.
  • Generalization: The model showed a robust ability to generalize to different query types (e.g., queries generated via Random Walks vs. BFS) that it hadn't seen during training.

Limitations and Future Work

The primary limitation noted is generalization to larger query sizes. If the model is trained on small query graphs (e.g., 10-25 nodes), its accuracy dips when asked to handle much larger queries (e.g., 50+ nodes). The authors suggest that future work should focus on improving how these models scale to "out-of-distribution" graph sizes, perhaps through multi-scale embedding techniques. Additionally, while the framework can be extended to edge labels, the current experiments focused primarily on node labels and topology.

Summary updated

BibTeX
@inproceedings{ranjan2022greed,
  author = {Rishabh Ranjan and Siddharth Grover and Sourav Medya and Venkatesan T. Chakaravarthy and Yogish Sabharwal and Sayan Ranu},
  title = {{GREED: A Neural Framework for Learning Graph Distance Functions}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=BGyqRIeuPi},
}
Figure