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

Adding Multiple Virtual Nodes to Transform module #9873

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

deniselj24
Copy link

@deniselj24 deniselj24 commented Dec 15, 2024

Currently, PyG Transforms module supports adding a single Virtual Node connected to all nodes in the graph, implemented in torch_geometric/transforms/virtual_node.py. Motivated by the paper "An Analysis of Virtual Nodes in Graph Neural Networks for Link Prediction" , which finds that adding multiple or more virtual nodes to the graph improves performance, I added / modified 3 files to support adding multiple virtual nodes to the graph within the Transforms module:

  1. Added torch_geometric/transforms/multiple_virtual_nodes.py:
  • creates the MultipleVirtualNodes class, which can be initialized with 3 parameters, num_to_add: int number of virtual nodes to add to graph, clustering: bool that specifies if the user wants to perform the PyG METIS clustering on the graph to assign virtual nodes to current nodes, or wants to assign them randomly, and recursive: bool to specify if PyG clustering is multi-level bisection (True) or k-way multilevel clustering (False). Note: ClusterData requires either 'pyg-lib' or 'torch-sparse'
  • modifies data.edge_index, x, edge_index, edge_type, etc to reflect these changes to the graph.
  1. Added test/transforms/test_multiple_virtual_nodes.py to validate the changes.
  2. Updated torch_geometric/transforms/init.py to reflect the new transform.
    I referred to the current VirtualNode implementations.

@deniselj24 deniselj24 requested a review from wsad1 as a code owner December 15, 2024 09:41
Copy link

codecov bot commented Dec 15, 2024

Codecov Report

Attention: Patch coverage is 95.94595% with 3 lines in your changes missing coverage. Please review.

Project coverage is 86.33%. Comparing base (2b1b327) to head (6cc5aff).

Files with missing lines Patch % Lines
...rch_geometric/transforms/multiple_virtual_nodes.py 95.89% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9873      +/-   ##
==========================================
+ Coverage   85.63%   86.33%   +0.70%     
==========================================
  Files         478      491      +13     
  Lines       31925    32361     +436     
==========================================
+ Hits        27339    27940     +601     
+ Misses       4586     4421     -165     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

1 participant