clustering_coef_wd.m 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function C=clustering_coef_wd(W)
  2. %CLUSTERING_COEF_WD Clustering coefficient
  3. %
  4. % C = clustering_coef_wd(W);
  5. %
  6. % The weighted clustering coefficient is the average "intensity"
  7. % (geometric mean) of all triangles associated with each node.
  8. %
  9. % Input: W, weighted directed connection matrix
  10. % (all weights must be between 0 and 1)
  11. %
  12. % Output: C, clustering coefficient vector
  13. %
  14. % Reference: Fagiolo (2007) Phys Rev E 76:026107.
  15. %
  16. % Note: All weights must be between 0 and 1.
  17. % This may be achieved using the weight_conversion.m function,
  18. % W_nrm = weight_conversion(W, 'normalize');
  19. %
  20. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  21. % Modification history:
  22. % 2007: original
  23. % 2015: expanded documentation
  24. % Methodological note (also see clustering_coef_bd)
  25. % The weighted modification is as follows:
  26. % - The numerator: adjacency matrix is replaced with weights matrix ^ 1/3
  27. % - The denominator: no changes from the binary version
  28. %
  29. % The above reduces to symmetric and/or binary versions of the clustering
  30. % coefficient for respective graphs.
  31. A=W~=0; %adjacency matrix
  32. S=W.^(1/3)+(W.').^(1/3); %symmetrized weights matrix ^1/3
  33. K=sum(A+A.',2); %total degree (in + out)
  34. cyc3=diag(S^3)/2; %number of 3-cycles (ie. directed triangles)
  35. K(cyc3==0)=inf; %if no 3-cycles exist, make C=0 (via K=inf)
  36. CYC3=K.*(K-1)-2*diag(A^2); %number of all possible 3-cycles
  37. C=cyc3./CYC3; %clustering coefficient