motif3struct_wei.m 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function [I,Q,F]=motif3struct_wei(W)
  2. %MOTIF3STRUCT_WEI Intensity and coherence of structural class-3 motifs
  3. %
  4. % [I,Q,F] = motif3struct_wei(W);
  5. %
  6. % Structural motifs are patterns of local connectivity in complex
  7. % networks. Such patterns are particularly diverse in directed networks.
  8. % The motif frequency of occurrence around an individual node is known as
  9. % the motif fingerprint of that node. The motif intensity and coherence
  10. % are weighted generalizations of the motif frequency. The motif
  11. % intensity is equivalent to the geometric mean of weights of links
  12. % comprising each motif. The motif coherence is equivalent to the ratio
  13. % of geometric and arithmetic means of weights of links comprising each
  14. % motif.
  15. %
  16. % Input: W, weighted directed connection matrix
  17. % (all weights must be between 0 and 1)
  18. %
  19. % Output: I, node motif intensity fingerprint
  20. % Q, node motif coherence fingerprint
  21. % F, node motif frequency fingerprint
  22. %
  23. % Notes:
  24. % 1. The function find_motif34.m outputs the motif legend.
  25. % 2. Average intensity and coherence are given by I./F and Q./F
  26. % 3. All weights must be between 0 and 1. This may be achieved using
  27. % the weight_conversion.m function, as follows:
  28. % W_nrm = weight_conversion(W, 'normalize');
  29. %
  30. % References: Onnela et al. (2005), Phys Rev E 71:065103
  31. % Milo et al. (2002) Science 298:824-827
  32. % Sporns O, Kötter R (2004) PLoS Biol 2: e369%
  33. %
  34. %
  35. % Mika Rubinov, UNSW/U Cambridge, 2007-2015
  36. % Modification History:
  37. % 2007: Original
  38. % 2015: Improved documentation
  39. persistent M3 M3n ID3 N3
  40. if isempty(N3)
  41. load motif34lib M3 M3n ID3 N3 %load motif data
  42. end
  43. n=length(W); %number of vertices in W
  44. I=zeros(13,n); %intensity
  45. Q=zeros(13,n); %coherence
  46. F=zeros(13,n); %frequency
  47. A=1*(W~=0); %adjacency matrix
  48. As=A|A.'; %symmetrized adjacency
  49. for u=1:n-2 %loop u 1:n-2
  50. V1=[false(1,u) As(u,u+1:n)]; %v1: neibs of u (>u)
  51. for v1=find(V1)
  52. V2=[false(1,u) As(v1,u+1:n)]; %v2: all neibs of v1 (>u)
  53. V2(V1)=0; %not already in V1
  54. V2=([false(1,v1) As(u,v1+1:n)])|V2; %and all neibs of u (>v1)
  55. for v2=find(V2)
  56. w=[W(v1,u) W(v2,u) W(u,v1) W(v2,v1) W(u,v2) W(v1,v2)];
  57. s=uint32(sum(10.^(5:-1:0).*[A(v1,u) A(v2,u) A(u,v1)...
  58. A(v2,v1) A(u,v2) A(v1,v2)]));
  59. ind=(s==M3n);
  60. M=w.*M3(ind,:);
  61. id=ID3(ind);
  62. l=N3(ind);
  63. x=sum(M,2)/l; %arithmetic mean
  64. M(M==0)=1; %enable geometric mean
  65. i=prod(M,2)^(1/l); %intensity
  66. q=i/x; %coherence
  67. %then add to cumulative count
  68. I(id,[u v1 v2])=I(id,[u v1 v2])+[i i i];
  69. Q(id,[u v1 v2])=Q(id,[u v1 v2])+[q q q];
  70. F(id,[u v1 v2])=F(id,[u v1 v2])+[1 1 1];
  71. end
  72. end
  73. end