-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdataplot3params.m
225 lines (220 loc) · 7.01 KB
/
dataplot3params.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
%% Performance Metrics Varying with Parameters
% mode = 'vareta'|'varweight'|'varnumber'
%% For HSR/HSR-RSV/Baseline (Default)
%{
lines.Sources = {'Dimconfig','DimconfigReserve', 'DimBaseline'}; % 'Fastconfig','FastconfigReserve',
lines.Lables = {'HSR', 'HSR-RSV', 'Baseline'};
metrics.Names = {'ReconfigRatio'}; % 'FairIndex', 'Utilization', 'Profit'
metrics.Labels = {'Reconfigure Ratio'}; % 'Fairness Index', 'Utilization Ratio', 'Profit';
options.Suffix = '';
%}
%% For FSR/Baseline
% Modify following Arguments
%{
lines.Sources = {'Fastconfig', 'DimBaseline'}; % 'Fastconfig','FastconfigReserve',
lines.Labels = {'FSR', 'Baseline'};
options.Suffix = 'fast'; % 'fastcomp' for no normalized version.
%}
function dataplot3params(mode, lines, metrics, idx_offset, options)
global figs;
if ~exist('figs', 'var') || isempty(figs) || ~isstruct(figs)
figs = struct;
end
%%
if nargin <= 0 || isempty(mode)
mode = 'vareta';
end
if nargin <= 1 || isempty(lines)
lines = struct;
end
if ~isfield(lines, 'Sources')
lines.Sources = {'Dimconfig','DimconfigReserve', 'DimBaseline'};
end
if ~isfield(lines, 'Labels')
lines.Labels = {'HSR', 'HSR-RSV', 'Baseline'};
end
if ~isfield(lines, 'Markers')
lines.Markers = {'x', 'o', 's'};
end
if ~isfield(lines, 'Styles')
lines.Styles = {'-', '--', '-.'};
end
if ~isfield(lines, 'Colors')
lines.Colors = [Color.MildBlue; Color.Red; Color.MildGreen];
end
if nargin <= 2 || isempty(metrics)
metrics = struct;
end
if ~isfield(metrics, 'Names')
metrics.Names = {'ReconfigRatio'};
end
if ~isfield(metrics, 'Labels')
metrics.Labels = {'Reconfigure Ratio'};
end
if nargin <= 3 || isempty(idx_offset)
idx_offset = 1;
end
if nargin <= 4
options = struct;
end
if ~isfield(options, 'Suffix')
options.Suffix = '';
end
options.bNormalizeRatio = true;
if strcmpi(options.Suffix, '-fastcomp')
options.bNormalizeRatio = false;
end
if ~isfield(options, 'bSavePlot')
options.bSavePlot = false;
end
%%
switch mode
case {'vareta', 'var-eta'}
if length(lines.Sources) == 2
load('Results/EXP5024_vareta_fast.mat', 'results', 'etas');
else
load('Results/EXP5024_vareta.mat', 'results', 'etas');
end
mode = 'vareta';
vars = etas;
x_label = '\eta';
case {'varweight', 'var-weight'}
if length(lines.Sources) == 2
load('Results/EXP5024_varweight_fast.mat', 'results', 'weight');
else
load('Results/EXP5024_varweight.mat', 'results', 'weight');
end
mode = 'varweight';
vars = weight;
x_label = 'flow weight';
case {'varnumber', 'var-number'}
if length(lines.Sources) == 2
load('Results/EXP5024_varnumber_fast.mat', 'results', 'numberflow');
else
load('Results/singles/EXP4_OUTPUT241s0100.mat', 'results', 'numberflow');
% load('Results/EXP5024_varnumber.mat', 'results', 'numberflow');
end
mode = 'varnumber';
vars = numberflow;
x_label = 'number of flows';
end
% load(['Results/5024_', mode, '.mat'], 'results'); % TODO, update the file name.
for k = 1:length(metrics.Names)
metric = metrics.Names{k};
if isfield(figs, metric) && figs.(metric).isvalid
figs.(metric).Children.delete;
figure(figs.(metric));
else
figs.(metric) = figure('Name', metric);
figs.(metric).OuterPosition = [100+10*k 500-10*k 350 350];
end
for j = 1:length(lines.Sources)
name = lines.Sources{j};
if (strcmpi(name, 'Baseline') || strcmpi(name, 'dimbaseline')) ...
&& strcmpi(metric, 'ReconfigRatio') ...
&& options.bNormalizeRatio
continue;
end
if (strcmpi(name, 'Baseline') || strcmpi(name, 'dimbaseline')) ...
&& strcmpi(mode, 'vareta')
if strcmpi(metric, 'reconfigratio')
mean_value = mean(results.(name){1}{idx,'ReVariables'}./...
results.(name){1}{idx,'NumVariables'})*ones(length(vars),1);
else
mean_value = mean(results.(name){1}{idx,metric})*ones(length(vars),1);
end
else
mean_value = zeros(length(results.(name)),1);
for i = 1:length(results.(name))
idx = (idx_offset+1):height(results.(name){i});
if strcmpi(metric, 'reconfigratio')
if options.bNormalizeRatio
%% Normalize the reconfiguration ratio based on the Baseline
mean_value(i) = mean(results.(name){i}{idx,'ReVariables'}./...
results.(name){i}{idx,'NumVariables'})/...
mean(results.DimBaseline{1}{idx,'ReVariables'}./...
results.DimBaseline{1}{idx,'NumVariables'});
else
%% Not Normalize
mean_value(i) = mean(results.(name){i}{idx,'ReVariables'}./...
results.(name){i}{idx,'NumVariables'});
end
else
mean_value(i) = mean(results.(name){i}{idx,metric});
end
end
end
if strcmpi(mode, 'vareta')
semilogx(vars, mean_value, lines.Styles{length(lines.Sources)-j+1});
else
plot(vars, mean_value, lines.Styles{length(lines.Sources)-j+1});
end
hold on;
end
h = figs.(metric).Children(end).Children;
for j=1:length(h)
h(j).Color = lines.Colors(length(h)-j+1).RGB;
h(j).Marker = lines.Markers{length(h)-j+1};
h(j).LineWidth = 1;
end
ax = h(1).Parent;
if strcmpi(metric, 'Utilization')
ax.YLim(2) = 1.1;
end
if strcmpi(mode, 'vareta')
ax.XLim = [vars(1) vars(end)];
ax.XTick = vars;
% h(1).Parent.XTickLabel = split(num2str(vars));
ax.TickLabelInterpreter = 'latex';
ax.XTickLabel = {'$^1\!/\!_{32}$', '$^1\!/\!_{16}$', '$^1\!/\!_{8}$', ...
'$^1\!/\!_{4}$', '$^1\!/\!_{2}$', '1', '2', '4', '8'};
else
xlim([vars(1), vars(end)])
end
switch mode
case 'vareta'
ax.OuterPosition = [0 0.01 1.08 1.04];
case 'varweight'
ax.OuterPosition = [0 0.01 1.05 1.04];
case 'varnumber'
ax.OuterPosition = [0 0.01 1.08 1.04];
end
if strcmpi(metric, 'ReconfigRatio')
if ~options.bNormalizeRatio
legend(lines.Labels, 'Location', 'best');
elseif strcmpi(mode, 'varweight')
legend(lines.Labels, 'Location', 'northwest');
else
legend(lines.Labels, 'Location', 'northeast');
end
else
legend(lines.Labels, 'Location', 'best');
end
if strcmpi(metric, 'Profit')
if strcmpi(mode, 'varweight')
ax.OuterPosition = [0 0.01 1.05 1.00];
end
end
xlabel(x_label);
ylabel(metrics.Labels{k});
hold off;
if strcmpi(metric, 'ReconfigRatio')
switch mode
case {'vareta','var-eta'}
filename = 'Figures/reconfig-ratio-vareta';
case {'var-number','varnumber'}
filename = 'Figures/reconfig-ratio-varnum';
case {'var-weight', 'varweight'}
filename = 'figures/reconfig-ratio-varweight';
end
filename = [filename, options.Suffix]; %#ok<AGROW>
if options.bSavePlot
export_fig(figs.ReconfigRatio, filename, '-pdf', '-transparent');
end
end
end
end
%%
% Average profit over time, derived from accumulate profit devided by time.
function mean_profit(profit, reconfig_cost) %#ok<INUSD,DEFNU>
end