This repository implements a graph pooling operator to either coarsen the graph or cluster the similar nodes of the graph together using Spectral Modularity Maximization formulation. This operator is expected to learn the cluster assignment matrix using Graph Neural Networks by the following operations:
where
Spectral Loss:
where
Orthogonal Loss:
Cluster Loss:
where N is the number of nodes, F is the number of node features, BS is the Batch Size, C is the number of clusters. More in-depth information about this implementation can be found on PyTorch Geometric Official Website.
math
PyTorch
PyTorch Geometric
The PROTEINS
dataset contains 1113
homogeneous attributed graphs with average no. of nodes (~39.1
), edges (~145.6
), features (3
), and classes (2
) per graph.
- The layer implementation can be found inside
dmon_pool.py
. - To train and test this layer implementation on graphs, run
example.py
, and it printstrain
,validation
, andtest
accuracies alongside their corresponding losses after every epoch.
- Though the example given performs only the graph pooling operation, it is possible to use the GNN layer only to compute the clusters, each having similar nodes, by just calculating the
cluster loss
and turning off the other two losses. - Since the implementation is meant to either cluster the nodes or coarsen the graph, the implementation is only to perform
graph-level
tasks such as graph classification.