-
Notifications
You must be signed in to change notification settings - Fork 1
/
graphGeneration.py
141 lines (104 loc) · 3.9 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import networkx as nx
import torch_geometric.datasets as ds
import random
import ndlib
import ndlib.models.epidemics as ep
import ndlib.models.ModelConfig as mc
from torch_geometric.datasets import Planetoid
def connSW():
g = nx.connected_watts_strogatz_graph(5000, 10, 0.1)
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
g[a][b]['weight'] = weight
config.add_edge_configuration("threshold", (a, b), weight)
return g, config
def BA():
g = nx.barabasi_albert_graph(1000, 5)
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
g[a][b]['weight'] = weight
config.add_edge_configuration("threshold", (a, b), weight)
return g, config
def ER():
g = nx.erdos_renyi_graph(5000, 0.002)
while nx.is_connected(g) == False:
g = nx.erdos_renyi_graph(5000, 0.002)
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config
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()
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config
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()
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config
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()
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(40,80)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config
def photo():
dataset = ds.Amazon(root='./geo', name = 'Photo')
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
g = nx.convert_node_labels_to_integers(G, first_label=0, ordering='default', label_attribute=None)
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(5,20)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config
def coms():
dataset = ds.Amazon(root='./geo', name = 'Computers')
data = dataset[0]
edges = (data.edge_index.numpy()).T.tolist()
G = nx.from_edgelist(edges)
g = nx.convert_node_labels_to_integers(G, first_label=0, ordering='default', label_attribute=None)
config = mc.Configuration()
for a, b in g.edges():
weight = random.randrange(5,20)
weight = round(weight / 100, 2)
config.add_edge_configuration("threshold", (a, b), weight)
g[a][b]['weight'] = weight
return g, config