New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/filippomb/benchmark_dataset_for_graph_classification

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/filippomb/benchmark_dataset_for_graph_classification

  • v0.0.0-20230322150027-77ae0ba04ba9
  • Source
  • Go
  • Socket score

Version published
Created
Source

Benchmark dataset for graph classification

This repository contains datasets to quickly test graph classification algorithms, such as Graph Kernels and Graph Neural Networks.

The purpose of this dataset is to make the features on the nodes and the adjacency matrix to be completely uninformative if considered alone. Therefore, an algorithm that relies only on the node features or on the graph structure will fail to achieve good classification results.

Citation

Please, cite the original paper if you are using this dataset in your research

@inproceedings{bianchi2022pyramidal,
    title={Pyramidal Reservoir Graph Neural Network},
    author={Bianchi, Filippo Maria and Gallicchio, Claudio and Micheli, Alessio},
    journal={Neurocomputing},
    volume={470},
    pages={389--404},
    year={2022},
    publisher={Elsevier}
}

Dataset details

The dataset consists of graphs belonging to 3 different classes. The number of nodes in each graph is variable and the feature vector on each node is a one-hot vector of size 5, which encodes the color of the node. The class is determined by the relative position of the colors on the graph.

There are 4 versions of the dataset

  • small_easy: 100 graphs per class, number of nodes varying in 40 and 80. Highly connected graphs.
  • easy: 600 graphs per class, number of nodes varying in 100 and 200. Highly connected graphs.
  • small_hard: 100 graphs per class, number of nodes varying in 40 and 80. Sparse graphs.
  • hard: 600 graphs per class, number of nodes varying in 100 and 200. Sparse graphs.

In the hard dataset, it is necessary to consider higher order neighborhoods to understand the correct class and the graphs might be disconnected.

Dataset# classes# graphsTR sizeVAL sizeTEST sizeavg nodesavg edgesNode Attr. (Dim.)
easy_small3300239303158.25358.85
hard_small3300245292658.64224.945
easy318001475162163147.82922.665
hard318001451159190148.32572.325

Format

The dataset is already split in training, validation and classification sets. Each set contains:

  • the list of adjacency matrices in csr_matrix format,
  • the list of node features as numpy arrays,
  • the class labels contained in a numpy array,

The following code snippet shows how to load the data

import numpy as np

loaded = np.load('datasets/hard.npz', allow_pickle=True)

X_train = loaded['tr_feat'] # node features
A_train = list(loaded['tr_adj']) # list of adjacency matrices
y_train = loaded['tr_class'] # class labels

X_val = loaded['val_feat'] # node features
A_val = list(loaded['val_adj']) # list of adjacency matrices
y_val = loaded['val_class'] # class labels

X_test = loaded['te_feat'] # node features
A_test = list(loaded['te_adj']) # list of adjacency matrices
y_test = loaded['te_class'] # class labels

# OPTIONAL - Convert to networkx format
import networkx as nx

G_train = []
for a, x in zip(A_train, X_train):
    G = nx.from_scipy_sparse_matrix(a)
    x_tuple = tuple(map(tuple, x))
    nx.set_node_attributes(G, dict(enumerate(x_tuple)), 'features')
    G_train.append(G)
    
G_val = []
for a, x in zip(A_val, X_val):
    G = nx.from_scipy_sparse_matrix(a)
    x_tuple = tuple(map(tuple, x))
    nx.set_node_attributes(G, dict(enumerate(x_tuple)), 'features')
    G_val.append(G)
    
G_test = []
for a, x in zip(A_test, X_test):
    G = nx.from_scipy_sparse_matrix(a)
    x_tuple = tuple(map(tuple, x))
    nx.set_node_attributes(G, dict(enumerate(x_tuple)), 'features')
    G_test.append(G)

Loader (Pytorch)

The dataset can be processed by a GNN implemented in Pytorch Geometric using the function defined in torch_loader.py.

from torch_geometric.loader import DataLoader
from torch_loader import GraphClassificationBench

# Load "hard"
train_dataset = GraphClassificationBench("data/", split='train', easy=False, small=False)
val_dataset = GraphClassificationBench("data/", split='val', easy=False, small=False)
test_dataset = GraphClassificationBench("data/", split='test', easy=False, small=False)

train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True)
val_loader = DataLoader(val_dataset, batch_size=32)
test_loader = DataLoader(test_dataset, batch_size=32)

See torch_classification_example.py for a complete working example.

Results

Classification results obtained by using Graph Kernels and other techniques are reported below.

Feel free to send a pull request if you have results you'd like to share!

Graph Kernels

The Graph Kernels are computed with the GraKeL library. After each kernel is computed, an SVM that uses as precomputed kernel the Graph Kernel is trained and then evaluated on the test data. As SVM implementation, the sklearn.svm module was used. The code used to generate the results can be found in the notebook of this repository.

Dependecies to run the notebook:

  • scikitlearn pip install sklearn
  • networkx pip install networkx
  • grakel pip install grakel-dev
easy_smallhard_small
Shortest PathAccuracy: 100Time: 20.67 sAccuracy: 69.23Time: 7.85 s
Graphlet SamplingAccuracy: 41.94Time: 281.35 sAccuracy: 38.46Time: 37.84 s
Pyramid MatchAccuracy: 51.61Time: 2.91 sAccuracy: 23.08Time: 2.86 s
SVM ThetaAccuracy: 32.26Time: 3.34 sAccuracy: 23.08Time: 2.91 s
Neighborhood HashAccuracy: 90.32Time: 2.73 sAccuracy: 69.23Time: 2.71 s
Subtree WLAccuracy: 29.03Time: 0.01 sAccuracy: 15.38Time: 0.03 s
ODD STHAccuracy: 77.42Time: 58.75 sAccuracy: 42.31Time: 24.48 s
PropagationAccuracy: 87.1Time: 3.35 sAccuracy: 53.85Time: 2.61 s
Vertex HistogramAccuracy: 29.03Time: 0.02 sAccuracy: 15.38Time: 0.01 s
Weisfeiler LehmanAccuracy: 100Time: 151.81 sAccuracy: 73.08Time: 58.92 s
Core FrameworkAccuracy: 100Time: 62.18 sAccuracy: 69.23Time: 18.62 s
Graph Neural Networks

Results obtained with the following GNN architecture: MP(32)-Pool-MP(32)-Pool-MP(32)-GlobalPool-Dense(Softmax). MP is a message-passing architecture. A Chebyshev convolutional layer [1] with K=1 and 32 hidden units was used here. Results refer to different graph pooling layers: Graclus [2], Node Decimation Pooling (NDP) [3], DiffPool [4], Top-K pooling [5], SAGpool [6] and MinCutPool [7].

easyhard
GraclusAccuracy: 97.5 ± 0.5Accuracy: 69.0 ± 1.5
NDPAccuracy: 97.9 ± 0.5Accuracy: 72.6 ± 0.9
DiffPoolAccuracy: 98.6 ± 0.4Accuracy: 69.9 ± 1.9
Top-KAccuracy: 82.4 ± 8.9Accuracy: 42.7 ± 15.2
SAGPoolAccuracy: 84.2 ± 2.3Accuracy: 37.7 ± 14.5
MinCutPoolAccuracy: 99.0 ± 0.0Accuracy: 73.8 ± 1.9
Embedding Simplicial Complexes (ESC)

Techniques proposed in [8].

easy_smallhard_small
ESC + RBF-SVMAccuracy: 74.19 ± 6.84Time: 0.68 sAccuracy: 48.46 ± 8.43Time: 0.48 s
ESC + L1-SVMAccuracy: 94.19 ± 2.70Time: 0.68 sAccuracy: 70.77 ± 5.83Time: 0.48 s
ESC + L2-SVMAccuracy: 92.26 ± 2.89Time: 0.68 sAccuracy: 69.23 ± 5.44Time: 0.48 s
easyhard
ESC + RBF-SVMAccuracy: 80.37 ± 7.04Time: 10.94 sAccuracy: 62.53 ± 4.58Time: 16.65 s
ESC + L1-SVMAccuracy: 96.07 ± 0.93Time: 10.94 sAccuracy: 72.21 ± 1.01Time: 16.65 s
ESC + L2-SVMAccuracy: 93.37 ± 1.96Time: 10.94 sAccuracy: 69.26 ± 1.85Time: 16.65 s
Hypergraph kernels

Techniques proposed in [9].

easy_smallhard_small
Hist KernelAccuracy: 94.0 ± 0.02Time: 0.72 sAccuracy: 77.0 ± 0.02Time: 0.46 s
Jaccard KernelAccuracy: 94.0 ± 0.0Time: 0.86 sAccuracy: 68.0 ± 0.02Time: 0.54 s
Edit KernelAccuracy: 94.0 ± 0.01Time: 9.97 sAccuracy: 60.0 ± 0.02Time: 7.70 s
Stratedit KernelAccuracy: 94.0 ± 0.0Time: 5.14 sAccuracy: 58.0 ± 0.02Time: 4.79 s
easyhard
Hist KernelAccuracy: 94.0 ± 0.01Time: 10.39 sAccuracy: 72.0 ± 0.01Time: 6.93 s
Jaccard KernelAccuracy: 94.0 ± 0.01Time: 14.15 sAccuracy: 63.0 ± 0.00Time: 8.11 s
Edit KernelAccuracy: 93.0 ± 0.00Time: 2784.47 sAccuracy: 60.0 ± 0.00Time: 2183.41 s
Stratedit KernelAccuracy: 93.0 ± 0.00Time: 932.96 sAccuracy: 60.0 ± 0.01Time: 954.87 s

References

[1] Defferrard, M., Bresson, X., & Vandergheynst, P. (2016). Convolutional neural networks on graphs with fast localized spectral filtering. In Advances in neural information processing systems

[2] Dhillon, I. S., Guan, Y., & Kulis, B. (2007). Weighted graph cuts without eigenvectors a multilevel approach. IEEE transactions on pattern analysis and machine intelligence

[3] Bianchi, F. M., Grattarola, D., Livi, L., & Alippi, C. (2019). Hierarchical Representation Learning in Graph Neural Networks with Node Decimation Pooling

[4] Ying, Z., You, J., Morris, C., Ren, X., Hamilton, W., & Leskovec, J. (2018). Hierarchical graph representation learning with differentiable pooling. In Advances in neural information processing systems

[5] Gao, H., & Ji, S., Graph u-nets, ICML 2019

[6] Lee, J., Lee, I., & Kang, J., Self-attention graph pooling, ICML 2019

[7] F. M. Bianchi, D. Grattarola, C. Alippi, Spectral Clustering with Graph Neural Networks for Graph Pooling, ICML 2020

[8] Martino A, Giuliani A, Rizzi A., (Hyper) Graph Embedding and Classification via Simplicial Complexes. Algorithms. 2019 Nov; 12(11):223

[9] Martino A. and Rizzi A., (Hyper)graph kernels over simplicial complexes. 2020. Pattern Recognition

License

The dataset and the code are released under the MIT License. See the attached LICENSE file.

FAQs

Package last updated on 22 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc