forked from neurominer-git/NeuroMiner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnk_CheckLoadFile.m
More file actions
276 lines (250 loc) · 13 KB
/
Copy pathnk_CheckLoadFile.m
File metadata and controls
276 lines (250 loc) · 13 KB
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
function [out, fnd, out2, out3, out4] = nk_CheckLoadFile(pth, filetyp, f, d, ovrwrt, nclass)
global FUSION RAND
% Check file type
a = regexp(filetyp,'CVdatamat','ONCE'); if ~isempty(a), a=1; else, a=0; end
nvar = size(pth,1); % get number of variates
out = []; fnd = false; out2=[]; out3 = [];
if ~exist('ovrwrt','var') || isempty(ovrwrt), ovrwrt = false; end
% Addition of 11/05/2024: Dealing with missing data
if ~isfield(FUSION,'DealWithCompleteNanRows')
DealWithCompleteNanRows = 1;
else
DealWithCompleteNanRows = FUSION.DealWithCompleteNanRows;
end
for i=1:nvar
px = deblank(pth(i,:));
if exist(px,'file')
fnd = true;
if ovrwrt
fprintf('\nFound %s file, CV2 partition [%g,%g].',filetyp, f, d)
else
[~,n] = fileparts(px);
if ~a
fprintf('\nFound %s file for modality #%g, CV2 partition [%g,%g].',filetyp, i, f, d)
else
fprintf('\nFound %s file, CV2 partition [%g,%g].',filetyp, f, d)
end
loadstr = sprintf('\nLoading %s file:\n%s',filetyp, n);
fprintf(loadstr);
try
load(px);
catch
fprintf('\nCould not open file. May be corrupt. Recompute CV2 partition [%g,%g].',f,d);
fnd = false;
return
end
if exist('GD','var')
out = GD;
elseif exist('pGD','var')
out = pGD;
elseif exist('mapY','var')
[iy,jy] = size(mapY.Tr);
switch FUSION.flag % Concatenate modality data into single structure
case 2 % Intermediate fusion
if ~iscell(mapY.Tr{1,1}{1})
t_nclass = 1;
multiproc = true;
else
t_nclass = nclass;
multiproc = false;
end
if i == 1
out = mapY;
out.Tr = cell(iy,jy);
out.CV = cell(iy,jy);
out.Ts = cell(iy,jy);
out.VI = cell(iy,jy);
if ~multiproc
for k=1:iy
for l=1:jy
out.Tr{k,l} = cell(t_nclass,1);
out.CV{k,l} = cell(t_nclass,1);
out.Ts{k,l} = cell(t_nclass,1);
out.VI{k,l} = cell(t_nclass,1);
end
end
end
end
if i>1, fprintf('\nAdding data of modality #%g to single data matrix.',i); end
for k=1:iy
for l=1:jy
for j=1:t_nclass
% in multi-class preprocessing we don't
% have a one-nested cell array as data
% container, e.g.
% mapY.Tr{CV1 perm, CV1 fold}{data shelves}
if multiproc
TR = mapY.Tr{k,l};
CV = mapY.CV{k,l};
TS = mapY.Ts{k,l};
nZo = size(out.Tr{k,l},1);
else
% in binary preprocessing we have a
% two-nested cell arrays as data
% containers, e.g.:
% mapY.Tr{CV1 perm, CV1 fold}{binary classifier}{data shelves}
TR = mapY.Tr{k,l}{j};
CV = mapY.CV{k,l}{j};
TS = mapY.Ts{k,l}{j};
nZo = size(out.Tr{k,l}{j},1);
end
if i>1
% Create mixtures of data shelves,
% if modality concatenation is
% activated
cnt = 1;
nZp = size(TR,1);
MixCount = nZo * nZp;
tOut.Tr = cell(MixCount,1);
tOut.CV = cell(MixCount,1);
tOut.Ts = cell(MixCount,1);
tOut.VI = cell(MixCount,1);
for zp = 1:nZp
for zo = 1:nZo
if multiproc
tOut.Tr{cnt} = [ out.Tr{k,l}{zo}, TR{zp} ];
tOut.CV{cnt} = [ out.CV{k,l}{zo}, CV{zp} ];
tOut.Ts{cnt} = [ out.Ts{k,l}{zo}, TS{zp} ];
tOut.VI{cnt} = [ out.VI{k,l}{zo}; i*ones(size(TR{zp},2),1) ];
else
tOut.Tr{cnt} = [ out.Tr{k,l}{j}{zo}, TR{zp} ];
tOut.CV{cnt} = [ out.CV{k,l}{j}{zo}, CV{zp} ];
tOut.Ts{cnt} = [ out.Ts{k,l}{j}{zo}, TS{zp} ];
tOut.VI{cnt} = [ out.VI{k,l}{j}{zo}; i*ones(size(TR{zp},2),1) ];
end
cnt = cnt+1;
end
end
if multiproc
out.Tr{k,l} = tOut.Tr;
out.CV{k,l} = tOut.CV;
out.Ts{k,l} = tOut.Ts;
out.VI{k,l} = tOut.VI;
else
out.Tr{k,l}{j} = tOut.Tr;
out.CV{k,l}{j} = tOut.CV;
out.Ts{k,l}{j} = tOut.Ts;
out.VI{k,l}{j} = tOut.VI;
end
clear tOut;
else
if multiproc
out.Tr{k,l} = TR;
out.CV{k,l} = CV;
out.Ts{k,l} = TS;
for m=1:numel(TR)
out.VI{k,l}{m} = ones(size(TR{m},2),1);
end
else
out.Tr{k,l}{j} = TR;
out.CV{k,l}{j} = CV;
out.Ts{k,l}{j} = TS;
for m=1:numel(TR)
out.VI{k,l}{j}{m} = ones(size(TR{m},2),1);
end
end
end
end
end
end
case {0,1,3,4} % Create structure storing modality information separately
if i == 1
out = mapY;
out.Tr = cell(iy,jy,nvar);
out.CV = cell(iy,jy,nvar);
out.Ts = cell(iy,jy,nvar);
if size(mapY.Tr{1,1},2) == nclass
for g=1:nvar
for k=1:iy
for l=1:jy
out.Tr{k,l,g} = cell(1,nclass);
out.CV{k,l,g} = cell(1,nclass);
out.Ts{k,l,g} = cell(1,nclass);
end
end
end
end
end
for k=1:iy
for l=1:jy
if size(mapY.Tr{k,l},2) == nclass && ~RAND.Decompose == 9
for j=1:nclass % loop through binary
% Concatenate CV1 training data
out.Tr{k,l,i}(:,j) = mapY.Tr{k,l}(:,j);
% Concatenate CV1 test data
out.CV{k,l,i}(:,j) = mapY.CV{k,l}(:,j);
% Concatenate CV2 test data
out.Ts{k,l,i}(:,j) = mapY.Ts{k,l}(:,j);
end
else
out.Tr{k,l,i} = mapY.Tr{k,l};
% Concatenate CV1 test data
out.CV{k,l,i} = mapY.CV{k,l};
% Concatenate CV2 test data
out.Ts{k,l,i} = mapY.Ts{k,l};
end
end
end
end
elseif exist('mapYocv','var')
[iy,jy] = size(mapYocv.Ts);
switch FUSION.flag % Concatenate modality data into single structure
case 2
if i == 1
out = mapYocv; out.Ts = cell(iy,jy);
if iscell(mapYocv.Ts{1,1})
for k=1:iy
for l=1:jy
out.Ts{k,l} = cell(nclass,1);
end
end
end
end
if i >1, fprintf('\nAdding data of modality #%g to single data matrix.',i); end
for k=1:iy
for l=1:jy
if iscell(mapYocv.Ts{k,l})
for j=1:nclass % loop through binary
% Concatenate CV2 test data
out.Ts{k,l}{j} = [out.Ts{k,l}{j} mapYocv.Ts{k,l}{j}];
end
else
% Concatenate CV2 test data
out.Ts{k,l} = [out.Ts{k,l} mapYocv.Ts{k,l}];
end
end
end
case {0,1,3,4} % Create structure storing modality information separately for MKL
if i == 1
out = mapYocv;
out.Ts = cell(iy,jy,nvar);
end
for k=1:iy
for l=1:jy
if iscell(mapYocv.Ts{k,l})
for j=1:nclass % loop through binary
% Concatenate CV2 test data
out.Ts{k,l,i}{j} = mapYocv.Ts{k,l}{j};
end
else
% Concatenate CV2 test data
out.Ts{k,l,i} = mapYocv.Ts{k,l};
end
end
end
end
end
end
if exist('MD','var')
out2=MD;
end
if exist('xpos','var')
out3=xpos;out4=ypos;
end
end
end
if exist('mapY','var') && (FUSION.flag == 1 || FUSION.flag == 2)
fprintf('\nChecking combined data shelves for missing data.')
[iy,jy] = size(mapY.Tr);
out = nk_DealWithNaNCases(out, iy, jy, nclass, DealWithCompleteNanRows);
end