gateway_coef_sign.m 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. function [GWpos,GWneg] = gateway_coef_sign(W,Ci,centtype)
  2. %GATEWAY_COEF_SIGN Gateway coefficient
  3. %
  4. % [Gpos,Gneg] = gateway_coef_sign(W,Ci,centtype);
  5. %
  6. % Gateway coefficient is a variant of participation coefficient. Similar
  7. % to participation coefficient, gateway coefficient measures the
  8. % diversity of intermodular connections of individual nodes, but this is
  9. % weighted by how critical these connections are to intermodular
  10. % connectivity (e.g., if a node is the only connection between it's
  11. % module and another module, it will have a higher gateway coefficient).
  12. %
  13. % Inputs: W, undirected connection matrix with positive and
  14. % negative weights
  15. %
  16. % Ci, community affiliation vector
  17. %
  18. % centtype, centrality measure to use
  19. % 1 = Node Strength
  20. % 2 = Betweenness Centrality
  21. %
  22. % Output: Gpos, gateway coefficient for positive weights
  23. %
  24. % Gneg, gateway coefficient for negative weights
  25. %
  26. % Reference: Vargas ER, Wahl LM. Eur Phys J B (2014) 87:1-10.
  27. %
  28. % Jeff Spielberg, Boston University
  29. % Modification History:
  30. % May 2015: Original (adapted from participation_coef_sign.m)
  31. [~,~,Ci] = unique(Ci);
  32. n=length(W); %number of vertices
  33. W(1:(n+1):end) = 0;
  34. GWpos = gcoef( W.*(W>0));
  35. GWneg = gcoef(-W.*(W<0));
  36. function GW = gcoef(W_)
  37. S = sum(W_,2); %strength
  38. Gc = (W_~=0)*diag(Ci); %neighbor community affiliation
  39. Sc2 = zeros(n,1); %community-specific neighbors
  40. ksm = zeros(n,1); % Weighting by extra-modular importance
  41. centm = zeros(n,1); % Weighting by intra-modular importance
  42. switch centtype % Which centrality measure to use?
  43. case 1 % Node Strength
  44. cent = S;
  45. case 2 % Betweenness Centrality
  46. L = weight_conversion(W_,'lengths');
  47. cent = betweenness_wei(L);
  48. end
  49. for i = 1:max(Ci)
  50. ks = sum(W_.*(Gc==i),2);
  51. Sc2 = Sc2 + (ks.^2);
  52. for j = 1:max(Ci)
  53. ksm(Ci==j) = ksm(Ci==j) + ks(Ci==j)/sum(ks(Ci==j)); % Calculate extra-modular weights
  54. end
  55. centm(Ci==i) = sum(cent(Ci==i)); % Calculate intra-modular weights
  56. end
  57. centm = centm./max(centm); % Re-map to be between 0 & 1
  58. gs = (1-(ksm.*centm)).^2; % Calculate total weights
  59. GW = ones(n,1) - (Sc2./(S.^2).*gs);
  60. GW(isnan(GW)) = 0;
  61. GW(~GW) = 0; %p_ind=0 if no (out)neighbors
  62. end
  63. end