Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding weak ties using networkx

I am trying to find the weak ties as defined by Granovetter. So far I have tried using centrality measurements to plot the Stanford Facebook network dataset (facebook_combined.txt) according to importance. The plot below uses degree centrality. I've indicated with blue rectangles some of the nodes that I wish to find (the 'weak ties').

degree centrality

Bridges seem close, but not quite there. How should I proceed in finding these nodes?

Example code:

import networkx as nx

fb = nx.read_edgelist("facebook_combined.txt")
degree_cent_fb = nx.degree_centrality(fb)

pos_fb = nx.spring_layout(fb ,iterations = 1000)

nsize = np.array ([v for v in degree_cent_fb.values ()])

nsize = 500*( nsize - min(nsize))/(max(nsize) - min(nsize))

nodes = nx.draw_networkx_nodes (fb , pos = pos_fb ,
                                node_size = nsize)
edges = nx.draw_networkx_edges (fb , pos = pos_fb ,
                                alpha = .1)

Here are some more example plots with other sizing functions:

Same data, sized by betweenness centrality:

betweenness centrality

And closeness centrality:

closeness centrality

And with PageRank:

PageRank

like image 502
Kostas Mouratidis Avatar asked Jun 15 '18 11:06

Kostas Mouratidis


1 Answers

Note that weak ties or bridges refer to edges and you are looking rather for a node-level measure. You may be interested in Ron Burt's concept of a structural hole. Nodes occupying structural holes are brokers, connecting groups with limited overlap - sounds like what you are looking for.

NetworkX (as of version 2.0, if I recall correctly) has an implementation of Burt's constraint measure. Burt says a node occupies a structural hole if it has low constraint. One minus a node's constraint score seems to highlight the nodes in between communities quite well, though not in every case.

Large, red nodes have low constraint

And here is the code. Beware - it takes some time to calculate constraint!

fb = nx.read_edgelist("facebook_combined.txt")
pos_fb = nx.spring_layout(fb ,iterations = 100)

cons = nx.constraint(fb)

plt.figure(figsize=(15,10))
nsize = np.array ([1-v for v in cons.values()])

nsize = 10**(nsize+1)

nodes = nx.draw_networkx_nodes (fb , pos = pos_fb , node_color=nsize, cmap=plt.cm.coolwarm,
                                node_size = nsize)
edges = nx.draw_networkx_edges (fb , pos = pos_fb , 
                                alpha = .1)

plt.axis('off')
like image 180
Johannes Wachs Avatar answered Oct 05 '22 23:10

Johannes Wachs