graphslim 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of graphslim might be problematic. Click here for more details.
- graphslim-1.0.0/MANIFEST.in +2 -0
- graphslim-1.0.0/PKG-INFO +33 -0
- graphslim-1.0.0/README.md +222 -0
- graphslim-1.0.0/graphslim/__init__.py +0 -0
- graphslim-1.0.0/graphslim/coarsening/__init__.py +12 -0
- graphslim-1.0.0/graphslim/coarsening/affinity_gs.py +110 -0
- graphslim-1.0.0/graphslim/coarsening/algebraic_jc.py +110 -0
- graphslim-1.0.0/graphslim/coarsening/averaging.py +58 -0
- graphslim-1.0.0/graphslim/coarsening/clustering.py +64 -0
- graphslim-1.0.0/graphslim/coarsening/clusteringagg.py +77 -0
- graphslim-1.0.0/graphslim/coarsening/coarsening_base.py +246 -0
- graphslim-1.0.0/graphslim/coarsening/heavy_edge.py +110 -0
- graphslim-1.0.0/graphslim/coarsening/kron.py +109 -0
- graphslim-1.0.0/graphslim/coarsening/utils.py +2002 -0
- graphslim-1.0.0/graphslim/coarsening/variation_cliques.py +131 -0
- graphslim-1.0.0/graphslim/coarsening/variation_edges.py +131 -0
- graphslim-1.0.0/graphslim/coarsening/variation_neighborhoods.py +131 -0
- graphslim-1.0.0/graphslim/coarsening/vng.py +118 -0
- graphslim-1.0.0/graphslim/condensation/__init__.py +9 -0
- graphslim-1.0.0/graphslim/condensation/doscond.py +64 -0
- graphslim-1.0.0/graphslim/condensation/doscondx.py +59 -0
- graphslim-1.0.0/graphslim/condensation/gcond.py +80 -0
- graphslim-1.0.0/graphslim/condensation/gcond_base.py +186 -0
- graphslim-1.0.0/graphslim/condensation/gcondx.py +76 -0
- graphslim-1.0.0/graphslim/condensation/gcsntk.py +160 -0
- graphslim-1.0.0/graphslim/condensation/geom.py +449 -0
- graphslim-1.0.0/graphslim/condensation/msgc.py +244 -0
- graphslim-1.0.0/graphslim/condensation/sfgc.py +215 -0
- graphslim-1.0.0/graphslim/condensation/sgdd.py +102 -0
- graphslim-1.0.0/graphslim/condensation/utils.py +236 -0
- graphslim-1.0.0/graphslim/configs/doscond/citeseer.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscond/cora.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscond/flickr.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscond/ogbn-arxiv.json +9 -0
- graphslim-1.0.0/graphslim/configs/doscond/reddit.json +9 -0
- graphslim-1.0.0/graphslim/configs/doscondx/citeseer.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscondx/cora.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscondx/flickr.json +7 -0
- graphslim-1.0.0/graphslim/configs/doscondx/ogbn-arxiv.json +8 -0
- graphslim-1.0.0/graphslim/configs/doscondx/reddit.json +7 -0
- graphslim-1.0.0/graphslim/configs/gcond/citeseer.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcond/cora.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcond/flickr.json +10 -0
- graphslim-1.0.0/graphslim/configs/gcond/ogbn-arxiv.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcond/reddit.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcondx/citeseer.json +8 -0
- graphslim-1.0.0/graphslim/configs/gcondx/cora.json +8 -0
- graphslim-1.0.0/graphslim/configs/gcondx/flickr.json +7 -0
- graphslim-1.0.0/graphslim/configs/gcondx/ogbn-arxiv.json +8 -0
- graphslim-1.0.0/graphslim/configs/gcondx/reddit.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcsntk/citeseer.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcsntk/cora.json +11 -0
- graphslim-1.0.0/graphslim/configs/gcsntk/flickr.json +13 -0
- graphslim-1.0.0/graphslim/configs/gcsntk/ogbn-arxiv.json +13 -0
- graphslim-1.0.0/graphslim/configs/gcsntk/reddit.json +13 -0
- graphslim-1.0.0/graphslim/configs/geom/citeseer.json +26 -0
- graphslim-1.0.0/graphslim/configs/geom/cora.json +25 -0
- graphslim-1.0.0/graphslim/configs/geom/flickr.json +30 -0
- graphslim-1.0.0/graphslim/configs/geom/ogbn-arxiv.json +27 -0
- graphslim-1.0.0/graphslim/configs/geom/reddit.json +29 -0
- graphslim-1.0.0/graphslim/configs/msgc/citeseer.json +12 -0
- graphslim-1.0.0/graphslim/configs/msgc/cora.json +12 -0
- graphslim-1.0.0/graphslim/configs/msgc/flickr.json +12 -0
- graphslim-1.0.0/graphslim/configs/msgc/ogbn-arxiv.json +12 -0
- graphslim-1.0.0/graphslim/configs/msgc/reddit.json +12 -0
- graphslim-1.0.0/graphslim/configs/sfgc/citeseer.json +12 -0
- graphslim-1.0.0/graphslim/configs/sfgc/cora.json +12 -0
- graphslim-1.0.0/graphslim/configs/sfgc/flickr.json +12 -0
- graphslim-1.0.0/graphslim/configs/sfgc/ogbn-arxiv.json +12 -0
- graphslim-1.0.0/graphslim/configs/sfgc/reddit.json +12 -0
- graphslim-1.0.0/graphslim/configs/sgdd/citeseer.json +16 -0
- graphslim-1.0.0/graphslim/configs/sgdd/cora.json +16 -0
- graphslim-1.0.0/graphslim/configs/sgdd/flickr.json +15 -0
- graphslim-1.0.0/graphslim/configs/sgdd/ogbn-arxiv.json +17 -0
- graphslim-1.0.0/graphslim/configs/sgdd/reddit.json +17 -0
- graphslim-1.0.0/graphslim/configs.py +193 -0
- graphslim-1.0.0/graphslim/dataset/__init__.py +3 -0
- graphslim-1.0.0/graphslim/dataset/attack.py +95 -0
- graphslim-1.0.0/graphslim/dataset/convertor.py +257 -0
- graphslim-1.0.0/graphslim/dataset/loader.py +404 -0
- graphslim-1.0.0/graphslim/dataset/utils.py +374 -0
- graphslim-1.0.0/graphslim/evaluation/__init__.py +3 -0
- graphslim-1.0.0/graphslim/evaluation/eval_agent.py +210 -0
- graphslim-1.0.0/graphslim/evaluation/nas_eval.py +161 -0
- graphslim-1.0.0/graphslim/evaluation/utils.py +145 -0
- graphslim-1.0.0/graphslim/evaluation/vis.py +73 -0
- graphslim-1.0.0/graphslim/models/__init__.py +13 -0
- graphslim-1.0.0/graphslim/models/appnp.py +196 -0
- graphslim-1.0.0/graphslim/models/base.py +212 -0
- graphslim-1.0.0/graphslim/models/cheby.py +29 -0
- graphslim-1.0.0/graphslim/models/gat.py +80 -0
- graphslim-1.0.0/graphslim/models/gcn.py +23 -0
- graphslim-1.0.0/graphslim/models/gntk.py +166 -0
- graphslim-1.0.0/graphslim/models/graphsage.py +149 -0
- graphslim-1.0.0/graphslim/models/ignr.py +213 -0
- graphslim-1.0.0/graphslim/models/krr.py +21 -0
- graphslim-1.0.0/graphslim/models/layers.py +379 -0
- graphslim-1.0.0/graphslim/models/parametrized_adj.py +86 -0
- graphslim-1.0.0/graphslim/models/prbcd.py +445 -0
- graphslim-1.0.0/graphslim/models/random_attack.py +162 -0
- graphslim-1.0.0/graphslim/models/reparam_module.py +150 -0
- graphslim-1.0.0/graphslim/models/sgc.py +86 -0
- graphslim-1.0.0/graphslim/models/sgformer.py +476 -0
- graphslim-1.0.0/graphslim/models/sntk.py +96 -0
- graphslim-1.0.0/graphslim/requirements.txt +18 -0
- graphslim-1.0.0/graphslim/requirements_torch1+.txt +18 -0
- graphslim-1.0.0/graphslim/sparsification/__init__.py +15 -0
- graphslim-1.0.0/graphslim/sparsification/cent_degree.py +28 -0
- graphslim-1.0.0/graphslim/sparsification/cent_pagerank.py +55 -0
- graphslim-1.0.0/graphslim/sparsification/coreset_base.py +46 -0
- graphslim-1.0.0/graphslim/sparsification/edge_sparsification_base.py +34 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_citeseer_0.1_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_citeseer_0.25_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_citeseer_0.5_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_citeseer_1.0_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_cora_0.1_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_cora_0.25_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_cora_0.5_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_cora_1.0_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_flickr_0.001_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_flickr_0.005_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_flickr_0.01_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.001_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.005_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.01_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_reddit_0.0005_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_reddit_0.001_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_reddit_0.002_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/fixed_idx/idx_reddit_0.005_kcenter_15.npy +0 -0
- graphslim-1.0.0/graphslim/sparsification/g_spar.py +21 -0
- graphslim-1.0.0/graphslim/sparsification/herding.py +25 -0
- graphslim-1.0.0/graphslim/sparsification/herding_agg.py +25 -0
- graphslim-1.0.0/graphslim/sparsification/kcenter.py +24 -0
- graphslim-1.0.0/graphslim/sparsification/kcenter_agg.py +27 -0
- graphslim-1.0.0/graphslim/sparsification/kcenter_sample.py +79 -0
- graphslim-1.0.0/graphslim/sparsification/local_degree.py +21 -0
- graphslim-1.0.0/graphslim/sparsification/model_based_coreset_base.py +63 -0
- graphslim-1.0.0/graphslim/sparsification/model_free_coreset_base.py +61 -0
- graphslim-1.0.0/graphslim/sparsification/random.py +17 -0
- graphslim-1.0.0/graphslim/sparsification/random_edge.py +21 -0
- graphslim-1.0.0/graphslim/sparsification/rank_degree.py +68 -0
- graphslim-1.0.0/graphslim/sparsification/scan.py +21 -0
- graphslim-1.0.0/graphslim/sparsification/spanning_forest.py +19 -0
- graphslim-1.0.0/graphslim/sparsification/t_spanner.py +28 -0
- graphslim-1.0.0/graphslim/sparsification/utils.py +0 -0
- graphslim-1.0.0/graphslim/train_all.py +69 -0
- graphslim-1.0.0/graphslim/utils.py +946 -0
- graphslim-1.0.0/graphslim.egg-info/PKG-INFO +33 -0
- graphslim-1.0.0/graphslim.egg-info/SOURCES.txt +152 -0
- graphslim-1.0.0/graphslim.egg-info/dependency_links.txt +1 -0
- graphslim-1.0.0/graphslim.egg-info/requires.txt +17 -0
- graphslim-1.0.0/graphslim.egg-info/top_level.txt +1 -0
- graphslim-1.0.0/setup.cfg +4 -0
- graphslim-1.0.0/setup.py +51 -0
graphslim-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: graphslim
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Slimming the graph data for graph learning
|
|
5
|
+
Author: Rockcor
|
|
6
|
+
Author-email: jshmhsb@gmail.com
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Intended Audience :: Education
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
13
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Requires-Python: >=3.8
|
|
17
|
+
Requires-Dist: click>=8.1.0
|
|
18
|
+
Requires-Dist: deeprobust==0.2.10
|
|
19
|
+
Requires-Dist: gdown==5.2.0
|
|
20
|
+
Requires-Dist: matplotlib>=3.8.4
|
|
21
|
+
Requires-Dist: networkit>=11.0
|
|
22
|
+
Requires-Dist: networkx>=3.1
|
|
23
|
+
Requires-Dist: numpy>=2.0.0
|
|
24
|
+
Requires-Dist: ogb>=1.3.0
|
|
25
|
+
Requires-Dist: PyGSP==0.5.1
|
|
26
|
+
Requires-Dist: scikit_learn>=1.4.0
|
|
27
|
+
Requires-Dist: scipy>=1.14.0
|
|
28
|
+
Requires-Dist: sortedcontainers>=2.4.0
|
|
29
|
+
Requires-Dist: torch>=2.0.0
|
|
30
|
+
Requires-Dist: torch_geometric>=2.4.0
|
|
31
|
+
Requires-Dist: torch_scatter==2.1.2
|
|
32
|
+
Requires-Dist: torch_sparse==0.6.18
|
|
33
|
+
Requires-Dist: tqdm>=4.0.0
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
# GraphSlim
|
|
2
|
+
|
|
3
|
+
[](https://graphslim.readthedocs.io/en/latest/?badge=latest)
|
|
4
|
+
|
|
5
|
+
**[Benchmark Paper](https://arxiv.org/abs/2406.16715)** |
|
|
6
|
+
**[Benchmark Scripts](https://github.com/Emory-Melody/GraphSlim/tree/main/benchmark)** |
|
|
7
|
+
**[Survey Paper](https://arxiv.org/pdf/2402.03358)** |
|
|
8
|
+
**[Paper Collection](https://github.com/Emory-Melody/awesome-graph-reduction)** |
|
|
9
|
+
**[Web Interface](https://graphslim-vis.streamlit.app/)**
|
|
10
|
+
|
|
11
|
+
# Features
|
|
12
|
+
|
|
13
|
+
GraphSlim is a PyTorch library for graph reduction. It takes graph of PyG format as input and outputs a reduced graph
|
|
14
|
+
preserving **properties or performance** of the original graph.
|
|
15
|
+
|
|
16
|
+
* Covering representative methods of all 3 graph reduction strategies: Sparsification, Coarsening and Condensation.
|
|
17
|
+
* Different reduction strategies can be easily combined in one run.
|
|
18
|
+
* Unified evaluation tools including Grid Search and NAS.
|
|
19
|
+
* Support evasion and poisoning attacks on the input graph by DeepRobust.
|
|
20
|
+
|
|
21
|
+
# Guidance
|
|
22
|
+
|
|
23
|
+
* Please first prepare the environments.
|
|
24
|
+
* If you are new to GraphSlim, we highly suggest you first run the examples in the `examples` folder.
|
|
25
|
+
* If you have any questions or suggestions regarding this library, feel free to create an
|
|
26
|
+
issue [here](https://github.com/Emory-Melody/GraphSlim/issues). We will reply as soon as possible :)
|
|
27
|
+
|
|
28
|
+
# Prepare Environments
|
|
29
|
+
|
|
30
|
+
Please choose from `requirements_torch1+.txt (torch 1.\*)` and `requirements.txt (torch2.*)` at your convenience.
|
|
31
|
+
Please change the cuda version of `torch`, `torch-geometric` and `torch-sparse` in the requirements file according to
|
|
32
|
+
your system configuration.
|
|
33
|
+
|
|
34
|
+
<!--# Download Datasets
|
|
35
|
+
|
|
36
|
+
For cora, citeseer, flickr and reddit (reddit2 in pyg), the pyg code will directly download them.
|
|
37
|
+
For arxiv, we use the datasets provided by [GraphSAINT](https://github.com/GraphSAINT/GraphSAINT).
|
|
38
|
+
Our code will automatically download all datasets.
|
|
39
|
+
|
|
40
|
+
The default path of datasets is `../../data`.-->
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
[//]: # (# Installation)
|
|
44
|
+
|
|
45
|
+
[//]: # ()
|
|
46
|
+
|
|
47
|
+
[//]: # (## Install from pip)
|
|
48
|
+
|
|
49
|
+
[//]: # ()
|
|
50
|
+
|
|
51
|
+
[//]: # (```)
|
|
52
|
+
|
|
53
|
+
[//]: # (pip install graphslim)
|
|
54
|
+
|
|
55
|
+
[//]: # (```)
|
|
56
|
+
|
|
57
|
+
# Examples
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
python examples/train_coreset.py
|
|
61
|
+
python examples/train_coarsen.py
|
|
62
|
+
python examples/train_gcond.py
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
See more examples in **[Benchmark Scripts](https://github.com/Emory-Melody/GraphSlim/tree/main/benchmark)**.
|
|
66
|
+
|
|
67
|
+
# Use As Project
|
|
68
|
+
```shell
|
|
69
|
+
cd graphslim
|
|
70
|
+
python train_all.py -xxx xx
|
|
71
|
+
```
|
|
72
|
+
Run `python configs.py --help` to get all command line options.
|
|
73
|
+
```shell
|
|
74
|
+
Options:
|
|
75
|
+
-D, --dataset TEXT [default: cora]
|
|
76
|
+
-G, --gpu_id INTEGER gpu id start from 0, -1 means cpu [default:
|
|
77
|
+
0]
|
|
78
|
+
--setting [trans|ind] transductive or inductive setting
|
|
79
|
+
--split TEXT only support public split now, do not change
|
|
80
|
+
it [default: fixed]
|
|
81
|
+
--run_reduction INTEGER repeat times of reduction [default: 3]
|
|
82
|
+
--run_eval INTEGER repeat times of final evaluations [default:
|
|
83
|
+
10]
|
|
84
|
+
--run_inter_eval INTEGER repeat times of intermediate evaluations
|
|
85
|
+
[default: 5]
|
|
86
|
+
--eval_interval INTEGER [default: 100]
|
|
87
|
+
-H, --hidden INTEGER [default: 256]
|
|
88
|
+
--eval_epochs, --ee INTEGER [default: 300]
|
|
89
|
+
--eval_model, --em [GCN|GAT|SGC|APPNP|Cheby|GraphSage|GAT|SGFormer]
|
|
90
|
+
[default: GCN]
|
|
91
|
+
--condense_model [GCN|GAT|SGC|APPNP|Cheby|GraphSage|GAT]
|
|
92
|
+
[default: SGC]
|
|
93
|
+
-E, --epochs INTEGER number of reduction epochs [default: 1000]
|
|
94
|
+
--lr FLOAT [default: 0.01]
|
|
95
|
+
--weight_decay, --wd INTEGER [default: 0]
|
|
96
|
+
--pre_norm BOOLEAN pre-normalize features, forced true for
|
|
97
|
+
arxiv, flickr and reddit [default: True]
|
|
98
|
+
--outer_loop INTEGER [default: 10]
|
|
99
|
+
--inner_loop INTEGER [default: 1]
|
|
100
|
+
-R, --reduction_rate FLOAT -1 means use representative reduction rate;
|
|
101
|
+
reduction rate of training set, defined as
|
|
102
|
+
(number of nodes in small graph)/(number of
|
|
103
|
+
nodes in original graph) [default: -1.0]
|
|
104
|
+
-S, --seed INTEGER Random seed [default: 1]
|
|
105
|
+
--nlayers INTEGER number of GNN layers of condensed model
|
|
106
|
+
[default: 2]
|
|
107
|
+
-V, --verbose
|
|
108
|
+
--init [variation_neighborhoods|variation_edges|variation_cliques|heavy_edge|algebraic_JC|affinity_GS|kron|vng|clustering|averaging|cent_d|cent_p|kcenter|herding|random]
|
|
109
|
+
features initialization methods
|
|
110
|
+
-M, --method [variation_neighborhoods|variation_edges|variation_cliques|heavy_edge|algebraic_JC|affinity_GS|kron|vng|clustering|averaging|gcond|doscond|gcondx|doscondx|sfgc|msgc|disco|sgdd|gcsntk|geom|cent_d|cent_p|kcenter|herding|random]
|
|
111
|
+
[default: kcenter]
|
|
112
|
+
--activation [sigmoid|tanh|relu|linear|softplus|leakyrelu|relu6|elu]
|
|
113
|
+
activation function when do NAS [default:
|
|
114
|
+
relu]
|
|
115
|
+
-A, --attack [random_adj|metattack|random_feat]
|
|
116
|
+
corruption method
|
|
117
|
+
-P, --ptb_r FLOAT perturbation rate for corruptions [default:
|
|
118
|
+
0.25]
|
|
119
|
+
--aggpreprocess use aggregation for coreset methods
|
|
120
|
+
--dis_metric TEXT distance metric for all condensation
|
|
121
|
+
methods,ours means metric used in GCond
|
|
122
|
+
paper [default: ours]
|
|
123
|
+
--lr_adj FLOAT [default: 0.0001]
|
|
124
|
+
--lr_feat FLOAT [default: 0.0001]
|
|
125
|
+
--threshold INTEGER sparsificaiton threshold before evaluation
|
|
126
|
+
[default: 0]
|
|
127
|
+
--dropout FLOAT [default: 0.0]
|
|
128
|
+
--ntrans INTEGER number of transformations in SGC and APPNP
|
|
129
|
+
[default: 1]
|
|
130
|
+
--with_bn
|
|
131
|
+
--no_buff skip the buffer generation and use existing
|
|
132
|
+
in geom,sfgc
|
|
133
|
+
--batch_adj INTEGER batch size for msgc [default: 1]
|
|
134
|
+
--alpha FLOAT for appnp [default: 0.1]
|
|
135
|
+
--mx_size INTEGER for gcsntk methods, avoid SVD error
|
|
136
|
+
[default: 100]
|
|
137
|
+
--save_path, --sp TEXT save path for synthetic graph [default:
|
|
138
|
+
../checkpoints]
|
|
139
|
+
-W, --eval_whole if run on whole graph
|
|
140
|
+
--help Show this message and exit.
|
|
141
|
+
```
|
|
142
|
+
# Use As Package
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from graphslim.dataset import *
|
|
146
|
+
from graphslim.evaluation import *
|
|
147
|
+
from graphslim.sparsification/coarsening/condensation import <main:method>
|
|
148
|
+
|
|
149
|
+
graph = get_dataset(<main:dataset>, <dataset_args>)
|
|
150
|
+
# To reproduce the benchmark, use our args and graph class
|
|
151
|
+
# To use your own args and graph format, please ensure the args and graph class has the required attributes
|
|
152
|
+
|
|
153
|
+
# create an agent of one reduction algorithm
|
|
154
|
+
agent = <main:method>(setting=<'trans/ind'>, data=graph, args=<agent_args>)
|
|
155
|
+
# reduce the graph
|
|
156
|
+
reduced_graph = agent.reduce(graph, verbose=<True/False>)
|
|
157
|
+
# create an evaluator
|
|
158
|
+
evaluator = Evaluator(<evaluator_args>)
|
|
159
|
+
# evaluate the reduced graph on a GNN model
|
|
160
|
+
res_mean, res_std = evaluator.evaluate(reduced_graph, model_type=<evaluator:eval_model>)
|
|
161
|
+
```
|
|
162
|
+
All parameters can be divided into
|
|
163
|
+
```shell
|
|
164
|
+
<main_args>: dataset, method, setting, init, reduction_rate, seed, aggpreprocess, eval_whole, run_reduction
|
|
165
|
+
<attack_args>: attack, ptb_r
|
|
166
|
+
<dataset_args>: pre_norm, save_path, split, threshold
|
|
167
|
+
<agent_args>: eval_interval, eval_epochs, eval_model, condense_model, epochs, lr, weight_decay, outer_loop, inner_loop, nlayers, method, activation, dropout, ntrans, with_bn, no_buff, batch_adj, alpha, mx_size, dis_metric, lr_adj, lr_feat
|
|
168
|
+
<evaluator_args>: final_eval_model, eval_epochs, lr, weight_decay
|
|
169
|
+
```
|
|
170
|
+
See more details in [](https://graphslim.readthedocs.io/en/latest/?badge=latest)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# Customization
|
|
174
|
+
|
|
175
|
+
* To implement a new reduction algorithm, you need to create a new class in `sparsification` or `coarsening`
|
|
176
|
+
or `condensation` and inherit the `Base` class.
|
|
177
|
+
* To implement a new dataset, you need to create a new class in `dataset/loader.py` and inherit the `TransAndInd` class.
|
|
178
|
+
* To implement a new evaluation metric, you need to create a new function in `evaluation/eval_agent.py`.
|
|
179
|
+
* To implement a new GNN model, you need to create a new class in `models` and inherit the `Base` class.
|
|
180
|
+
* To customize sparsification before evaluation, please modify the function `sparsify` in `evaluation/utils.py`.
|
|
181
|
+
|
|
182
|
+
# Web Interface
|
|
183
|
+
|
|
184
|
+
Our [web application](https://graphslim-vis.streamlit.app/) is deployed online using [streamlit](https://streamlit.io/).
|
|
185
|
+
But it also can be initiated using:
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
cd interface
|
|
189
|
+
python -m streamlit run vis_graphslim.py
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
to activate the interface. Please satisfy the dependency in [interface/requirements.txt](interface/requirements.txt).
|
|
193
|
+
|
|
194
|
+
# TODO
|
|
195
|
+
|
|
196
|
+
- [ ] Add sparsification algorithms like Spanner
|
|
197
|
+
- [ ] Add latest condensation methods
|
|
198
|
+
- [ ] Support more datasets
|
|
199
|
+
- [ ] Present full results in a website
|
|
200
|
+
|
|
201
|
+
# Limitations
|
|
202
|
+
|
|
203
|
+
* The GEOM and SFGC are not fully implemented in the current version due to disk space limit. We set the number of
|
|
204
|
+
experts to 20 currently. If you have over 100GB disk space, you can set the number of experts to 1000 to reproduce the
|
|
205
|
+
If you have over 100GB disk space, you can set the number of experts to 200 to reproduce the results in the paper.
|
|
206
|
+
|
|
207
|
+
# Acknowledgement
|
|
208
|
+
|
|
209
|
+
Some of the algorithms are referred to paper authors' implementations and other packages.
|
|
210
|
+
|
|
211
|
+
[SCAL](https://github.com/szzhang17/Scaling-Up-Graph-Neural-Networks-Via-Graph-Coarsening)
|
|
212
|
+
|
|
213
|
+
[GCOND](https://github.com/ChandlerBang/GCond)
|
|
214
|
+
|
|
215
|
+
[GCSNTK](https://github.com/WANGLin0126/GCSNTK)
|
|
216
|
+
|
|
217
|
+
[SFGC](https://github.com/Amanda-Zheng/SFGC)
|
|
218
|
+
|
|
219
|
+
[GEOM](https://github.com/NUS-HPC-AI-Lab/GEOM/tree/main)
|
|
220
|
+
|
|
221
|
+
[DeepRobust](https://github.com/DSE-MSU/DeepRobust)
|
|
222
|
+
|
|
File without changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from .coarsening_base import Coarsen
|
|
2
|
+
from .vng import VNG
|
|
3
|
+
from .clustering import Cluster
|
|
4
|
+
from .clusteringagg import ClusterAgg
|
|
5
|
+
from .averaging import Average
|
|
6
|
+
from .variation_neighborhoods import VariationNeighborhoods
|
|
7
|
+
from .variation_edges import VariationEdges
|
|
8
|
+
from .variation_cliques import VariationCliques
|
|
9
|
+
from .heavy_edge import HeavyEdge
|
|
10
|
+
from .algebraic_jc import AlgebraicJc
|
|
11
|
+
from .affinity_gs import AffinityGs
|
|
12
|
+
from .kron import Kron
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import scipy as sp
|
|
5
|
+
import torch
|
|
6
|
+
from pygsp import graphs
|
|
7
|
+
from torch_geometric.utils import to_dense_adj
|
|
8
|
+
|
|
9
|
+
from graphslim.coarsening.utils import contract_variation_edges, contract_variation_linear, get_proximity_measure, \
|
|
10
|
+
matching_optimal, matching_greedy, get_coarsening_matrix, coarsen_matrix, coarsen_vector, zero_diag
|
|
11
|
+
from graphslim.dataset.convertor import pyg2gsp, csr2ei, ei2csr
|
|
12
|
+
from graphslim.dataset.utils import save_reduced
|
|
13
|
+
from graphslim.evaluation import *
|
|
14
|
+
from graphslim.utils import one_hot, to_tensor
|
|
15
|
+
from graphslim.coarsening.coarsening_base import Coarsen
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AffinityGs(Coarsen):
|
|
19
|
+
|
|
20
|
+
def coarsen(self, G):
|
|
21
|
+
"""
|
|
22
|
+
This function provides a common interface for coarsening algorithms that contract subgraphs
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
G : pygsp Graph
|
|
27
|
+
K : int
|
|
28
|
+
The size of the subspace we are interested in preserving.
|
|
29
|
+
r : float between (0,1)
|
|
30
|
+
The desired reduction defined as 1 - n/N.
|
|
31
|
+
method : String
|
|
32
|
+
['variation_neighborhoods', 'variation_edges', 'variation_cliques', 'heavy_edge', 'algebraic_JC', 'affinity_GS', 'kron']
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
C : np.array of size n x N
|
|
37
|
+
The coarsening matrix.
|
|
38
|
+
Gc : pygsp Graph
|
|
39
|
+
The smaller graph.
|
|
40
|
+
Call : list of np.arrays
|
|
41
|
+
Coarsening matrices for each level
|
|
42
|
+
Gall : list of (n_levels+1) pygsp Graphs
|
|
43
|
+
All graphs involved in the multilevel coarsening
|
|
44
|
+
|
|
45
|
+
Example
|
|
46
|
+
-------
|
|
47
|
+
C, Gc, Call, Gall = coarsen(G, K=10, r=0.8)
|
|
48
|
+
"""
|
|
49
|
+
K = 10
|
|
50
|
+
r = 0.5
|
|
51
|
+
max_levels = 10
|
|
52
|
+
Uk = None
|
|
53
|
+
lk = None
|
|
54
|
+
max_level_r = 0.99,
|
|
55
|
+
r = np.clip(r, 0, 0.999)
|
|
56
|
+
G0 = G
|
|
57
|
+
N = G.N
|
|
58
|
+
|
|
59
|
+
# current and target graph sizes
|
|
60
|
+
n, n_target = N, np.ceil((1 - r) * N)
|
|
61
|
+
|
|
62
|
+
C = sp.sparse.eye(N, format="csc")
|
|
63
|
+
Gc = G
|
|
64
|
+
|
|
65
|
+
Call, Gall = [], []
|
|
66
|
+
Gall.append(G)
|
|
67
|
+
method = "affinity_GS"
|
|
68
|
+
algorithm=self.args.coarsen_strategy
|
|
69
|
+
# algorithm = "greedy"
|
|
70
|
+
for level in range(1, max_levels + 1):
|
|
71
|
+
|
|
72
|
+
G = Gc
|
|
73
|
+
|
|
74
|
+
# how much more we need to reduce the current graph
|
|
75
|
+
r_cur = np.clip(1 - n_target / n, 0.0, max_level_r)
|
|
76
|
+
|
|
77
|
+
weights = get_proximity_measure(G, method, K=K)
|
|
78
|
+
|
|
79
|
+
if algorithm == "optimal":
|
|
80
|
+
# the edge-weight should be light at proximal edges
|
|
81
|
+
weights = -weights
|
|
82
|
+
if "rss" not in method:
|
|
83
|
+
weights -= min(weights)
|
|
84
|
+
coarsening_list = matching_optimal(G, weights=weights, r=r_cur)
|
|
85
|
+
|
|
86
|
+
elif algorithm == "greedy":
|
|
87
|
+
coarsening_list = matching_greedy(G, weights=weights, r=r_cur)
|
|
88
|
+
iC = get_coarsening_matrix(G, coarsening_list)
|
|
89
|
+
|
|
90
|
+
if iC.shape[1] - iC.shape[0] <= 2:
|
|
91
|
+
break # avoid too many levels for so few nodes
|
|
92
|
+
|
|
93
|
+
C = iC.dot(C)
|
|
94
|
+
Call.append(iC)
|
|
95
|
+
|
|
96
|
+
Wc = zero_diag(coarsen_matrix(G.W, iC)) # coarsen and remove self-loops
|
|
97
|
+
Wc = (Wc + Wc.T) / 2 # this is only needed to avoid pygsp complaining for tiny errors
|
|
98
|
+
|
|
99
|
+
if not hasattr(G, "coords"):
|
|
100
|
+
Gc = graphs.Graph(Wc)
|
|
101
|
+
else:
|
|
102
|
+
Gc = graphs.Graph(Wc, coords=coarsen_vector(G.coords, iC))
|
|
103
|
+
Gall.append(Gc)
|
|
104
|
+
|
|
105
|
+
n = Gc.N
|
|
106
|
+
|
|
107
|
+
if n <= n_target:
|
|
108
|
+
break
|
|
109
|
+
|
|
110
|
+
return C, Gc, Call, Gall
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import scipy as sp
|
|
5
|
+
import torch
|
|
6
|
+
from pygsp import graphs
|
|
7
|
+
from torch_geometric.utils import to_dense_adj
|
|
8
|
+
|
|
9
|
+
from graphslim.coarsening.utils import contract_variation_edges, contract_variation_linear, get_proximity_measure, \
|
|
10
|
+
matching_optimal, matching_greedy, get_coarsening_matrix, coarsen_matrix, coarsen_vector, zero_diag
|
|
11
|
+
from graphslim.dataset.convertor import pyg2gsp, csr2ei, ei2csr
|
|
12
|
+
from graphslim.dataset.utils import save_reduced
|
|
13
|
+
from graphslim.evaluation import *
|
|
14
|
+
from graphslim.utils import one_hot, to_tensor
|
|
15
|
+
from graphslim.coarsening.coarsening_base import Coarsen
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class AlgebraicJc(Coarsen):
|
|
19
|
+
|
|
20
|
+
def coarsen(self, G):
|
|
21
|
+
"""
|
|
22
|
+
This function provides a common interface for coarsening algorithms that contract subgraphs
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
G : pygsp Graph
|
|
27
|
+
K : int
|
|
28
|
+
The size of the subspace we are interested in preserving.
|
|
29
|
+
r : float between (0,1)
|
|
30
|
+
The desired reduction defined as 1 - n/N.
|
|
31
|
+
method : String
|
|
32
|
+
['variation_neighborhoods', 'variation_edges', 'variation_cliques', 'heavy_edge', 'algebraic_JC', 'affinity_GS', 'kron']
|
|
33
|
+
|
|
34
|
+
Returns
|
|
35
|
+
-------
|
|
36
|
+
C : np.array of size n x N
|
|
37
|
+
The coarsening matrix.
|
|
38
|
+
Gc : pygsp Graph
|
|
39
|
+
The smaller graph.
|
|
40
|
+
Call : list of np.arrays
|
|
41
|
+
Coarsening matrices for each level
|
|
42
|
+
Gall : list of (n_levels+1) pygsp Graphs
|
|
43
|
+
All graphs involved in the multilevel coarsening
|
|
44
|
+
|
|
45
|
+
Example
|
|
46
|
+
-------
|
|
47
|
+
C, Gc, Call, Gall = coarsen(G, K=10, r=0.8)
|
|
48
|
+
"""
|
|
49
|
+
K = 10
|
|
50
|
+
r = 0.5
|
|
51
|
+
max_levels = 10
|
|
52
|
+
Uk = None
|
|
53
|
+
lk = None
|
|
54
|
+
max_level_r = 0.99,
|
|
55
|
+
r = np.clip(r, 0, 0.999)
|
|
56
|
+
G0 = G
|
|
57
|
+
N = G.N
|
|
58
|
+
|
|
59
|
+
# current and target graph sizes
|
|
60
|
+
n, n_target = N, np.ceil((1 - r) * N)
|
|
61
|
+
|
|
62
|
+
C = sp.sparse.eye(N, format="csc")
|
|
63
|
+
Gc = G
|
|
64
|
+
|
|
65
|
+
Call, Gall = [], []
|
|
66
|
+
Gall.append(G)
|
|
67
|
+
method = "algebraic_JC"
|
|
68
|
+
algorithm=self.args.coarsen_strategy
|
|
69
|
+
# algorithm = "greedy"
|
|
70
|
+
for level in range(1, max_levels + 1):
|
|
71
|
+
|
|
72
|
+
G = Gc
|
|
73
|
+
|
|
74
|
+
# how much more we need to reduce the current graph
|
|
75
|
+
r_cur = np.clip(1 - n_target / n, 0.0, max_level_r)
|
|
76
|
+
|
|
77
|
+
weights = get_proximity_measure(G, method, K=K)
|
|
78
|
+
|
|
79
|
+
if algorithm == "optimal":
|
|
80
|
+
# the edge-weight should be light at proximal edges
|
|
81
|
+
weights = -weights
|
|
82
|
+
if "rss" not in method:
|
|
83
|
+
weights -= min(weights)
|
|
84
|
+
coarsening_list = matching_optimal(G, weights=weights, r=r_cur)
|
|
85
|
+
|
|
86
|
+
elif algorithm == "greedy":
|
|
87
|
+
coarsening_list = matching_greedy(G, weights=weights, r=r_cur)
|
|
88
|
+
iC = get_coarsening_matrix(G, coarsening_list)
|
|
89
|
+
|
|
90
|
+
if iC.shape[1] - iC.shape[0] <= 2:
|
|
91
|
+
break # avoid too many levels for so few nodes
|
|
92
|
+
|
|
93
|
+
C = iC.dot(C)
|
|
94
|
+
Call.append(iC)
|
|
95
|
+
|
|
96
|
+
Wc = zero_diag(coarsen_matrix(G.W, iC)) # coarsen and remove self-loops
|
|
97
|
+
Wc = (Wc + Wc.T) / 2 # this is only needed to avoid pygsp complaining for tiny errors
|
|
98
|
+
|
|
99
|
+
if not hasattr(G, "coords"):
|
|
100
|
+
Gc = graphs.Graph(Wc)
|
|
101
|
+
else:
|
|
102
|
+
Gc = graphs.Graph(Wc, coords=coarsen_vector(G.coords, iC))
|
|
103
|
+
Gall.append(Gc)
|
|
104
|
+
|
|
105
|
+
n = Gc.N
|
|
106
|
+
|
|
107
|
+
if n <= n_target:
|
|
108
|
+
break
|
|
109
|
+
|
|
110
|
+
return C, Gc, Call, Gall
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
from collections import Counter
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import torch
|
|
5
|
+
|
|
6
|
+
from graphslim.coarsening.coarsening_base import Coarsen
|
|
7
|
+
from graphslim.dataset.utils import save_reduced
|
|
8
|
+
from graphslim.evaluation.utils import verbose_time_memory
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class Average(Coarsen):
|
|
12
|
+
# a structure free coarsening method
|
|
13
|
+
# also serve as initialization for condensation methods
|
|
14
|
+
# output: feat_syn, label_syn
|
|
15
|
+
def __init__(self, setting, data, args, **kwargs):
|
|
16
|
+
super(Average, self).__init__(setting, data, args, **kwargs)
|
|
17
|
+
|
|
18
|
+
@verbose_time_memory
|
|
19
|
+
def reduce(self, data, verbose=True, save=True):
|
|
20
|
+
args = self.args
|
|
21
|
+
n_classes = data.nclass
|
|
22
|
+
if hasattr(data, 'labels_syn'):
|
|
23
|
+
y_syn = data.labels_syn
|
|
24
|
+
self.labels_train = data.labels_train
|
|
25
|
+
y_train = data.labels_train
|
|
26
|
+
x_train = data.feat_train
|
|
27
|
+
else:
|
|
28
|
+
y_syn, y_train, x_train = self.prepare_select(data, args)
|
|
29
|
+
x_syn = torch.zeros(y_syn.shape[0], x_train.shape[1])
|
|
30
|
+
for c in range(n_classes):
|
|
31
|
+
x_c = x_train[y_train == c]
|
|
32
|
+
x_syn[y_syn == c] = x_c.mean(0)
|
|
33
|
+
data.feat_syn, data.labels_syn = x_syn.to(x_train.device), y_syn
|
|
34
|
+
data.adj_syn = torch.eye(data.feat_syn.shape[0])
|
|
35
|
+
if save:
|
|
36
|
+
save_reduced(data.adj_syn, data.feat_syn, data.labels_syn, args)
|
|
37
|
+
return data
|
|
38
|
+
|
|
39
|
+
def prepare_select(self, data, args):
|
|
40
|
+
num_class_dict = {}
|
|
41
|
+
syn_class_indices = {}
|
|
42
|
+
feat_train = data.feat_train
|
|
43
|
+
|
|
44
|
+
labels_train = data.labels_train
|
|
45
|
+
# d = data.feat_train.shape[1]
|
|
46
|
+
counter = Counter(data.labels_train.tolist())
|
|
47
|
+
# n = len(data.labels_train)
|
|
48
|
+
sorted_counter = sorted(counter.items(), key=lambda x: x[1])
|
|
49
|
+
sum_ = 0
|
|
50
|
+
labels_syn = []
|
|
51
|
+
for ix, (c, num) in enumerate(sorted_counter):
|
|
52
|
+
num_class_dict[c] = max(int(num * args.reduction_rate), 1)
|
|
53
|
+
sum_ += num_class_dict[c]
|
|
54
|
+
syn_class_indices[c] = [len(labels_syn), len(labels_syn) + num_class_dict[c]]
|
|
55
|
+
labels_syn += [c] * num_class_dict[c]
|
|
56
|
+
labels_syn = np.array(labels_syn)
|
|
57
|
+
|
|
58
|
+
return labels_syn, labels_train, feat_train
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from collections import Counter
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
import torch
|
|
5
|
+
from sklearn.cluster import BisectingKMeans
|
|
6
|
+
from torch_scatter import scatter_mean
|
|
7
|
+
|
|
8
|
+
from graphslim.coarsening.coarsening_base import Coarsen
|
|
9
|
+
from graphslim.dataset.utils import save_reduced
|
|
10
|
+
from graphslim.evaluation.utils import verbose_time_memory
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class Cluster(Coarsen):
|
|
14
|
+
# a structure free coarsening method
|
|
15
|
+
# also serve as initialization for condensation methods
|
|
16
|
+
# output: feat_syn, label_syn
|
|
17
|
+
def __init__(self, setting, data, args, **kwargs):
|
|
18
|
+
super(Cluster, self).__init__(setting, data, args, **kwargs)
|
|
19
|
+
|
|
20
|
+
@verbose_time_memory
|
|
21
|
+
def reduce(self, data, verbose=True, save=True):
|
|
22
|
+
args = self.args
|
|
23
|
+
n_classes = data.nclass
|
|
24
|
+
if hasattr(data, 'labels_syn') and data.labels_syn is not None:
|
|
25
|
+
y_syn = data.labels_syn
|
|
26
|
+
self.labels_train = data.labels_train
|
|
27
|
+
y_train = data.labels_train
|
|
28
|
+
x_train = data.feat_train
|
|
29
|
+
else:
|
|
30
|
+
y_syn, y_train, x_train = self.prepare_select(data, args)
|
|
31
|
+
x_syn = torch.zeros(y_syn.shape[0], x_train.shape[1])
|
|
32
|
+
for c in range(n_classes):
|
|
33
|
+
x_c = x_train[y_train == c].cpu()
|
|
34
|
+
n_c = (y_syn == c).sum().item()
|
|
35
|
+
k_means = BisectingKMeans(n_clusters=n_c, random_state=0)
|
|
36
|
+
k_means.fit(x_c)
|
|
37
|
+
clusters = torch.from_numpy(k_means.predict(x_c)).long()
|
|
38
|
+
x_syn[y_syn == c] = scatter_mean(x_c, clusters, dim=0)
|
|
39
|
+
data.feat_syn, data.labels_syn = x_syn.to(x_train.device), y_syn
|
|
40
|
+
data.adj_syn = torch.eye(data.feat_syn.shape[0])
|
|
41
|
+
if save:
|
|
42
|
+
save_reduced(data.adj_syn, data.feat_syn, data.labels_syn, args)
|
|
43
|
+
return data
|
|
44
|
+
|
|
45
|
+
def prepare_select(self, data, args):
|
|
46
|
+
num_class_dict = {}
|
|
47
|
+
syn_class_indices = {}
|
|
48
|
+
feat_train = data.feat_train
|
|
49
|
+
|
|
50
|
+
labels_train = data.labels_train
|
|
51
|
+
# d = data.feat_train.shape[1]
|
|
52
|
+
counter = Counter(data.labels_train.tolist())
|
|
53
|
+
# n = len(data.labels_train)
|
|
54
|
+
sorted_counter = sorted(counter.items(), key=lambda x: x[1])
|
|
55
|
+
sum_ = 0
|
|
56
|
+
labels_syn = []
|
|
57
|
+
for ix, (c, num) in enumerate(sorted_counter):
|
|
58
|
+
num_class_dict[c] = max(int(num * args.reduction_rate), 1)
|
|
59
|
+
sum_ += num_class_dict[c]
|
|
60
|
+
syn_class_indices[c] = [len(labels_syn), len(labels_syn) + num_class_dict[c]]
|
|
61
|
+
labels_syn += [c] * num_class_dict[c]
|
|
62
|
+
labels_syn = np.array(labels_syn)
|
|
63
|
+
|
|
64
|
+
return labels_syn, labels_train, feat_train
|