{"id":15649293,"url":"https://github.com/danielegrattarola/src","last_synced_at":"2025-04-30T16:15:14.556Z","repository":{"id":54698654,"uuid":"413415593","full_name":"danielegrattarola/SRC","owner":"danielegrattarola","description":"Code for \"Understanding Pooling in Graph Neural Networks\" (TNNLS 2022).","archived":false,"fork":false,"pushed_at":"2022-06-02T11:56:22.000Z","size":16389,"stargazers_count":62,"open_issues_count":1,"forks_count":7,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T16:14:57.234Z","etag":null,"topics":["deep-learning","graph-neural-networks","graph-pooling","machine-learning","tensorflow"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2110.05292","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danielegrattarola.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-04T12:39:30.000Z","updated_at":"2025-04-11T12:48:46.000Z","dependencies_parsed_at":"2022-08-14T00:20:35.944Z","dependency_job_id":null,"html_url":"https://github.com/danielegrattarola/SRC","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielegrattarola%2FSRC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielegrattarola%2FSRC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielegrattarola%2FSRC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danielegrattarola%2FSRC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danielegrattarola","download_url":"https://codeload.github.com/danielegrattarola/SRC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251739649,"owners_count":21635892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","graph-neural-networks","graph-pooling","machine-learning","tensorflow"],"created_at":"2024-10-03T12:29:10.011Z","updated_at":"2025-04-30T16:15:14.503Z","avatar_url":"https://github.com/danielegrattarola.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Select, Reduce, Connect\n\n![](images/src.png)\n\nThis repository contains the code used for the experiments of:\n\n**\"Understanding Pooling in Graph Neural Networks\"**   \nD. Grattarola, D. Zambon, F. M. Bianchi, C. Alippi  \nhttps://arxiv.org/abs/2110.05292\n\n\n# Setup\n\nThe dependencies of the project are listed in requirements.txt. You can install them with: \n\n```bash\npip install -r requirements.txt\n```\n\n# Running experiments\n\nThe code to run our experiments is in the following folders: \n\n- `autoencoder/`\n- `spectral_similarity/`\n- `graph_classification/`\n\nEach folder has a script called `run_all.sh` that will reproduce the results reported in the paper. \n\nTo generate the plots and tables from the paper, you can use the `plots.py`, `plots_datasets.py`, or `tables.py` scripts in each folder.\n\nTo run experiments for an individual pooling operator, you can use the `run_[OPERATOR NAME].py` scripts in each folder. \n\nThe pooling operators that we used for the experiments are in `layers/` (trainable) and `modules/` (non-trainable).\nThe GNN architectures used in the experiments are in `models/`. \n\n# The SRCPool class\n\nThe core of this repository is the `SRCPool` class that implements a general \ninterface to create SRC pooling layers with the Keras API.\n\nOur implementation of MinCutPool, DiffPool, LaPool, Top-K, and SAGPool using the\n`SRCPool` class can be found in `src/layers`.\n\nSRC layers have the following structure \n$$\\mathcal{S} = \\mathrm{SEL}( \\mathcal{G} ) = \\\\\\{\\mathcal{S}\\_k \\\\\\}\\_{k=1:K}; \\\\;\\\\; \\mathcal{X}' = \\\\\\{\\mathrm{RED}( \\mathcal{G}, \\mathcal{S}\\_k ) \\\\\\}\\_{k=1:K}; \\\\;\\\\; \\mathcal{E}' = \\\\\\{\\mathrm{CON}( \\mathcal{G}, \\mathcal{S}\\_k, \\mathcal{S}\\_l )\\\\\\}\\_{k,l=1:K}$$\n\nwhere $\\textrm{SEL}$ is a permutation-equivariant selection function that computes the supernodes $\\mathcal{S}_k$, $\\textrm{RED}$ is a permutation-invariant function to reduce the supernodes into the new node attributes, and $\\textrm{CON}$\nis a permutation-invariant connection function that computes the edges among the new nodes.\n\nBy extending this class, it is possible to create any pooling layer in the\nSRC framework.\n\n**Input**\n\n- `X`: Tensor of shape `([batch], N, F)` representing node features;\n- `A`: Tensor or SparseTensor of shape `([batch], N, N)` representing the\nadjacency matrix;\n- `I`: (optional) Tensor of integers with shape `(N, )` representing the\nbatch index;\n\n**Output**\n\n- `X_pool`: Tensor of shape `([batch], K, F)`, representing the node\nfeatures of the output. `K` is the number of output nodes and depends on the\nspecific pooling strategy;\n- `A_pool`: Tensor or SparseTensor of shape `([batch], K, K)` representing\nthe adjacency matrix of the output;\n- `I_pool`: (only if `I` was given as input) Tensor of integers with shape\n`(K, )` representing the batch index of the output;\n- `S_pool`: (if `return_sel=True`) Tensor or SparseTensor representing the\nsupernode assignments;\n\n**API**\n\n- `pool(X, A, I, **kwargs)`: pools the graph and returns the reduced node\nfeatures and adjacency matrix. If the batch index `I` is not `None`, a\nreduced version of `I` will be returned as well.\nAny given `kwargs` will be passed as keyword arguments to `select()`,\n`reduce()` and `connect()` if any matching key is found.\nThe mandatory arguments of `pool()` (`X`, `A`, and `I`) **must** be computed in \n`call()` by calling `self.get_inputs(inputs)`.\n- `select(X, A, I, **kwargs)`: computes supernode assignments mapping the\nnodes of the input graph to the nodes of the output.\n- `reduce(X, S, **kwargs)`: reduces the supernodes to form the nodes of the\npooled graph.\n- `connect(A, S, **kwargs)`: connects the reduced supernodes.\n- `reduce_index(I, S, **kwargs)`: helper function to reduce the batch index\n(only called if `I` is given as input).\n\nWhen overriding any function of the API, it is possible to access the\ntrue number of nodes of the input (`N`) as a Tensor in the instance variable\n`self.N` (this is populated by `self.get_inputs()` at the beginning of\n`call()`).\n\n**Arguments**:\n\n- `return_sel`: if `True`, the Tensor used to represent supernode assignments\nwill be returned with `X_pool`, `A_pool`, and `I_pool`;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielegrattarola%2Fsrc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanielegrattarola%2Fsrc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanielegrattarola%2Fsrc/lists"}