-
Notifications
You must be signed in to change notification settings - Fork 2
/
strengthcorrect.m
37 lines (35 loc) · 959 Bytes
/
strengthcorrect.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
function sW=strengthcorrect(W,ss,nreps)
% sW=strengthcorrect(W,ss,[nreps])
%
% Iteratively rescale weights in connectivity matrix W to make the strength
% sequence converge onto desired strength sequence ss
%
% Inputs
% W = weighted connectivity matrix
% ss = desired strength sequence
% nreps = number of iterations in the rescaling algorithm
% (optional, default=9)
%
% Outputs
% sW = network with desired strength sequence ss
%
% Note: assumes W is undirected (symmetric)
%
% Reference: Roberts et al. (2016) NeuroImage 124:379-393.
%
% M Breakspear, J Roberts
% QIMR Berghofer, 2015
if nargin<3,
nreps=9;
end
ss=ss(:)';
N=length(ss);
discnodes=sum(W)==0;
sW=W.*repmat(ss./sum(W),N ,1);
sW(:,discnodes)=0; %ensure disconnected nodes don't introduce NaNs
sW=(sW+sW')/2;
for j=1:nreps,
sW=sW.*repmat(ss./sum(sW),N ,1);
sW(:,discnodes)=0;
sW=(sW+sW')/2;
end