blob: 5e10bfa8b1e6c17b2c094489afc1e500174465cc (
plain)
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
|
####
##
##
## Take a file with the degree sequence of nodes which are active on
## both layers, and compute \overline{k}(q) and \overline{q}(k),
## i.e. the two inter-layer correlation functions, where we call "k"
## the degree on the first column, and "q" the degree on the second
## column
##
##
import sys
if len(sys.argv) < 2:
print "Usage: %s <filein>" % sys.argv[0]
sys.exit(1)
qnn_k = {}
knn_q = {}
with open(sys.argv[1]) as f:
for l in f:
k, q = [int(x) for x in l.strip(" \n").split(" ")]
if qnn_k.has_key(k):
qnn_k[k].append(q)
else:
qnn_k[k] = [q]
if knn_q.has_key(q):
knn_q[q].append(k)
else:
knn_q[q] = [k]
keys= qnn_k.keys()
keys.sort()
for k in keys:
print k, 1.0 * sum(qnn_k[k])/len(qnn_k[k])
keys= knn_q.keys()
keys.sort()
for q in keys:
sys.stderr.write("%d %f\n" % (q, 1.0 * sum(knn_q[q])/len(knn_q[q])))
|