File: closeness.txt

package info (click to toggle)
python-networkx 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,780 kB
  • ctags: 1,910
  • sloc: python: 29,050; makefile: 126
file content (108 lines) | stat: -rw-r--r-- 2,306 bytes parent folder | download
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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