-
Notifications
You must be signed in to change notification settings - Fork 8
/
test_execution_time.m
214 lines (185 loc) · 5.75 KB
/
test_execution_time.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
% The script is designed to evaluate the speed of F-PCA against other
% competing methods - specifically we compare against:
%
% - PM: https://arxiv.org/pdf/1307.0032.pdf
% - GROUSE: https://arxiv.org/pdf/1702.01005.pdf
% - SPIRIT: https://dl.acm.org/doi/10.5555/1083592.1083674
% - FD: https://arxiv.org/abs/1501.01711.pdf
%
% The following parameters can be configured:
%
% - n: the ambient dimension
% - r: r-truncation target
% - alpha: parameter for the power law distribution
% - trials: the number of performance runs for each parameter tuple.
%
% We define the above as a parameter tuple and the defaults are the
% following: (200:200:1000, 10, 1, 5)
%
% Based on work of Grammenos et al.: https://arxiv.org/abs/1907.08059
%
% Author: Andreas Grammenos (ag926@cl.cam.ac.uk)
%
% Last touched date: 08/06/2020
%
% License: GPLv3
%
%% Initialisation
% fist clear everything
clear; close all; clc;
% trial parameters
d = 200:200:1000;
r = 10;
trials = 3;
T = 0;
use_log_plot = 0;
% dataset parameters
synth_params.spectrum_type = "pl";
synth_params.lambda = 1;
synth_params.alpha = 1;
% general parameters
params.pflag = 1;
params.type = "speed-test";
% setup the parameters
params = setup_vars(params);
% raise the no error flag for speed tests
no_err = 1;
% number of parameter tuples
param_num = size(d, 2);
% preallocate time arrays
fpca_ta = zeros(param_num, trials);
fpca_mask_ta = zeros(param_num, trials);
pm_ta = zeros(param_num, trials);
gr_ta = zeros(param_num, trials);
fd_ta = zeros(param_num, trials);
sp_ta = zeros(param_num, trials);
if T < 2000
fprintf("\n ** WARN: T must be at least 2k, reverting to default 10k\n");
T = 10000;
end
%% Run the trials
% now run the speed test
for i = 1:param_num
fprintf("\n ** Starting speed %d trials for: d=%d, r=%d\n", trials, d(i), r);
% run the number of specified trials
for j = 1:trials
fprintf("\n -- Trial no: %d...\n", j);
% first, generate the synthetic data for that trial
Y = synthetic_data_gen(d(i), T, synth_params);
% secondly, execute the timed runs
clear params_fpca
params_fpca.verbose = 0;
[~, ~, fpca_opts] = fpca_edge(Y, r, params_fpca);
clear params_fpca_mask
params_fpca_mask.verbose = 0;
params_fpca_mask.private = 1;
[~, ~, fpca_mask_opts] = fpca_edge(Y, r, params_fpca_mask);
[~, pm_opts] = mitliag_pm(Y, r);
[~, ~, gr_opts] = my_grouse(Y, r);
[~, fd_opts] = fd(Y', r);
clear params_sp
params_sp.verbose = 0;
[~, sp_opts] = SPIRIT(Y', 0.95, [0.95,0.98], params_sp);
% then, set the execution time for this trial
fpca_ta(i, j) = fpca_opts.t;
fpca_mask_ta(i, j) = fpca_mask_opts.t;
pm_ta(i, j) = pm_opts.t;
gr_ta(i, j) = gr_opts.t;
fd_ta(i, j) = fd_opts.t;
sp_ta(i, j) = sp_opts.t;
% clear the structures
clear params_fpca;
clear params_fpca_mask;
clear params_sp;
end
fprintf("\nFinished running %d trials...\n", j);
end
%% Plot the results
% find the means for the speed runs
if use_log_plot == 1
mtr_fpca = log(mean(fpca_ta, 2));
mtr_mask_fpca = log(mean(fpca_mask_ta, 2));
mtr_pm = log(mean(pm_ta, 2));
mtr_gr = log(mean(gr_ta, 2));
mtr_fd = log(mean(fd_ta, 2));
mtr_sp = log(mean(sp_ta, 2));
% find the std for the speed runs
str_fpca = log(std(fpca_ta, 0, 2));
str_mask_fpca = log(std(fpca_mask_ta, 0, 2));
str_pm = log(std(pm_ta, 0, 2));
str_gr = log(std(gr_ta, 0, 2));
str_fd = log(std(fd_ta, 0, 2));
str_sp = log(std(sp_ta, 0, 2));
else
% find the means for the speed runs
mtr_fpca = mean(fpca_ta, 2);
mtr_mask_fpca = mean(fpca_mask_ta, 2);
mtr_pm = mean(pm_ta, 2);
mtr_gr = mean(gr_ta, 2);
mtr_fd = mean(fd_ta, 2);
mtr_sp = mean(sp_ta, 2);
% find the std for the speed runs
str_fpca = std(fpca_ta, 0, 2);
str_mask_fpca = std(fpca_mask_ta, 0, 2);
str_pm = std(pm_ta, 0, 2);
str_gr = std(gr_ta, 0, 2);
str_fd = std(fd_ta, 0, 2);
str_sp = std(sp_ta, 0, 2);
end
%% F-PCA (without mask)
% plot the figure
fig = figure;
hold on
errorbar(mtr_sp, str_fd, '-^', 'LineWidth', 2);
errorbar(mtr_pm, str_pm, '-*', 'LineWidth', 2);
errorbar(mtr_fd, str_fd, '-x', 'LineWidth', 2);
errorbar(mtr_gr, str_gr, '-+', 'LineWidth', 2);
errorbar(mtr_fpca, str_fpca, '-o', 'LineWidth', 2);
hold off
% full legend cells
legendCells = {'SP', 'PM', 'FD', 'GROUSE', 'F-PCA'};
% assign labels
legend(legendCells, 'location', 'best');
xticks(1:1:size(d, 2));
xticklabels(num2cell(d));
xlabel("ambient dimension (d)");
if use_log_plot == 1
ylabel("average per trial time (log(sec))");
else
ylabel("average per trial time (sec)");
end
cap = sprintf("Time to compute U for r=%d", r);
title(cap);
% print figure, if needed
t = sprintf("speedtest_T_%sk_kr_%d_alpha_%d_trials_%d", ...
strrep(num2str(T/1000), ".", "_"), r, synth_params.alpha, trials);
print_fig(fig, t, params);
%% Differentially Private F-PCA (with mask) included
% plot the figure
fig = figure;
hold on
errorbar(mtr_sp, str_sp, '-^', 'LineWidth', 2);
errorbar(mtr_pm, str_pm, '-*', 'LineWidth', 2);
errorbar(mtr_fd, str_fd, '-x', 'LineWidth', 2);
errorbar(mtr_gr, str_gr, '-+', 'LineWidth', 2);
errorbar(mtr_fpca, str_fpca, '-o', 'LineWidth', 2);
errorbar(mtr_mask_fpca, str_mask_fpca, '--', 'LineWidth', 2);
hold off
% full legend cells
legendCells = {'SP', 'PM', 'FD', 'GROUSE', 'F-PCA', 'F-PCA_{mask}'};
% assign labels
legend(legendCells, 'location', 'best');
xticks(1:1:size(d, 2));
xticklabels(num2cell(d));
xlabel("ambient dimension (d)");
if use_log_plot == 1
ylabel("average per trial time (log(sec))");
else
ylabel("average per trial time (sec)");
end
cap = sprintf("Time to compute U for r=%d", r);
title(cap);
% print figure, if needed
t = sprintf("speedtest_mask_T_%sk_kr_%d_alpha_%d_trials_%d", ...
strrep(num2str(T/1000), ".", "_"), r, synth_params.alpha, trials);
print_fig(fig, t, params);