-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathC_vowels.py
More file actions
71 lines (57 loc) · 1.6 KB
/
Copy pathC_vowels.py
File metadata and controls
71 lines (57 loc) · 1.6 KB
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
import networkx as nx
import pickle
import random
try:
graph = pickle.load(open('R_infomap.bin','rb'))
print('[i] loaded graph')
except:
# load any graph version, let's take the simple one for the moment
graph = nx.read_yaml('R_infomap.yaml')
with open('R_infomap.bin', 'wb') as f:
pickle.dump(graph, f)
# assemble subgraphs
subs = {}
for n,data in graph.nodes(data=True):
col = data['color']
try:
subs[col] += [n]
except KeyError:
subs[col] = [n]
ccol = {
'red' : 'ə',
'green' : 'a',
'blue' : 'u',
'gray' : 'e',
'yellow' : 'i',
'cyan' : 'o'
}
for s in sorted([x for x in subs if x not in '']):
subg = nx.subgraph(graph, subs[s])
nInt = len(subg.edges())
nExt = 0
for n in sorted(subs[s]):
for nB in graph.edge[n]:
if nB in subg:
pass
else:
nExt += 1
print(ccol[s], '\t', '{0:.2f}'.format(nExt / (nExt + 2 * nInt)))
# compute random conductance
cons = [0 for i in range(6)]
for i in range(100):
nodes = list(graph.nodes())
for j,s in enumerate(sorted([x for x in subs if x not in ''])):
nnodes = random.sample(nodes, len(subs[s]))
nExt = 0
nInt = 0
for n in nnodes:
for nB in graph.edge[n]:
if nB in nnodes:
nInt += 1
else:
nExt += 1
c = nExt / (nExt + 2 * nInt)
cons[j] += c
print('')
for i,c in enumerate(cons):
print(i+1, '\t', '{0:.2f}'.format(c / 100))