{"id":22229795,"url":"https://github.com/graph-com/peg","last_synced_at":"2025-07-27T19:31:57.616Z","repository":{"id":54338070,"uuid":"413967746","full_name":"Graph-COM/PEG","owner":"Graph-COM","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-04T01:23:03.000Z","size":29801,"stargazers_count":38,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T07:02:10.597Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Graph-COM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-05T20:22:03.000Z","updated_at":"2025-03-20T22:44:02.000Z","dependencies_parsed_at":"2024-12-03T01:23:51.178Z","dependency_job_id":null,"html_url":"https://github.com/Graph-COM/PEG","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Graph-COM/PEG","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FPEG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FPEG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FPEG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FPEG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Graph-COM","download_url":"https://codeload.github.com/Graph-COM/PEG/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FPEG/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267413713,"owners_count":24083482,"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","status":"online","status_checked_at":"2025-07-27T02:00:11.917Z","response_time":82,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-12-03T01:12:27.474Z","updated_at":"2025-07-27T19:31:52.597Z","avatar_url":"https://github.com/Graph-COM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PEG\nThe official implementation of PEG for our paper: [Equivariant and Stable Positional Encoding for More Powerful Graph Neural Networks](https://arxiv.org/abs/2203.00199).\n\n## Introduction\nIn this work, we propose a principled way of using stable Positional Encoding (PE) to build more powerful GNNs. The key idea is to use separate channels to update the original node features and positional features. To achieve PE-stability, the GNN layer should keep not only permutation equivariance w.r.t. node features but also rotation equivariance w.r.t. positional features. This idea applies to a broad range of PE techniques that can be formulated as matrix factorization such as Laplacian Eigenmap (LE) and Deepwalk (DW).\n\nWe design a GNN layer with edge weights according to distance between the end nodes of the edge and keep the position features unchanged. This satisfies the above two necessary conditions and gives the **PE-stable GNN layer** as\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://latex.codecogs.com/svg.image?g_{\\text{PEG}}(A,X,Z)\u0026space;=\u0026space;\\left(\\psi\\left[\\left(\\hat{A}\u0026space;\\odot\u0026space;\\Xi\\right)\u0026space;X\u0026space;W\u0026space;\\right],\u0026space;Z\\right),\\,\\text{where\u0026space;$\\Xi_{uv}=\\phi\\left(\\|Z_u-Z_v\\|\\right)$,\u0026space;$\\forall\u0026space;u,v\\in[N]$}.\" title=\"g_{\\text{PEG}}(A,X,Z) = \\left(\\psi\\left[\\left(\\hat{A} \\odot \\Xi\\right) X W \\right], Z\\right),\\,\\text{where $\\Xi_{uv}=\\phi\\left(\\|Z_u-Z_v\\|\\right)$, $\\forall u,v\\in[N]$}.\" /\u003e\n\u003c/p\u003e\n\nHere, \u003cimg src=\"https://latex.codecogs.com/svg.image?\\psi\" title=\"\\psi\" /\u003e is an element-wise activation function, \u003cimg src=\"https://latex.codecogs.com/svg.image?\\phi\" title=\"\\phi\" /\u003e is an MLP mapping from \u003cimg src=\"https://latex.codecogs.com/svg.image?\\mathbb{R}\\rightarrow\u0026space;\\mathbb{R}\" title=\"\\mathbb{R}\\rightarrow \\mathbb{R}\" /\u003e and \u003cimg src=\"https://latex.codecogs.com/svg.image?\\odot\" title=\"\\odot\" /\u003e is the Hadamard product.\n\n## Requirements ##\n(Other versions may work, but are untested)\n* Python 3.7\n* PyTorch 1.8.1 Cuda 10.2\n* Tensorflow 2.6.0\n* NetworkX 2.6.2\n* Numpy 1.20.3\n* Scipy 1.6.2\n* Scikit-Learn 0.24.1\n* dgl 0.6.1\n* torch-geometric 2.0.3\n\n## PEG Environment Setup ##\n- Install basic dependencies to virtual environment and activate it: \n```bash\nconda env create -f environment.yml\nconda activate PEG_env\n```\n\n- Example commends of installation for PyTorch (\u003e= 1.8.0) and torch-geometric (\u003e=1.7.2) with CUDA 10.2:\n```bash\nconda install pytorch==1.8.0 torchvision torchaudio cudatoolkit=10.2\npip install torch-scatter -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html\npip install torch-sparse -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html\npip install torch-cluster -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html\npip install torch-spline-conv -f https://pytorch-geometric.com/whl/torch-1.8.0+cu102.html\npip install torch-geometric==1.7.2\n```\nFor more details, please refer to the [PyTorch](https://pytorch.org/) and [PyTorch Geometric](https://pytorch-geometric.readthedocs.io/en/1.6.3/notes/installation.html). The code of this repository is lately tested with Python 3.7.11 + PyTorch 1.8.1 + torch-geometric 1.7.2.\n\n#### Run Examples\nIn Task 1 (traditional link prediction), the model gets trained, validated and tested over the same graphs while using different link sets. In Task 2 (domain-shift link prediction), the graph used for training/validation is different from the one used for testing. Both tasks may reflect the effectiveness of a model while Task 2 may better demonstrate the model's generalization capability that strongly depends on permutation equivariance and stability.\n##### Task1\n```bash\ncd task1\n```\nPEG-DW using node feature on cora\n```bash\npython main.py --PE_method DW --dataset cora --feature_type N\n```\nPEG-LE+ using constant feature on cora\n```bash\npython main.py --PE_method LE --dataset cora --feature_type C --random_partition --hidden_dim 1\n```\n\nFor ddi and collab, the script is under the folder task1_OGB.\n\n##### Task2\n```bash\ncd task2\n```\nPEG-DW using node feature on cora-\u003eciteseer\n```bash\npython main.py --PE_method DW --source_dataset cora --target_dataset citeseer --feature_type N\n```\nPEG-LE+ using constant feature on cora-\u003eciteseer\n```bash\npython main.py --PE_method LE --source_dataset cora --target_dataset citeseer --feature_type C --random_partition --hidden_dim 1\n```\nFor PPI dataset\n```bash\npython PPI.py --PE_method LE --feature_type N\n```\n```bash\npython PPI.py --PE_method DW --feature_type C --hidden_dim 1\n```\n## Usage Summary\n```\nusage: main.py [-h] [--device DEVICE]\n               [--dataset {cora,citeseer,pubmed,PTBR,RU,ENGB,ES,chameleon}]\n               [--PE_method {DW,LE}] [--feature_type {N,C}]\n               [--num_layers NUM_LAYERS] [--PE_dim PE_DIM]\n               [--hidden_dim HIDDEN_DIM] [--batch_size BATCH_SIZE] [--lr LR]\n               [--weight_decay WEIGHT_DECAY] [--epochs EPOCHS]\n               [--val_ratio VAL_RATIO] [--test_ratio TEST_RATIO]\n               [--random_partition]\n\n```\n\n## Optional Arguments\n```\noptional arguments:\n  -h, --help            show this help message and exit\n  --device DEVICE\n  --dataset {cora,citeseer,pubmed,PTBR,RU,ENGB,ES,chameleon}\n                        dataset name\n  --PE_method {DW,LE}   positional encoding techniques\n  --feature_type {N,C}  features type, N means node feature, C means constant\n                        feature (node degree)\n  --num_layers NUM_LAYERS\n                        number of layers\n  --PE_dim PE_DIM       dimension of positional encoding\n  --hidden_dim HIDDEN_DIM\n                        hidden dimension\n  --batch_size BATCH_SIZE\n                        batch size\n  --lr LR               learning rate\n  --weight_decay WEIGHT_DECAY\n                        weight decay\n  --epochs EPOCHS       number of epochs to train\n  --val_ratio VAL_RATIO\n                        validation ratio\n  --test_ratio TEST_RATIO\n                        testing ratio\n  --random_partition    whether to use random partition while training\n```\n\n## Citation\nPlease refer to our paper. Haorui Wang, Haoteng Yin, Muhan Zhang, Pan Li. [Equivariant and Stable Positional Encoding for More Powerful Graph Neural Networks](https://arxiv.org/abs/2203.00199). In *International Conference on Learning Representations (ICLR)*, 2022\n\n```\n  @inproceedings{wang2022equivariant,\n  title={Equivariant and Stable Positional Encoding for More Powerful Graph Neural Networks},\n  author={Wang, Haorui and Yin, Haoteng and Zhang, Muhan and Li, Pan},\n  booktitle={International Conference on Learning Representations},\n  year={2022}\n```\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fpeg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraph-com%2Fpeg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Fpeg/lists"}