File: krackhardt_centrality.py

package info (click to toggle)
python-networkx 0.32-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,332 kB
  • ctags: 1,020
  • sloc: python: 21,197; makefile: 67; sh: 11
file content (33 lines) | stat: -rw-r--r-- 876 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python
"""
Centrality measures of Krackhardt social network.
"""
__author__ = """Aric Hagberg (hagberg@lanl.gov)"""
__date__ = "$Date: 2005-05-12 14:33:11 -0600 (Thu, 12 May 2005) $"
__credits__ = """"""
__revision__ = "$Revision: 998 $"
#    Copyright (C) 2004 by 
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Pieter Swart <swart@lanl.gov>
#    Distributed under the terms of the GNU Lesser General Public License
#    http://www.gnu.org/copyleft/lesser.html

from networkx import *

G=krackhardt_kite_graph()

print "Betweenness"
b=betweenness_centrality(G)
for v in G.nodes():
    print "%0.2d %5.3f"%(v,b[v])

print "Degree centrality"
d=degree_centrality(G)
for v in G.nodes():
    print "%0.2d %5.3f"%(v,d[v])

print  "Closeness centrality"
c=closeness_centrality(G)
for v in G.nodes():
    print "%0.2d %5.3f"%(v,c[v])