clustering_coef_wu.m 1015 B

123456789101112131415161718192021222324252627282930
  1. function C=clustering_coef_wu(W)
  2. %CLUSTERING_COEF_WU Clustering coefficient
  3. %
  4. % C = clustering_coef_wu(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 undirected connection matrix
  10. % (all weights must be between 0 and 1)
  11. %
  12. % Output: C, clustering coefficient vector
  13. %
  14. % Note: All weights must be between 0 and 1.
  15. % This may be achieved using the weight_conversion.m function,
  16. % W_nrm = weight_conversion(W, 'normalize');
  17. %
  18. % Reference: Onnela et al. (2005) Phys Rev E 71:065103
  19. %
  20. %
  21. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  22. % Modification history:
  23. % 2007: original
  24. % 2015: expanded documentation
  25. K=sum(W~=0,2);
  26. cyc3=diag((W.^(1/3))^3);
  27. K(cyc3==0)=inf; %if no 3-cycles exist, make C=0 (via K=inf)
  28. C=cyc3./(K.*(K-1)); %clustering coefficient