graphslim 1.0.1__py3-none-any.whl
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.
- graphslim/__init__.py +0 -0
- graphslim/coarsening/__init__.py +12 -0
- graphslim/coarsening/affinity_gs.py +110 -0
- graphslim/coarsening/algebraic_jc.py +110 -0
- graphslim/coarsening/averaging.py +58 -0
- graphslim/coarsening/clustering.py +64 -0
- graphslim/coarsening/clusteringagg.py +77 -0
- graphslim/coarsening/coarsening_base.py +246 -0
- graphslim/coarsening/heavy_edge.py +110 -0
- graphslim/coarsening/kron.py +109 -0
- graphslim/coarsening/utils.py +2002 -0
- graphslim/coarsening/variation_cliques.py +131 -0
- graphslim/coarsening/variation_edges.py +131 -0
- graphslim/coarsening/variation_neighborhoods.py +131 -0
- graphslim/coarsening/vng.py +118 -0
- graphslim/condensation/__init__.py +9 -0
- graphslim/condensation/doscond.py +64 -0
- graphslim/condensation/doscondx.py +59 -0
- graphslim/condensation/gcond.py +80 -0
- graphslim/condensation/gcond_base.py +186 -0
- graphslim/condensation/gcondx.py +76 -0
- graphslim/condensation/gcsntk.py +160 -0
- graphslim/condensation/geom.py +449 -0
- graphslim/condensation/msgc.py +244 -0
- graphslim/condensation/sfgc.py +215 -0
- graphslim/condensation/sgdd.py +102 -0
- graphslim/condensation/utils.py +236 -0
- graphslim/configs/doscond/citeseer.json +8 -0
- graphslim/configs/doscond/cora.json +8 -0
- graphslim/configs/doscond/flickr.json +8 -0
- graphslim/configs/doscond/ogbn-arxiv.json +9 -0
- graphslim/configs/doscond/reddit.json +9 -0
- graphslim/configs/doscondx/citeseer.json +8 -0
- graphslim/configs/doscondx/cora.json +8 -0
- graphslim/configs/doscondx/flickr.json +7 -0
- graphslim/configs/doscondx/ogbn-arxiv.json +8 -0
- graphslim/configs/doscondx/reddit.json +7 -0
- graphslim/configs/gcond/citeseer.json +11 -0
- graphslim/configs/gcond/cora.json +11 -0
- graphslim/configs/gcond/flickr.json +10 -0
- graphslim/configs/gcond/ogbn-arxiv.json +11 -0
- graphslim/configs/gcond/reddit.json +11 -0
- graphslim/configs/gcondx/citeseer.json +8 -0
- graphslim/configs/gcondx/cora.json +8 -0
- graphslim/configs/gcondx/flickr.json +7 -0
- graphslim/configs/gcondx/ogbn-arxiv.json +8 -0
- graphslim/configs/gcondx/reddit.json +11 -0
- graphslim/configs/gcsntk/citeseer.json +11 -0
- graphslim/configs/gcsntk/cora.json +11 -0
- graphslim/configs/gcsntk/flickr.json +13 -0
- graphslim/configs/gcsntk/ogbn-arxiv.json +13 -0
- graphslim/configs/gcsntk/reddit.json +13 -0
- graphslim/configs/geom/citeseer.json +26 -0
- graphslim/configs/geom/cora.json +25 -0
- graphslim/configs/geom/flickr.json +30 -0
- graphslim/configs/geom/ogbn-arxiv.json +27 -0
- graphslim/configs/geom/reddit.json +29 -0
- graphslim/configs/msgc/citeseer.json +12 -0
- graphslim/configs/msgc/cora.json +12 -0
- graphslim/configs/msgc/flickr.json +12 -0
- graphslim/configs/msgc/ogbn-arxiv.json +12 -0
- graphslim/configs/msgc/reddit.json +12 -0
- graphslim/configs/sfgc/citeseer.json +12 -0
- graphslim/configs/sfgc/cora.json +12 -0
- graphslim/configs/sfgc/flickr.json +12 -0
- graphslim/configs/sfgc/ogbn-arxiv.json +12 -0
- graphslim/configs/sfgc/reddit.json +12 -0
- graphslim/configs/sgdd/citeseer.json +16 -0
- graphslim/configs/sgdd/cora.json +16 -0
- graphslim/configs/sgdd/flickr.json +15 -0
- graphslim/configs/sgdd/ogbn-arxiv.json +17 -0
- graphslim/configs/sgdd/reddit.json +17 -0
- graphslim/configs.py +193 -0
- graphslim/dataset/__init__.py +3 -0
- graphslim/dataset/attack.py +95 -0
- graphslim/dataset/convertor.py +257 -0
- graphslim/dataset/loader.py +404 -0
- graphslim/dataset/utils.py +374 -0
- graphslim/evaluation/__init__.py +3 -0
- graphslim/evaluation/eval_agent.py +210 -0
- graphslim/evaluation/nas_eval.py +161 -0
- graphslim/evaluation/utils.py +145 -0
- graphslim/evaluation/vis.py +73 -0
- graphslim/models/__init__.py +13 -0
- graphslim/models/appnp.py +196 -0
- graphslim/models/base.py +212 -0
- graphslim/models/cheby.py +29 -0
- graphslim/models/gat.py +80 -0
- graphslim/models/gcn.py +23 -0
- graphslim/models/gntk.py +166 -0
- graphslim/models/graphsage.py +149 -0
- graphslim/models/ignr.py +213 -0
- graphslim/models/krr.py +21 -0
- graphslim/models/layers.py +379 -0
- graphslim/models/parametrized_adj.py +86 -0
- graphslim/models/prbcd.py +445 -0
- graphslim/models/random_attack.py +162 -0
- graphslim/models/reparam_module.py +150 -0
- graphslim/models/sgc.py +86 -0
- graphslim/models/sgformer.py +476 -0
- graphslim/models/sntk.py +96 -0
- graphslim/sparsification/__init__.py +15 -0
- graphslim/sparsification/cent_degree.py +28 -0
- graphslim/sparsification/cent_pagerank.py +55 -0
- graphslim/sparsification/coreset_base.py +46 -0
- graphslim/sparsification/edge_sparsification_base.py +34 -0
- graphslim/sparsification/fixed_idx/idx_citeseer_0.1_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_citeseer_0.25_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_citeseer_0.5_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_citeseer_1.0_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_cora_0.1_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_cora_0.25_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_cora_0.5_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_cora_1.0_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_flickr_0.001_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_flickr_0.005_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_flickr_0.01_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.001_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.005_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_ogbn-arxiv_0.01_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_reddit_0.0005_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_reddit_0.001_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_reddit_0.002_kcenter_15.npy +0 -0
- graphslim/sparsification/fixed_idx/idx_reddit_0.005_kcenter_15.npy +0 -0
- graphslim/sparsification/g_spar.py +21 -0
- graphslim/sparsification/herding.py +25 -0
- graphslim/sparsification/herding_agg.py +25 -0
- graphslim/sparsification/kcenter.py +24 -0
- graphslim/sparsification/kcenter_agg.py +27 -0
- graphslim/sparsification/kcenter_sample.py +79 -0
- graphslim/sparsification/local_degree.py +21 -0
- graphslim/sparsification/model_based_coreset_base.py +63 -0
- graphslim/sparsification/model_free_coreset_base.py +61 -0
- graphslim/sparsification/random.py +17 -0
- graphslim/sparsification/random_edge.py +21 -0
- graphslim/sparsification/rank_degree.py +68 -0
- graphslim/sparsification/scan.py +21 -0
- graphslim/sparsification/spanning_forest.py +19 -0
- graphslim/sparsification/t_spanner.py +28 -0
- graphslim/sparsification/utils.py +0 -0
- graphslim/train_all.py +69 -0
- graphslim/utils.py +946 -0
- graphslim-1.0.1.dist-info/METADATA +34 -0
- graphslim-1.0.1.dist-info/RECORD +146 -0
- graphslim-1.0.1.dist-info/WHEEL +5 -0
- graphslim-1.0.1.dist-info/top_level.txt +1 -0
|
@@ -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 HeavyEdge(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 = "heavy_edge"
|
|
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,109 @@
|
|
|
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 Kron(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 = "kron"
|
|
68
|
+
algorithm=self.args.coarsen_strategy
|
|
69
|
+
for level in range(1, max_levels + 1):
|
|
70
|
+
|
|
71
|
+
G = Gc
|
|
72
|
+
|
|
73
|
+
# how much more we need to reduce the current graph
|
|
74
|
+
r_cur = np.clip(1 - n_target / n, 0.0, max_level_r)
|
|
75
|
+
|
|
76
|
+
weights = get_proximity_measure(G, method, K=K)
|
|
77
|
+
|
|
78
|
+
if algorithm == "optimal":
|
|
79
|
+
# the edge-weight should be light at proximal edges
|
|
80
|
+
weights = -weights
|
|
81
|
+
if "rss" not in method:
|
|
82
|
+
weights -= min(weights)
|
|
83
|
+
coarsening_list = matching_optimal(G, weights=weights, r=r_cur)
|
|
84
|
+
|
|
85
|
+
elif algorithm == "greedy":
|
|
86
|
+
coarsening_list = matching_greedy(G, weights=weights, r=r_cur)
|
|
87
|
+
iC = get_coarsening_matrix(G, coarsening_list)
|
|
88
|
+
|
|
89
|
+
if iC.shape[1] - iC.shape[0] <= 2:
|
|
90
|
+
break # avoid too many levels for so few nodes
|
|
91
|
+
|
|
92
|
+
C = iC.dot(C)
|
|
93
|
+
Call.append(iC)
|
|
94
|
+
|
|
95
|
+
Wc = zero_diag(coarsen_matrix(G.W, iC)) # coarsen and remove self-loops
|
|
96
|
+
Wc = (Wc + Wc.T) / 2 # this is only needed to avoid pygsp complaining for tiny errors
|
|
97
|
+
|
|
98
|
+
if not hasattr(G, "coords"):
|
|
99
|
+
Gc = graphs.Graph(Wc)
|
|
100
|
+
else:
|
|
101
|
+
Gc = graphs.Graph(Wc, coords=coarsen_vector(G.coords, iC))
|
|
102
|
+
Gall.append(Gc)
|
|
103
|
+
|
|
104
|
+
n = Gc.N
|
|
105
|
+
|
|
106
|
+
if n <= n_target:
|
|
107
|
+
break
|
|
108
|
+
|
|
109
|
+
return C, Gc, Call, Gall
|