{"id":30071392,"url":"https://github.com/graph-com/tsa","last_synced_at":"2025-08-08T12:42:35.613Z","repository":{"id":296711183,"uuid":"993992948","full_name":"Graph-COM/TSA","owner":"Graph-COM","description":"Source code of \"Structural Alignment Improves Graph Test-Time Adaptation\"","archived":false,"fork":false,"pushed_at":"2025-06-09T15:22:21.000Z","size":191,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-09T16:29:13.401Z","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,"zenodo":null}},"created_at":"2025-06-01T00:38:14.000Z","updated_at":"2025-06-09T15:22:25.000Z","dependencies_parsed_at":"2025-06-09T16:23:41.558Z","dependency_job_id":null,"html_url":"https://github.com/Graph-COM/TSA","commit_stats":null,"previous_names":["graph-com/tsa"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Graph-COM/TSA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FTSA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FTSA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FTSA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FTSA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Graph-COM","download_url":"https://codeload.github.com/Graph-COM/TSA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Graph-COM%2FTSA/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269423867,"owners_count":24414615,"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-08-08T02:00:09.200Z","response_time":72,"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":"2025-08-08T12:42:32.153Z","updated_at":"2025-08-08T12:42:35.521Z","avatar_url":"https://github.com/Graph-COM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TSA\nSource code of [\"Structural Alignment Improves Graph Test-Time Adaptation\"](https://arxiv.org/abs/2502.18334).\n\n## How TSA tackles test-time distribution shifts?\n\n**1. Neighborhood Alignment** Recalibrate the influence of neighboring nodes during message aggregation to address *conditional structure shift* (CSS).\n\n**2. SNR-inspired Adjustment**: Optimize the test-time combination of self-node representations and neighborhood-aggregated representations based on the *signal-to-noise ratio* (SNR).\n\n**3. Decision Boundary Refinement**: Mitigate mismatches caused by *label* and *feature* shifts.\n\n![TSA image](https://github.com/Graph-COM/TSA/blob/main/images/tsa.png?raw=true)\n\n## Installation\n\nThe code is based on Python 3.10 and Cuda 12.1. We recommend to setup the enviornment using `conda`. After cloning the repository, run the following command to create the `tsa` environment.\n\n```\ncd TSA\nconda env create -f env.yaml\nconda activate tsa\n```\n\n## Datasets\n\nAll datasets are saved in `./data/` directory. The `CSBM` and `Arxiv` datasets atasets will be loaded automatically at runtime. The raw data for `DBLP_ACM`, `MAG`, and `Pileup` should be downloaded manually from the following sources:\n\n* `DBLP_ACM`: [Google Drive](https://drive.google.com/file/d/1DzQ3QN9yjQxU4vtYkXyCiJKFw7oCCPSM/view). We follow the preprocessing procedure adopted from [UDAGCN](https://github.com/TrustAGI-Lab/UDAGCN).\n* `MAG`: [Zenodo](https://zenodo.org/records/10681285). We follow the preprocessing procedure adopted from [PairAlign](https://github.com/Graph-COM/Pair-Align).\n* `Pileup`: [Zenodo](https://zenodo.org/records/8015774). We follow the preprocessing procedure adopted from [StruRW](https://github.com/Graph-COM/StruRW).\n\n\nPlace the downloaded files according to the directory structure shown below. The preprocessed data, including dataset splitting, will be generated automatically after the first run:\n\n```\ndata/\n├── DBLP_ACM/\n│ ├── acm/\n│ │ └── raw/\n│ │ │ └── acm_docs.txt\n│ │ │ ├── acm_edgelist.txt\n│ │ │ └── acm_labels.txt\n│ ├── dblp/\n│ │ └── raw/\n│ │ │ └── dblp_docs.txt\n│ │ │ ├── dblp_edgelist.txt\n│ │ │ └── dblp_labels.txt\n│\n├── MAG/\n│ └── raw/\n│ │ └── CN_labels_20.pt\n│ │ ├── DE_labels_20.pt\n│ │ ├── FR_labels_20.pt\n│ │ ├── JP_labels_20.pt\n│ │ ├── RU_labels_20.pt\n│ │ ├── US_labels_20.pt\n│ │ ├── label_stat.csv\n│ │ └── papers.csv\n│\n├── Pileup/\n│ └── raw/\n│ │ └──test_gg_PU10.root\n│ │ ├── test_gg_PU30.root\n│ │ ├── test_gg_PU50.root\n│ │ ├── test_gg_PU140.root\n│ │ ├── test_qq_PU10.root\n│ │ └── test_qq_PU30.root\n```\n\n## Usage\n\n```\npython src/main.py data= \u003cDATASET\u003e adapter=\u003cMETHOD\u003e model=\u003cMODEL\u003e [Options]\n\n```\n* `adapter`: TSA variants include `TSA_T3A`, `TSA_LAME`, and `TSA_TENT`.\n* `model`: We include `GSN`, `GPRGNN`, and `GCN`.\n* `data`: `CSBM`, `MAG`, `Pileup`, `Arxiv`, and `DA` (DBLP_ACM). We use the number to indicate the column index in the corresponding dataset’s result table in the paper. For example, `MAG1` refers to US ➝ CN and `MAG2` refers to US ➝ DE.\n\n\n**Example of CSBM dataset:**\n\nRun `TSA_T3A` under `CSS` with `GSN` backbone.\n\n```\npython src/main.py data=CSBM1 adapter=TSA_T3A model=GSN model_config.gnn_dim=20 model_config.cls_dim=20 adapter_config.filter_K=20 adapter_config.scale_lr=0.1 adapter_config.pa_ratio=1.0 adapter_config.scale_thre=1.0\n```\n\n**Example of MAG dataset:**\n\nRun `TSA_T3A` under shift from `US ➝ CN` with `GSN` backbone.\n\n```\npython src/main.py data=MAG1 adapter=TSA_T3A model=GSN model_config.gnn_dim=300 model_config.cls_dim=300 adapter_config.filter_K=20 adapter_config.scale_lr=0.05 adapter_config.pa_ratio=0.5 adapter_config.scale_thre=1.0 \n```\n\n**Example of Pileup dataset:**\n\nRun `TSA_T3A` under shift from `PU30 ➝ PU10` with `GSN` backbone.\n\n```\npython src/main.py data=Pileup2 adapter=TSA_T3A model=GSN model_config.gnn_dim=50 model_config.cls_dim=50 adapter_config.filter_K=20  adapter_config.pa_ratio=0.5 adapter_config.scale_lr=0.1 adapter_config.scale_thre=0.1\n```\n\n**Example of Arxiv dataset:**\n\nRun `TSA_LAME` under shift from `1950-2007 ➝ 2016-2018` with `GSN` backbone.\n\n```\npython src/main.py data=Arxiv2 adapter=TSA_LAME model=GSN model_config.gnn_dim=300 model_config.cls_dim=300 adapter_config.pa_ratio=0.01 adapter_config.scale_lr=0.001 adapter_config.scale_thre=0.1\n```\n\n**Example of DBLP_ACM dataset:**\n\nRun `TSA_T3A` under shift from `DBLP ➝ ACM` with `GPRGNN` backbone.\n\n```\npython src/main.py data=DA1 adapter=TSA_T3A model=GPRGNN model_config.gnn_dim=128 model_config.cls_dim=40 adapter_config.filter_K=20 adapter_config.scale_lr=0.1 adapter_config.pa_ratio=0.5 adapter_config.scale_thre=1.0\n```\n\nFor detailed hyperparameters, please see `configs/adapter/`.\n\n## Graph Test-Time Adaptation with other Baselines\n\nWe implemented multiple baseline methods in `src/adaptation/`. To run the baseline methods, set the argument `adapter` to the corresponding values. This include:\n\n* **Graph TTA Methods**: `GTrans` ([Paper](https://arxiv.org/abs/2210.03561)), `SOGA` ([Paper](https://arxiv.org/abs/2112.00955)), `HomoTTT` ([Paper](https://dl.acm.org/doi/10.1145/3649507)), `Matcha-T3A`, `Matcha-LAME`, and `Matcha-TENT` ([Paper](https://arxiv.org/abs/2410.06976)).\n\n* **Non-Graph TTA Methods**: `ActMAD` ([Paper](https://arxiv.org/abs/2211.12870)), `T3A` ([Paper](https://proceedings.neurips.cc/paper/2021/hash/1415fe9fea0fa1e45dddcff5682239a0-Abstract.html)), `LAME` ([Paper](https://arxiv.org/abs/2201.05718)), and `TENT`([Paper](https://arxiv.org/abs/2006.10726)).\n\nFor detailed hyperparameters, please see `configs/adapter/`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Ftsa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraph-com%2Ftsa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraph-com%2Ftsa/lists"}