diversity_coef_sign.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function [Hpos,Hneg] = diversity_coef_sign(W, Ci)
  2. %DIVERSITY_COEF_SIGN Shannon-entropy based diversity coefficient
  3. %
  4. % [Hpos Hneg] = diversity_coef_sign(W,Ci);
  5. %
  6. % The Shannon-entropy based diversity coefficient measures the diversity
  7. % of intermodular connections of individual nodes and ranges from 0 to 1.
  8. %
  9. % Inputs: W, undirected connection matrix with positive and
  10. % negative weights
  11. %
  12. % Ci, community affiliation vector
  13. %
  14. % Output: Hpos, diversity coefficient based on positive connections
  15. % Hneg, diversity coefficient based on negative connections
  16. %
  17. % References: Shannon CE (1948) Bell Syst Tech J 27, 379-423.
  18. % Rubinov and Sporns (2011) NeuroImage.
  19. %
  20. %
  21. % 2011-2012, Mika Rubinov, U Cambridge
  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 nodes
  27. m = max(Ci); %number of modules
  28. Hpos = entropy(W.*(W>0));
  29. Hneg = entropy(-W.*(W<0));
  30. function H = entropy(W_)
  31. S = sum(W_,2); %strength
  32. Snm = zeros(n,m); %node-to-module degree
  33. for i = 1:m %loop over modules
  34. Snm(:,i) = sum(W_(:,Ci==i),2);
  35. end
  36. pnm = Snm ./ S(:,ones(1,m));
  37. pnm(isnan(pnm)) = 0;
  38. pnm(~pnm) = 1;
  39. H = -sum(pnm.*log(pnm),2)/log(m);
  40. end
  41. end