rich_club_bu.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. function [R,Nk,Ek] = rich_club_bu(CIJ,varargin)
  2. %RICH_CLUB_BU Rich club coefficients (binary undirected graph)
  3. %
  4. % R = rich_club_bu(CIJ)
  5. % [R,Nk,Ek] = rich_club_bu(CIJ,klevel)
  6. %
  7. % The rich club coefficient, R, at level k is the fraction of edges that
  8. % connect nodes of degree k or higher out of the maximum number of edges
  9. % that such nodes might share.
  10. %
  11. % Input: CIJ, connection matrix, binary and undirected
  12. % klevel, optional input argument. klevel sets the
  13. % maximum level at which the rich club
  14. % coefficient will be calculated. If klevel is
  15. % not included the the maximum level will be
  16. % set to the maximum degree of CIJ.
  17. %
  18. % Output: R, vector of rich-club coefficients for levels
  19. % 1 to klevel.
  20. % Nk, number of nodes with degree>k
  21. % Ek, number of edges remaining in subgraph with
  22. % degree>k
  23. %
  24. % Reference: Colizza et al. (2006) Nat. Phys. 2:110.
  25. %
  26. % Martijn van den Heuvel, University Medical Center Utrecht, 2011
  27. Degree = sum(CIJ); %compute degree of each node
  28. if nargin == 1
  29. klevel = max(Degree);
  30. elseif nargin == 2
  31. klevel = varargin{1};
  32. elseif nargin > 2
  33. error('number of inputs incorrect. Should be [CIJ], or [CIJ, klevel]')
  34. end
  35. R = zeros(1,klevel);
  36. Nk = zeros(1,klevel);
  37. Ek = zeros(1,klevel);
  38. for k = 1:klevel
  39. SmallNodes=find(Degree<=k); %get 'small nodes' with degree <=k
  40. subCIJ=CIJ; %extract subnetwork of nodes >k by removing nodes <=k of CIJ
  41. subCIJ(SmallNodes,:)=[]; %remove rows
  42. subCIJ(:,SmallNodes)=[]; %remove columns
  43. Nk(k)=size(subCIJ,2); %number of nodes with degree >k
  44. Ek(k)=sum(subCIJ(:)); %total number of connections in subgraph
  45. R(k)=Ek(k)/(Nk(k)*(Nk(k)-1)); %unweighted rich-club coefficient
  46. end