-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphGeneration.py
88 lines (62 loc) · 2.5 KB
/
graphGeneration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import networkx as nx
import torch_geometric.datasets as ds
import ndlib.models.ModelConfig as mc
from torch_geometric.datasets import Planetoid
def connSW(n):
g = nx.connected_watts_strogatz_graph(n, 20, 0.1)
while nx.is_connected(g) == False:
g = nx.connected_watts_strogatz_graph(n, 20, 0.1)
return g
def BA(n):
g = nx.barabasi_albert_graph(n, 10)
return g
def ER(n):
g = nx.erdos_renyi_graph(n, 0.02)
while nx.is_connected(g) == False:
g = nx.erdos_renyi_graph(n, 0.02)
return g
def CiteSeer():
dataset = Planetoid(root='./Planetoid', name='CiteSeer') # Cora, CiteSeer, PubMed
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
c = max(nx.connected_components(G), key=len)
g = G.subgraph(c).copy()
g = nx.convert_node_labels_to_integers(g, first_label=0, ordering='default', label_attribute=None)
return g
def PubMed():
dataset = Planetoid(root='./Planetoid', name='PubMed') # Cora, CiteSeer, PubMed
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
c = max(nx.connected_components(G), key=len)
g = G.subgraph(c).copy()
g = nx.convert_node_labels_to_integers(g, first_label=0, ordering='default', label_attribute=None)
return g
def Cora():
dataset = Planetoid(root='./Planetoid', name='Cora') # Cora, CiteSeer, PubMed
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
c = max(nx.connected_components(G), key=len)
g = G.subgraph(c).copy()
g = nx.convert_node_labels_to_integers(g, first_label=0, ordering='default', label_attribute=None)
return g
def photo():
dataset = ds.Amazon(root='./geo', name = 'Photo')
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
c = max(nx.connected_components(G), key=len)
g = G.subgraph(c).copy()
g = nx.convert_node_labels_to_integers(g, first_label=0, ordering='default', label_attribute=None)
return g
def coms():
dataset = ds.Amazon(root='./geo', name = 'Computers')
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
c = max(nx.connected_components(G), key=len)
g = G.subgraph(c).copy()
g = nx.convert_node_labels_to_integers(g, first_label=0, ordering='default', label_attribute=None)
return g