-
Notifications
You must be signed in to change notification settings - Fork 1
/
synthetic_dataset_eval.m
457 lines (366 loc) · 10.5 KB
/
synthetic_dataset_eval.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
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
function synthetic_dataset_eval(n, T, r, alpha, nSim)
%%SYNTHETIC_DATASET_EVAL: This function is responsible for performing
% comparisons for a number of synthetic datasets against three streaming
% algorithms to compute the r-truncated SVD out of an incoming sequence
% of vectors
%
% Author: Andreas Grammenos ([email protected])
%
% Last touched date: 30/12/2018
%
% License: GPLv3
%
%% Initialise
% scope-in the global variables
global pflag;
global use_fast_moses_only
global use_offline_svds
global use_fdr
% sanity checks
if n > T
fprintf("\n !! Error ambient dim (n) must be lower than T\n");
return
end
%% Print iteration info
fprintf("\n ** Running evaluation with parameters:\n");
fprintf("\n\tPower law alpha=%d", alpha);
fprintf("\n\tAmbient dim: %d", n);
fprintf("\n\tTime (in number of Columns): %d", T);
fprintf("\n\tTarget rank: %d", r);
fprintf("\n\tPrint flag is: %d\n", pflag);
%% Run the simulation
%profile on
% run the initial simulation
fprintf("\n ** Simulation number 1 **\n");
[MosesT, MosesError, MosesFroT, ...
MosesFT, MosesFError, MosesFFrotT, ...
PowerT, PowerError, PowerFroT, ...
FDT, FDError, FDFroT, ...
FDRT, FDRError, FDRFroT, ...
GrouseT, GrouseError, GrouseFroT, ...
OfflineT, OfflineError, OfflineFroT, ...
Sigma] = online_svds_synthetic(n, r, T, alpha);
% Frobenius norm error normalised per block
% Power Method
PEs = nan(nSim, length(PowerT));
PEs(1, :) = PowerError;
% GROUSE
GREs = nan(nSim, length(GrouseT));
GREs(1, :) = GrouseError;
% Moses fast
MFEs = nan(nSim, length(MosesFT));
MFEs(1, :) = MosesFError;
% Frequent Directions
FDEs = nan(nSim, length(FDT));
FDEs(1, :) = FDError;
% Robust Frequent Directions
FDREs = nan(nSim, length(FDRT));
FDREs(1, :) = FDRError;
% MSE Errors
o_froT = nan(nSim, 1);
p_froT = nan(nSim, 1);
g_froT = nan(nSim, 1);
mf_froT = nan(nSim, 1);
fd_froT = nan(nSim, 1);
% assign the first values
o_froT(1) = OfflineFroT;
p_froT(1) = PowerFroT;
g_froT(1) = GrouseFroT;
mf_froT(1) = MosesFFrotT;
fd_froT(1) = FDFroT;
% Only use that if we have Moses simple
if use_fast_moses_only == 0
MEs = nan(nSim, length(MosesT));
MEs(1,:) = MosesError;
m_froT = nan(nSim, 1);
m_froT(1) = MosesFroT;
end
% Only use that if we have fdr enabled
if use_fdr == 1
fdr_froT = nan(nSim, 1);
fdr_froT(1) = FDRFroT;
end
if use_offline_svds == 1
% Offline SVD error
OffEs = nan(nSim, length(OfflineT));
OffEs(1, :) = OfflineError;
end
%profile off
%profile viewer
%pause
% loop for the remaining simulation
for i = 2:nSim
fprintf("\n ** Simulation number %d **\n", i);
[~, MosesError, MosesFroT, ...
~, MosesFError, MosesFFrotT, ...
~, PowerError, PowerFroT, ...
~, FDError, FDFroT, ...
~, FDRError, FDRFroT, ...
~, GrouseError, GrouseFroT, ...
~, OfflineError, OfflineFroT, ~] = online_svds_synthetic(n, r, T, alpha);
% Frobenius norm error normalised with k^{.5}B
PEs(i, :) = PowerError;
GREs(i, :) = GrouseError;
MFEs(i, :) = MosesFError;
FDEs(i, :) = FDError;
% Final Frobenius norm normalised with T error
o_froT(i) = OfflineFroT;
p_froT(i) = PowerFroT;
g_froT(i) = GrouseFroT;
mf_froT(i) = MosesFFrotT;
fd_froT(i) = FDFroT;
if use_fast_moses_only == 0
MEs(i, :) = MosesError;
m_froT(i) = MosesFroT;
end
if use_fdr == 1
FDREs(i, :) = FDRError;
fdr_froT(i) = FDRFroT;
end
if use_offline_svds == 1
OffEs(i, :) = OfflineError;
end
end
% calculate relative metrics
% moses fast averaged metrics
AvMFE = mean(MFEs);
% power method averaged metrics
AvPE = mean(PEs);
% grouse metrics
AvGR = mean(GREs);
% fd metrics
AvFD = mean(FDEs);
% fdr metrics
AvFDR = mean(FDREs);
% moses simple averaged metrics
if use_fast_moses_only == 0
AvME = mean(MEs);
end
% offline averaged metrics
if use_offline_svds == 1
AvOffE = mean(OffEs);
end
%% Display scree plot of population distribution
fig = figure;
subplot(2,1,1)
plot(1:n, sqrt(diag(Sigma).^2));
title(['Population scree plot (alpha: ' num2str(alpha) ')'])
xlabel('rank'); ylabel('singular value')
%% Display error relative to T
subplot(2,1,2)
plot(MosesFT, AvMFE, 'LineWidth', 2);
hold on
% plot moses simple only if we have to
if use_fast_moses_only == 0
plot(MosesT, AvME, 'LineWidth', 1);
end
plot(PowerT, AvPE, 'LineWidth', 2);
plot(FDT, AvFD, 'LineWidth', 2);
% plot fdr only if we have to
if use_fdr == 1
plot(FDRT, AvFDR, 'LineWidth', 2);
end
plot(GrouseT, AvGR, 'LineWidth', 2);
% plot offline svds only if we have to
if use_offline_svds == 1
plot(OfflineT, AvOffE, 'LineWidth', 2);
end
hold off;
title('Rescaled error of Y_r relative to Y');
xlabel('samples'); ylabel('error');
% full legend cells
legendCells = {'MOSES', 'MOSES_s', 'PM', 'FD', 'FDR', 'GROUSE'};
% remove moses simple if we are only running fast
if use_fast_moses_only == 1
idc = ismember(legendCells, {'MOSES_s'});
legendCells = legendCells(~idc);
end
% remove fdr if need be
if use_fdr == 0
idc = ismember(legendCells, {'FDR'});
legendCells = legendCells(~idc);
end
% add the offline cell to the legends
if use_offline_svds == 1
legendCells{end+1} = 'Offline';
end
% finally set the legends
legend(legendCells, 'Location', 'best');
% set the figure limits
xlim([1, T])
% set the axis labels correctly
xlabel('samples'); ylabel('error');
% output figure to file if printing is enabled
t = sprintf("synthetic_froerror_n_%s_r_%s_alpha_%s_nsim_%s", ...
num2str(n), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
print_fig(fig, t);
%% Display the error relative to T as a singular plot
fig = figure;
plot(MosesFT, AvMFE, 'LineWidth', 2);
hold on
% plot moses simple only if we have to
if use_fast_moses_only == 0
plot(MosesT, AvME, 'LineWidth', 1);
end
plot(PowerT, AvPE, 'LineWidth', 2);
plot(FDT, AvFD, 'LineWidth', 2);
if use_fdr == 1
plot(FDRT, AvFDR, 'LineWidth', 2);
end
plot(GrouseT, AvGR, 'LineWidth', 2);
% plot offline svds only if we have to
if use_offline_svds == 1
plot(OfflineT, AvOffE, 'LineWidth', 2);
end
hold off;
title('Rescaled error of Y_r relative to Y');
xlabel('samples'); ylabel('error');
% full legend cells
legendCells = {'MOSES', 'MOSES_s', 'PM', 'FD', 'FDR', 'GROUSE'};
% remove moses simple if we are only running fast
if use_fast_moses_only == 1
idc = ismember(legendCells, {'MOSES_s'});
legendCells = legendCells(~idc);
end
% remove fdr if need be
if use_fdr == 0
idc = ismember(legendCells, {'FDR'});
legendCells = legendCells(~idc);
end
% add the offline cell to the legends
if use_offline_svds == 1
legendCells{end+1} = 'Offline';
end
% plot the correct legends
legend(legendCells, 'Location', 'SouthEast');
% set the figure limits
xlim([1, T])
% set the axis labels correctly
xlabel('samples'); ylabel('error');
% output figure to file if printing is enabled
t = sprintf("synthetic_froerror_noscree_n_%s_r_%s_alpha_%s_nsim_%s", ...
num2str(n), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
print_fig(fig, t);
%% Display only MOSES vs Power vs FD error over time
fig = figure;
hold on;
plot(MosesFT, AvMFE, 'LineWidth', 2);
plot(PowerT, AvPE, 'LineWidth', 2);
plot(FDT, AvFD, 'LineWidth', 2);
% plot fdr if enabled
if use_fdr == 1
plot(FDRT, AvFDR, 'LineWidth', 2);
end
hold off;
if use_fdr == 1
legend('MOSES', 'PM', 'FD', 'FDR');
title('MOSES vs PM vs FD vs FDR Comparison');
t = sprintf("synthetic_froerror_moses_vs_pm_vs_fd_vs_fdr_n_%s_T_%sk_r_%s_alpha_%s_nsim_%s", ...
num2str(n), strrep(num2str(T/1000), ".", "_"), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
else
legend('MOSES', 'PM', 'FD');
title('MOSES vs PM vs FD Comparison');
t = sprintf("synthetic_froerror_moses_vs_pm_vs_fd_n_%s_T_%sk_r_%s_alpha_%s_nsim_%s", ...
num2str(n), strrep(num2str(T/1000), ".", "_"), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
end
print_fig(fig, t);
%% Display error relative to the Frobenius norm over T of final Y_r against Y
fig = figure;
subplot(2,1,1)
hold on
plot(o_froT);
plot(mf_froT);
if use_fast_moses_only == 0
plot(m_froT);
end
plot(p_froT);
plot(fd_froT);
% plot fdr only we have to
if use_fdr == 1
plot(fdr_froT);
end
plot(g_froT);
hold off;
title(['Error of final Y_r vs real Y over ' num2str(nSim) ' sims']);
xlabel('simulation number'); ylabel('error');
% full legend cells
legendCells = {'MOSES', 'MOSES_s', 'PM', 'FD', 'FDR', 'GROUSE'};
% remove moses simple if we are only running fast
if use_fast_moses_only == 1
idc = ismember(legendCells, {'MOSES_s'});
legendCells = legendCells(~idc);
end
% remove fdr if need be
if use_fdr == 0
idc = ismember(legendCells, {'FDR'});
legendCells = legendCells(~idc);
end
% finally set the legend cells
legend(legendCells);
subplot(2,1,2)
plot(mf_froT, 'LineWidth', 2);
hold on
plot(p_froT, 'LineWidth', 2);
plot(fd_froT, 'LineWidth', 2);
% plot fdr only we have to
if use_fdr == 1
plot(fdr_froT, 'LineWidth', 2);
end
hold off;
% full legend cells
legendCells = {'MOSES', 'PM', 'FD', 'FDR'};
% remove fdr if need be
if use_fdr == 0
idc = ismember(legendCells, {'FDR'});
legendCells = legendCells(~idc);
title('Power Method vs MOSES vs FD');
else
title('Power Method vs MOSES vs FD vs FDR');
end
legend(legendCells);
xlabel('iterations'); ylabel('error');
% output figure to file if printing is enabled
t = sprintf("synthetic_fro_over_t_error_n_%s_T_%sk_r_%s_alpha_%s_nsim_%s", ...
num2str(n), strrep(num2str(T/1000), ".", "_"), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
print_fig(fig, t);
%% Display error relative to the Frobenius norm over T of final Y_r against Y
% for only MOSES and PM
fig = figure;
plot(mf_froT, 'LineWidth', 2);
hold on
plot(p_froT, 'LineWidth', 2);
plot(fd_froT, 'LineWidth', 2);
% plot fdr only we have to
if use_fdr == 1
plot(fdr_froT, 'LineWidth', 2);
end
hold off;
% full legend cells
legendCells = {'MOSES', 'PM', 'FD', 'FDR'};
% remove fdr if need be
if use_fdr == 0
idc = ismember(legendCells, {'FDR'});
legendCells = legendCells(~idc);
title('MOSES vs Power Method vs FD');
else
title('MOSES vs Power Method vs FD vs FDR');
end
legend(legendCells);
xlabel('iterations'); ylabel('error');
% output figure to file if printing is enabled
t = sprintf("synthetic_fro_over_t_error_single_n_%s_T_%sk_r_%s_alpha_%s_nsim_%s", ...
num2str(n), strrep(num2str(T/1000), ".", "_"), num2str(r), ...
strrep(num2str(alpha), ".", "_"), ...
strrep(num2str(nSim), ".", "_"));
print_fig(fig, t);
end