-
Notifications
You must be signed in to change notification settings - Fork 1
/
nk_CheckLoadFile.m
204 lines (185 loc) · 9.48 KB
/
nk_CheckLoadFile.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
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
function [out, fnd, out2, out3, out4] = nk_CheckLoadFile(pth, filetyp, f, d, ovrwrt, nclass)
global FUSION
% 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
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
[p,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);
load(px);
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
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 iscell(mapY.Tr{1,1})
for k=1:iy
for l=1:jy
out.Tr{k,l} = cell(nclass,1);
out.CV{k,l} = cell(nclass,1);
out.Ts{k,l} = cell(nclass,1);
out.VI{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
for j=1:nclass
if i>1
% Create mixtures of data shelves,
% if modality concatenation is
% activated
cnt = 1;
nZo = size(out.Tr{k,l}{j},1);
nZp = size(mapY.Tr{k,l}{j},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
tOut.Tr{cnt} = [ out.Tr{k,l}{j}{zo}, mapY.Tr{k,l}{j}{zp} ];
tOut.CV{cnt} = [ out.CV{k,l}{j}{zo}, mapY.CV{k,l}{j}{zp} ];
tOut.Ts{cnt} = [ out.Ts{k,l}{j}{zo}, mapY.Ts{k,l}{j}{zp} ];
tOut.VI{cnt} = [ out.VI{k,l}{j}{zo}; i*ones(size(mapY.Tr{k,l}{j}{zp},2),1) ];
cnt = cnt+1;
end
end
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;
clear tOut;
else
out.Tr{k,l}{j} = mapY.Tr{k,l}{j};
out.CV{k,l}{j} = mapY.CV{k,l}{j};
out.Ts{k,l}{j} = mapY.Ts{k,l}{j};
for m=1:numel(mapY.Tr{k,l}{j})
out.VI{k,l}{j}{m} = ones(size(mapY.Tr{k,l}{j}{m},2),1);
end
end
end
end
end
case {0,1,3,4} % Create structure storing modality information separately for MKL
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
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