Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:exact topology matching and approximate feature matching #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

OrigenesZhang
Copy link
Collaborator

Changes made to networkx's implementation for VF2 algorithm to support approximate matching on nodes' features.

Heuristics made on topology matching:

  • Starting the search with the node pairs with the most similar node embeddings (from cosine similarity perspective)
  • Letting node pairs with very similar node embeddings pass the syntactic feasibility test directly (threshold passed in as an argument of the class constructor)

Example:

from vf2 import GraphMatcher
from torch import Tensor
from torch_geometric.utils import from_networkx

import networkx as nx

G1 = nx.Graph()
for i in range(4):
    G1.add_node(i)
for i in range(3):
    G1.add_edge(i, i+1)
    
G2 = nx.Graph()
for i in range(3):
    G2.add_node(i)
for i in range(2):
    G2.add_edge(i, i+1)

G1 = from_networkx(G1)
G2 = from_networkx(G2)

e1 = Tensor([[1, 1], [2, 2], [3, 3], [4, 4]])
e2 = Tensor([[1, 2], [3, 4], [5, 6]])

fv1 = Tensor([[1, 1], [1, 2], [1, 3], [1, 4]])
fv2 = Tensor([[1, 1], [1, 3], [1, 4]])


GM = GraphMatcher(G1, G2, e1, e2, fv1, fv2, 0.3, 0)
print(GM.subgraph_is_isomorphic())
print(GM.mapping)  # node index in G1 (target graph) to node index in G2 (query graph)

GM = GraphMatcher(G1, G2, e1, e2, fv1, fv2, 0.01, 0)
print(GM.subgraph_is_isomorphic())

Expected output:

True
{2: 0, 1: 1, 0: 2}
False

@OrigenesZhang OrigenesZhang self-assigned this Apr 21, 2024
@OrigenesZhang OrigenesZhang requested a review from mjyoussef April 21, 2024 20:33
@@ -105,7 +106,7 @@ def candidate_pairs_iter(self):
# checkme: process the valid node pairs with the closest embedding first
ordered_T1_inout = sorted(
T1_inout.copy(),
key=lambda u: self.comparator(self.e1[u], self.e2[node_2])
key=lambda u: -self.cosf(self.e1[u], self.e2[node_2])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be improved with a top K search?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@OrigenesZhang OrigenesZhang force-pushed the feat/post-processing branch 2 times, most recently from 1c39154 to 5f712ea Compare April 22, 2024 04:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants