participation_coef_sign.m 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function [Ppos,Pneg]=participation_coef_sign(W,Ci)
  2. %PARTICIPATION_COEF_SIGN Participation coefficient
  3. %
  4. % [Ppos Pneg] = participation_coef_sign(W,Ci);
  5. %
  6. % Participation coefficient is a measure of diversity of intermodular
  7. % connections of individual nodes.
  8. %
  9. % Inputs: W, undirected connection matrix with positive and
  10. % negative weights
  11. %
  12. % Ci, community affiliation vector
  13. %
  14. % Output: Ppos, participation coefficient from positive weights
  15. %
  16. % Pneg, participation coefficient from negative weights
  17. %
  18. % Reference: Guimera R, Amaral L. Nature (2005) 433:895-900.
  19. %
  20. %
  21. % 2011, Mika Rubinov, UNSW
  22. % Modification History:
  23. % Mar 2011: Original
  24. % Sep 2012: Fixed treatment of nodes with no negative strength
  25. % (thanks to Alex Fornito and Martin Monti)
  26. n=length(W); %number of vertices
  27. Ppos = pcoef( W.*(W>0));
  28. Pneg = pcoef(-W.*(W<0));
  29. function P=pcoef(W_)
  30. S = sum(W_,2); %strength
  31. Gc = (W_~=0)*diag(Ci); %neighbor community affiliation
  32. Sc2 = zeros(n,1); %community-specific neighbors
  33. for i = 1:max(Ci)
  34. Sc2 = Sc2 + (sum(W_.*(Gc==i),2).^2);
  35. end
  36. P = ones(n,1) - Sc2./(S.^2);
  37. P(isnan(P)) = 0;
  38. P(~P) = 0; %p_ind=0 if no (out)neighbors
  39. end
  40. end