-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc_complexity.m
executable file
·103 lines (81 loc) · 2.77 KB
/
func_complexity.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
function [C, Cmax, coupling_max, Corr_mean] = func_complexity(W,nbins,coupling_vec,method)
% func_complexity.m
%
% Calculate functional complexity based on Zamora-Lopez et al., Sci Rep
% implementated as per python code here:
% https://github.com/gorkazl/pyGAlib/blob/master/galib_extra.py
%
% Inputs: W : connectivtiy matrix [NxN]
% nbins : number of histogram bins for the FC complexity (float)
% coupling_vec : coupling values (vector)
% method : method to calculate correlation matrix (string)
% 'Zamora' or 'Tononi'
%
% Outputs: C : complexity values (vector)
% Cmax : maximum complexity (float)
% coupling_max : coupling of maximum complexity (float)
% Corr_mean : mean correlation (vector)
%
% Original: James Roberts, QIMR Berghofer
% Edited: James Pang, QIMR Berghofer, 2020
%%
if nargin<4
method = 'Zamora';
end
if nargin<3
coupling_vec = linspace(0, 10, 51);
end
if nargin<2
nbins = 100;
end
C = zeros(1,length(coupling_vec));
Corr_mean = zeros(1,length(coupling_vec));
ut = triu(ones(size(W,1)),1)>0;
if strcmpi(method, 'Zamora')
corrfun = @corr_exp;
elseif strcmpi(method, 'Tononi')
corrfun = @corr_OU;
end
for m=1:length(coupling_vec)
coupling = coupling_vec(m);
corrmatrix = corrfun(W,coupling);
C(m) = complexity(corrmatrix(ut),nbins);
Corr_mean(m) = mean(corrmatrix(ut), 'all');
end
Cmax = max(C);
coupling_max = coupling_vec(C==Cmax);
end
function C = complexity(corrvals,nbins)
% Complexity from FC matrix values
binedges = linspace(0,1,nbins+1);
probs = histcounts(corrvals,binedges,'normalization','probability');
C = 1-sum(abs(probs-1/nbins))/(2*(nbins-1)/nbins);
end
function corrmatrix = corr_exp(W,coupling)
% Zamora-Lopez et al.'s method
% Compute the Q matrix
Qmatrix = expm(coupling*W);
% Compute the covariance matrix
COVmatrix = Qmatrix.'*Qmatrix;
% Normalises a covariance matrix into a cross-correlation matrix.
% Calculate the normalization factor for each pair
diagvalues = diag(COVmatrix);
normmatrix = sqrt(diagvalues*diagvalues.');
% Return result
corrmatrix = COVmatrix./normmatrix;
end
function corrmatrix = corr_OU(W,coupling)
% Tononi, Sporns, and Edelman's method.
% Construct the uncorrelated noise vector (diagonal matrix)
N = size(W,1);
% Compute the Q matrix
Qmatrix = inv(eye(N) - coupling*W);
% Compute the covariance matrix
COVmatrix = Qmatrix.'*Qmatrix;
% Normalises a covariance matrix into a cross-correlation matrix.
% Calculate the normalization factor for each pair
diagvalues = diag(COVmatrix);
normmatrix = sqrt(diagvalues*diagvalues.');
% Return result
corrmatrix = COVmatrix./normmatrix;
end