Created
September 20, 2013 05:45
-
-
Save onurvarol/6633729 to your computer and use it in GitHub Desktop.
Question from Fil:
Centrality challenge: today as I was teaching about closeness and betweenness centrality in class, a student asked for an example of a network where the node with highest closeness centrality is not also the one with highest betweenness. I could not think of a simple example. Output of file:
Closeness: ['a', 1, 2, 3, 4, 33, 11…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Question from Fil: | |
Centrality challenge: today as I was teaching about closeness | |
and betweenness centrality in class, a student asked for an | |
example of a network where the node with highest closeness | |
centrality is not also the one with highest betweenness. I | |
could not think of a simple example. Anyone? | |
''' | |
import networkx as nx | |
G = nx.Graph() | |
G.add_edge(1,2) | |
G.add_edge(11,22) | |
G.add_edge(1,3) | |
G.add_edge(11,33) | |
G.add_edge(2,4) | |
G.add_edge(22,44) | |
G.add_edge(3,4) | |
G.add_edge(33,44) | |
G.add_edge(1,11) | |
G.add_edge(2,22) | |
G.add_edge(3,33) | |
G.add_edge(4,44) | |
G.add_edge(1,'a') | |
G.add_edge(3,'a') | |
G.add_edge(2,'a') | |
G.add_edge(4,'a') | |
nx.circular_layout(G) | |
closenessC = nx.closeness_centrality(G, distance='weight') | |
print 'Closeness: ', sorted(closenessC, key=closenessC.get, reverse=True) | |
betweennessC = nx.betweenness_centrality(G, weight='weight') | |
print 'Betweenness: ',sorted(betweennessC, key=betweennessC.get, reverse=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment