betweenness_bin.m 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. function BC=betweenness_bin(G)
  2. %BETWEENNESS_BIN Node betweenness centrality
  3. %
  4. % BC = betweenness_bin(A);
  5. %
  6. % Node betweenness centrality is the fraction of all shortest paths in
  7. % the network that contain a given node. Nodes with high values of
  8. % betweenness centrality participate in a large number of shortest paths.
  9. %
  10. % Input: A, binary (directed/undirected) connection matrix.
  11. %
  12. % Output: BC, node betweenness centrality vector.
  13. %
  14. % Note: Betweenness centrality may be normalised to the range [0,1] as
  15. % BC/[(N-1)(N-2)], where N is the number of nodes in the network.
  16. %
  17. % Reference: Kintali (2008) arXiv:0809.1906v2 [cs.DS]
  18. % (generalization to directed and disconnected graphs)
  19. %
  20. %
  21. % Mika Rubinov, UNSW/U Cambridge, 2007-2012
  22. n=length(G); %number of nodes
  23. I=eye(n)~=0; %logical identity matrix
  24. d=1; %path length
  25. NPd=G; %number of paths of length |d|
  26. NSPd=NPd; %number of shortest paths of length |d|
  27. NSP=NSPd; NSP(I)=1; %number of shortest paths of any length
  28. L=NSPd; L(I)=1; %length of shortest paths
  29. %calculate NSP and L
  30. while find(NSPd,1)
  31. d=d+1;
  32. NPd=NPd*G;
  33. NSPd=NPd.*(L==0);
  34. NSP=NSP+NSPd;
  35. L=L+d.*(NSPd~=0);
  36. end
  37. L(~L)=inf; L(I)=0; %L for disconnected vertices is inf
  38. NSP(~NSP)=1; %NSP for disconnected vertices is 1
  39. Gt=G.';
  40. DP=zeros(n); %vertex on vertex dependency
  41. diam=d-1; %graph diameter
  42. %calculate DP
  43. for d=diam:-1:2
  44. DPd1=(((L==d).*(1+DP)./NSP)*Gt).*((L==(d-1)).*NSP);
  45. DP=DP + DPd1; %DPd1: dependencies on vertices |d-1| from source
  46. end
  47. BC=sum(DP,1); %compute betweenness