forked from ProcessNetwork/ProcessNetwork_Software
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAdjMatrices.m
135 lines (117 loc) · 5.26 KB
/
AdjMatrices.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function [Abinary,Awtd,AwtdCut,charLagFirstPeak,TcharLagFirstPeak,charLagMaxPeak,TcharLagMaxPeak,TvsIzerocharLagMaxPeak,nSigLags,FirstSigLag,LastSigLag]=AdjMatrices(T,SigThreshT,TvsIzero,lagVect)
% COMPUTES AN ADJACENCY MATRIX A
% COMPUTES THE CHARACTERISTIC LAG WHICH IS THE FIRST SIGNIFICANT LAG
% TAKES THE TRANSFER INFORMATION MATRIX AND THE SIGNIFICANCE THRESHOLDS
% NOTE - This code considers ONLY POSITIVE LAGS in the computation of these matrices
[nSignals,~,nLags,nFiles]=size(T);
nSLags = size(SigThreshT,3);
Abinary=zeros(nSignals,nSignals,nLags,nFiles);
Awtd=NaN(nSignals,nSignals,nLags,nFiles);
AwtdCut=zeros(nSignals,nSignals,nLags,nFiles);
charLagFirstPeak=zeros(nSignals,nSignals,nFiles);
TcharLagFirstPeak=zeros(nSignals,nSignals,nFiles);
charLagMaxPeak=zeros(nSignals,nSignals,nFiles);
TcharLagMaxPeak=zeros(nSignals,nSignals,nFiles);
TvsIzerocharLagMaxPeak=zeros(nSignals,nSignals,nFiles);
nSigLags=zeros(nSignals,nSignals,nFiles);
FirstSigLag=NaN(nSignals,nSignals,nFiles);
LastSigLag=NaN(nSignals,nSignals,nFiles);
% Find index of lag = 0
l0i = find(lagVect == 0,1);
for f=1:nFiles
for sX=1:nSignals
for sY=1:nSignals
FirstPeakFlag=0;
FirstSigFlag=0;
Awtd=T;
%check 0 lag
lag=l0i;
% Statistical sig threshold available for 1 or all lags?
if nSLags == 1
lagS = 1;
else
lagS = lag;
end
if T(sX,sY,lag,f) > SigThreshT(sX,sY,lagS,f)
Abinary(sX,sY,lag,f) = 1;
AwtdCut(sX,sY,lag,f) = T(sX,sY,lag,f);
LastSigLag(sX,sY,f)=lag;
nSigLags(sX,sY,f)=nSigLags(sX,sY,f)+1;
charLagMaxPeak(sX,sY,f)=lag;
TcharLagMaxPeak(sX,sY,f)=T(sX,sY,lag,f);
TvsIzerocharLagMaxPeak(sX,sY,f)=TvsIzero(sX,sY,lag,f);
FirstSigFlag=1;
if nLags > 1
if T(sX,sY,lag,f) > T(sX,sY,lag+1,f)
charLagFirstPeak(sX,sY,f)=lag;
TcharLagFirstPeak(sX,sY,f)=T(sX,sY,lag,f);
FirstPeakFlag = 1;
end
else
charLagFirstPeak(sX,sY,f)=lag;
TcharLagFirstPeak(sX,sY,f)=T(sX,sY,lag,f);
FirstPeakFlag = 1;
end
end
%check the other lag
if nLags > 1
for lag=l0i+1:nLags-1
% Statistical sig threshold available for 1 or all lags?
if nSLags == 1
lagS = 1;
else
lagS = lag;
end
if T(sX,sY,lag,f) > SigThreshT(sX,sY,lagS,f)
Abinary(sX,sY,lag,f) = 1;
AwtdCut(sX,sY,lag,f) = T(sX,sY,lag,f);
LastSigLag(sX,sY,f)=lag;
nSigLags(sX,sY,f)=nSigLags(sX,sY,f)+1;
if FirstSigFlag == 0
FirstSigLag(sX,sY,f)=lag;
FirstSigFlag = 1;
end
if FirstPeakFlag == 0 && T(sX,sY,lag,f) > T(sX,sY,lag-1,f) && T(sX,sY,lag,f) > T(sX,sY,lag+1,f)
charLagFirstPeak(sX,sY,f)=lag;
TcharLagFirstPeak(sX,sY,f)=T(sX,sY,lag,f);
FirstPeakFlag = 1;
end
if T(sX,sY,lag) > TcharLagMaxPeak(sX,sY,f)
charLagMaxPeak(sX,sY,f)=lag;
TcharLagMaxPeak(sX,sY,f)=T(sX,sY,lag,f);
TvsIzerocharLagMaxPeak(sX,sY,f)=TvsIzero(sX,sY,lag,f);
end
end
end
%check the last lag
lag=nLags;
% Statistical sig threshold available for 1 or all lags?
if nSLags == 1
lagS = 1;
else
lagS = lag;
end
if T(sX,sY,lag,f) > SigThreshT(sX,sY,lagS,f)
Abinary(sX,sY,lag,f) = 1;
AwtdCut(sX,sY,lag,f) = T(sX,sY,lag,f);
LastSigLag(sX,sY,f)=lag;
nSigLags(sX,sY,f)=nSigLags(sX,sY,f)+1;
if FirstSigFlag == 0
FirstSigLag(sX,sY,f)=lag;
FirstSigFlag = 1;
end
if FirstPeakFlag == 0 && T(sX,sY,lag,f) > T(sX,sY,lag-1,f)
charLagFirst(sX,sY,f)=lag;
TcharLagFirst(sX,sY,f)=T(sX,sY,lag,f);
FirstPeakFlag = 1;
end
if T(sX,sY,lag,f) > TcharLagMaxPeak(sX,sY,f)
charLagMaxPeak(sX,sY,f)=lag;
TcharLagMaxPeak(sX,sY,f)=T(sX,sY,lag,f);
TvsIzerocharLagMaxPeak(sX,sY,f)=TvsIzero(sX,sY,lag,f);
end
end
end
end
end
end