Centrality
==========

>>> from networkx import *

>>> K=krackhardt_kite_graph()
>>> P3=path_graph(3)
>>> P4=path_graph(4)
>>> K5=complete_graph(5)
>>> C4=cycle_graph(4)
>>> T=balanced_tree(r=2, h=2)
>>> Gb = Graph()
>>> Gb.add_edges_from([(0,1), (0,2), (1,3), (2,3), (2,4), (4,5), (3,5)])


>>> F=Graph() # Florentine families
>>> F.add_edge('Acciaiuoli','Medici')
>>> F.add_edge('Castellani','Peruzzi')
>>> F.add_edge('Castellani','Strozzi')
>>> F.add_edge('Castellani','Barbadori')
>>> F.add_edge('Medici','Barbadori')
>>> F.add_edge('Medici','Ridolfi')
>>> F.add_edge('Medici','Tornabuoni')
>>> F.add_edge('Medici','Albizzi')
>>> F.add_edge('Medici','Salviati')
>>> F.add_edge('Salviati','Pazzi')
>>> F.add_edge('Peruzzi','Strozzi')
>>> F.add_edge('Peruzzi','Bischeri')
>>> F.add_edge('Strozzi','Ridolfi')
>>> F.add_edge('Strozzi','Bischeri')
>>> F.add_edge('Ridolfi','Tornabuoni')
>>> F.add_edge('Tornabuoni','Guadagni')
>>> F.add_edge('Albizzi','Ginori')
>>> F.add_edge('Albizzi','Guadagni')
>>> F.add_edge('Bischeri','Guadagni')
>>> F.add_edge('Guadagni','Lamberteschi')



Closeness Centrality
--------------------

>>> c=closeness_centrality(K5)
>>> for v in K5:
...     print "%0.2d %5.3f"%(v,c[v])
00 1.000
01 1.000
02 1.000
03 1.000
04 1.000

>>> c=closeness_centrality(P3)
>>> for v in P3:
...     print "%0.2d %5.3f"%(v,c[v])
00 0.667
01 1.000
02 0.667


>>> c=closeness_centrality(K)
>>> for v in K:
...     print "%0.2d %5.3f"%(v,c[v])
00 0.529
01 0.529
02 0.500
03 0.600
04 0.500
05 0.643
06 0.643
07 0.600
08 0.429
09 0.310


>>> c=closeness_centrality(F)
>>> for v in sorted(F):
...     print "%-13s %5.3f"%(v,c[v])
Acciaiuoli    0.368
Albizzi       0.483
Barbadori     0.438
Bischeri      0.400
Castellani    0.389
Ginori        0.333
Guadagni      0.467
Lamberteschi  0.326
Medici        0.560
Pazzi         0.286
Peruzzi       0.368
Ridolfi       0.500
Salviati      0.389
Strozzi       0.438
Tornabuoni    0.483


Weighted Closeness
------------------

>>> XG=Graph()
>>> XG.add_weighted_edges_from([('s','u',10) ,('s','x',5) ,('u','v',1) ,('u','x',2) ,('v','y',1) ,('x','u',3) ,('x','v',5) ,('x','y',2) ,('y','s',7) ,('y','v',6)])
>>> c=closeness_centrality(XG,weighted_edges=True)
>>> for v in XG.nodes():
...     print "%s %5.3f"%(v,c[v])
y 0.200
x 0.286
s 0.138
u 0.235
v 0.200

