-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmotifs2.py
64 lines (46 loc) · 1.38 KB
/
motifs2.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
"""
This file implements the efficient algorithm for motif discovery in hypergraphs.
"""
from hypergraph import hypergraph
from utils import *
from loaders import *
def motifs_order_3(edges, TOT):
N = 3
full, visited = motifs_ho_full(edges, N, TOT)
standard = motifs_standard(edges, N, TOT, visited)
res = []
for i in range(len(full)):
res.append((full[i][0], max(full[i][1], standard[i][1])))
return res
def motifs_order_4(edges, TOT):
N = 4
full, visited = motifs_ho_full(edges, N, TOT)
not_full, visited = motifs_ho_not_full(edges, N, TOT, visited)
standard = motifs_standard(edges, N, TOT, visited)
res = []
for i in range(len(full)):
res.append((full[i][0], max([full[i][1], not_full[i][1], standard[i][1]])))
return res
N = 3
edges = load_high_school(N)
output = {}
if N == 3:
output['motifs'] = motifs_order_3(edges, -1)
elif N == 4:
output['motifs'] = motifs_order_4(edges, -1)
print(output['motifs'])
STEPS = len(edges)*10
ROUNDS = 10
results = []
for i in range(ROUNDS):
e1 = hypergraph(edges)
e1.MH(label='stub', n_steps=STEPS)
if N == 3:
m1 = motifs_order_3(e1.C, i)
elif N == 4:
m1 = motifs_order_4(e1.C, i)
results.append(m1)
output['config_model'] = results
delta = diff_sum(output['motifs'], output['config_model'])
norm_delta = norm_vector(delta)
print(norm_delta)