/
transitivity_wd.m
44 lines (36 loc) · 1.47 KB
/
transitivity_wd.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function T=transitivity_wd(W)
%TRANSITIVITY_WD Transitivity
%
% T = transitivity_wd(W);
%
% Transitivity is the ratio of 'triangles to triplets' in the network.
% (A classical version of the clustering coefficient).
%
% Input: W weighted directed connection matrix
%
% Output: T transitivity scalar
%
% Reference: Rubinov M, Sporns O (2010) NeuroImage 52:1059-69
% based on Fagiolo (2007) Phys Rev E 76:026107.
%
%
% Mika Rubinov, UNSW/U-Cambridge
% Christoph Schmidt, Friedrich Schiller University Jena
% 2007-2013
% Modification history:
% 2007: original (MR)
% 2013: removed test for absence of nodewise 3-cycles (CS)
% Methodological note (also see note for clustering_coef_bd)
% The weighted modification is as follows:
% - The numerator: adjacency matrix is replaced with weights matrix ^ 1/3
% - The denominator: no changes from the binary version
%
% The above reduces to symmetric and/or binary versions of the clustering
% coefficient for respective graphs.
T=0;
A=W~=0; %adjacency matrix
S=W.^(1/3)+(W.').^(1/3); %symmetrized weights matrix ^1/3
K=sum(A+A.',2); %total degree (in + out)
cyc3=diag(S^3)/2; %number of 3-cycles (ie. directed triangles)
CYC3=K.*(K-1)-2*diag(A^2); %number of all possible 3-cycles
T=sum(cyc3)./sum(CYC3); %transitivity