-
Notifications
You must be signed in to change notification settings - Fork 0
/
Test_Sergio_Acop_EEG.asv
195 lines (122 loc) · 5.38 KB
/
Test_Sergio_Acop_EEG.asv
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
clear all
close all
clc
electrode_run_type='test'; %'random_electrodes'; %selected_electrodes
data_run_type= 'data_shuffle'; %'normal';%trial_shuffle %data_shuffle
%
% electrode_number=90;
% electrode_selected_number=10;
electrodes=[1 11]; %Case of selected electrodes
stage='Baseline'
load(['P12/' stage '.mat']);
BindinERPs_RED_temp=cond(1).data(:,512:end,:); %1:100; retention baseline - 512:end ; retention stage
FeaturesERPs_RED_temp=cond(2).data(:,512:end,:);
complete_temp=cat(3,BindinERPs_RED_temp,FeaturesERPs_RED_temp);
setenv('PATH', [getenv('PATH') ';C:\Program Files\R\R-3.3.2\bin\']);
system('rm CSV/*');
%%
BindinERPs_RED=BindinERPs_RED_temp;
FeaturesERPs_RED=FeaturesERPs_RED_temp;
for t=1:100
t
% Shuffle
shufflevect=randperm(size(complete_temp,3));
BindinERPs_RED=complete_temp(:,:,shufflevect(1:65));
FeaturesERPs_RED=complete_temp(:,:,shufflevect(65:130));
trials=size(BindinERPs_RED,3);
electrode_selected_number=size(electrodes,2)
selection=electrodes;
nUnits=size(BindinERPs_RED,1);
for iter=1:trials
Bind(iter,:)=squeeze(mean(BindinERPs_RED(selection,:,iter),2));
Feat(iter,:)=squeeze(mean(FeaturesERPs_RED(selection,:,iter),2));
end
%Test independence bewteen signals
if (rank(Bind)==size(Bind,2)) && (rank(Feat)==size(Feat,2))
ok=1;
else
error('Non-independent data matrix');
end
Complete=[Bind' Feat'];
Hfeatnorm=0.25*log(det(cov(zscore(Feat))));
Hbindnorm=0.25*log(det(cov(zscore(Bind))));
Hnorm=0.5*log(det(cov(zscore(Complete'))));
fit_size=2*electrode_selected_number+sum([1:1:electrode_selected_number])+1;
csvwrite(['CSV/Binding.csv'],Bind);
csvwrite(['CSV/Features.csv'],Feat);
Complete=[Bind' Feat'];
csvwrite(['CSV/Complete.csv'],Complete');
csvwrite(['CSV/FitSize.csv'],fit_size);
%%
%!unset DYLD_LIBRARY_PATH; Rscript skewNromalFitBind.R
!Rscript skewNromalFitBind.R
snParamBind = csvread('skewNromalFitedDataBind.csv');
% snParam(snParam==-999999)=NaN;
!Rscript skewNromalFitFeat.R
snParamFeat = csvread('skewNromalFitedDataFeat.csv');
% snParamBind(snParam==-999999)=NaN;
!Rscript skewNromalFit.R
snParam = csvread('skewNromalFitedData.csv');
% snParamFeat(snParamGO==-999999)=NaN;
%%
for n=1:size(snParam,1)
alfainit=electrode_selected_number+sum([1:1:electrode_selected_number])+1;
alfaend=alfainit+electrode_selected_number-1;
alfa=snParam(n,alfainit:alfaend);
likelihood=snParam(end);
init=electrode_selected_number+1;
for i=1:electrode_selected_number %for 10 channels
l=electrode_selected_number-i ;% #components
omega(i,i:electrode_selected_number)=snParam(1,init:(init+l));
omega(i:electrode_selected_number,i)=snParam(1,init:(init+l));
init=(init+l+1);
end
M=100000;
a=randn(100000,1);
b=randn(100000,1);
W(find(sqrt(alfa*alfa')*a>b))=a(find(sqrt(alfa*alfa')*a>b));
W(find(sqrt(alfa*alfa')*a<=b))=-a(find(sqrt(alfa*alfa')*a<=b));
H(n) = 1/2*log((det(omega))) + 1 + log(2*pi) - mean(2*log(normcdf(sqrt(alfa*alfa')*W)));
%BIND
alfaBind=snParamBind(n,alfainit:alfaend);
likelihoodbind=snParamBind(end);
init=electrode_selected_number+1;
for i=1:electrode_selected_number
l=electrode_selected_number-i ;% #components
omegaBind(i,i:electrode_selected_number)=snParamBind(1,init:(init+l));
omegaBind(i:electrode_selected_number,i)=snParamBind(1,init:(init+l));
init=(init+l+1);
end
M=100000;
a=randn(100000,1);
b=randn(100000,1);
W(find(sqrt(alfaBind*alfaBind')*a>b))=a(find(sqrt(alfaBind*alfaBind')*a>b));
W(find(sqrt(alfaBind*alfaBind')*a<=b))=-a(find(sqrt(alfaBind*alfaBind')*a<=b));
HBind(n) = 1/2*log((det(omegaBind))) + 1 + log(2*pi) - mean(2*log(normcdf(sqrt(alfaBind*alfaBind')*W)));
%FEAT
alfaFeat=snParamFeat(n,alfainit:alfaend);
likelihoodFeat=snParamFeat(end);
init=electrode_selected_number+1;
for i=1:electrode_selected_number %for 10 channels
l=electrode_selected_number-i ;% #components
omegaFeat(i,i:electrode_selected_number)=snParamFeat(1,init:(init+l));
omegaFeat(i:electrode_selected_number,i)=snParamFeat(1,init:(init+l));
init=(init+l+1);
end
M=100000;
a=randn(100000,1);
b=randn(100000,1);
W(find(sqrt(alfaFeat*alfaFeat')*a>b))=a(find(sqrt(alfaFeat*alfaFeat')*a>b));
W(find(sqrt(alfaFeat*alfaFeat')*a<=b))=-a(find(sqrt(alfaFeat*alfaFeat')*a<=b));
HFeat(n) = 1/2*log((det(omegaFeat))) + 1 + log(2*pi) - mean(2*log(normcdf(sqrt(alfaFeat*alfaFeat')*W)));
end
MI(t)=H - 1/2*HFeat - 1/2*HBind
HH(t)=H;
HHf(t)=HFeat;
HHb(t)=HBind;
%%
end
Miprom=mean(MI);
HHprom=mean(HH);
HHfprom=mean(HHf);
HHbprom=mean(HHb);