-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlobby.py
63 lines (44 loc) · 1.59 KB
/
lobby.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
from igraph import *
def lobby(G, log_file=None):
"""Lobby or h index
================
All graph vertices are traversed and Lobby index is calculated and stored in the lobby macro-field.
If a node has the following list of neighbors sorted by degree:
========== ========
neighbor degree
========== ========
1 21
2 18
3 4
4 3
========== ========
the Lobby index is 3 because degree $\leq$ neighbor_position.
"""
lobbies = []
if (log_file!=None):
log_file.write('* ' + G.graph['name'] + '\n')
for u in range(G.number_of_nodes()):
if (log_file):
log_file.write(G.node[u]['name'] + "\tdegree=" + str(G.degree(u)) + '\n')
G.node[u]['Lobby'] = lobby = 1 # initialize lobby
degs = [] # neighbors' degree
for v in G.neighbors(u):
degs.append(G.degree(v))
degs.sort()
degs.reverse()
old_idx = idx = 0
for deg in degs:
lobby = idx = idx + 1
if (log_file!=None):
log_file.write("\t" + str(idx) + "\t" + str(deg) + '\n')
if (deg < idx):
lobby = old_idx
break
old_idx = idx
if (log_file!=None):
log_file.write("Lobby=" + str(lobby) + '\n')
G.node[u]['Lobby'] = float(lobby) / G.number_of_nodes() # normalize by N vertices
lobbies.append(G.node[u]['Lobby'])
if log_file:
log_file.flush()
return lobbies