-
Notifications
You must be signed in to change notification settings - Fork 5
/
viserrs.m
156 lines (154 loc) · 5.23 KB
/
viserrs.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
% Plot the errors (as computed by 'errmsr') of different methods.
%
% inputs
% mm: the row vector of "# of partitions".
%
% ni: indices of the multiple runs to show, a subset of 1:nrun.
%
% mi: indices of the multiple partition schemes to show, a subset of
% 1:numel(mm).
%
% errs: a cell array, each entry of which is the 'errs' (a nrun*numel(mm)
% cell array in itself) returned by the corresponding method.
%
% labels: a cell array of string labels for each method.
%
% logscale (optional): boolean, whether to use log scale or linear scale
% (default) for the y-axis.
%
% xfdname (optional): decides the meaning of the x-axis, 'nssamples' or
% npsamples'.
% 'nssamples' means the total # of samples drawn so far overall;
% 'npsamples' means the total # of samples drawn so far locally on each
% node.
%
% mkr (optional): a cell array of marker types to use.
%
% figdir (optional): when available, where the generated figures will be
% saved.
%
% fdnames (optional): a cell array of the subset of 'errs' to plot.
%
% examples:
% load('data.mat', 'nrun', 'mm');
% SMSs = load('dpep_sync.mat', 'errs');
% SMSa = load('dpep_async.mat', 'errs');
% XINGp = load('xing_p.mat', 'errs');
% XINGn = load('xing_n.mat', 'errs');
% WEIS = load('weis.mat', 'errs');
%
% viserrs(mm, 1, 1:numel(mm), {SMSs.errs, SMSa.errs}, {'SMS(s)', 'SMS(a)'}, 'nssamples');
% viserrs(mm, 1:nrun, 1, {SMSs.errs, XINGp.errs, XINGn.errs, WEIS.errs}, {'SMS(s)', 'XING(p)', 'XING(n)', 'WEIS'});
%
% Minjie Xu ([email protected])
function viserrs(mm, ni, mi, errs, labels, logscale, xfdname, mkr, figdir, fdnames, N)
dpsi = find(cellfun(@(c)~isempty(c), strfind(labels, 'SMS(s')), 1);
dpai = find(cellfun(@(c)~isempty(c), strfind(labels, 'SMS(a')), 1);
if ~exist('logscale', 'var') || isempty(logscale) || ~logscale
hplot = @plot;
else
hplot = @semilogy;
end
if ~exist('xfdname', 'var') || isempty(xfdname)
if ~isempty(dpai)
xfdname = 'nssamples';
else
xfdname = 'npsamples';
end
end
if ~exist('mkr', 'var') || isempty(mkr)
mkr = {'x','o','s','d','^','v','p','h','x'};
end
if ~exist('fdnames', 'var') || isempty(fdnames)
fdnames = fieldnames(errs{1}{1});
end
H = figure;
cc = lines(7);
for i = 1:numel(fdnames)
yfdname = fdnames{i};
if any(strcmp(yfdname, {'npsamples', 'nssamples'}))
continue;
end
clf(H, 'reset');
legl = zeros(1,numel(errs));
legm = zeros(1,numel(mi));
for j = 1:numel(errs)
cerr = errs{j};
if ~isfield(cerr{1}, yfdname)
continue;
end
for k = 1:numel(mi)
for l = ni
if isempty(cerr{l,mi(k)})
continue;
end
nsamples = cumsum([cerr{l,mi(k)}.(xfdname)]);
yvals = [cerr{l,mi(k)}.(yfdname)];
xvals = nsamples;
if exist('N', 'var')
xvals = nsamples*round(N/mi(k));
end
if legl(j) == 0
if numel(mi)==1
legl(j) = hplot(xvals(1), yvals(1), ...
['--',mkr{mod(j-1,numel(mkr))+1}], 'color', cc(mod(j-1,size(cc,1))+1,:), ...
'MarkerSize', 10, 'LineWidth', 2);
else
legl(j) = hplot(xvals(1), yvals(1), ...
mkr{mod(j-1,numel(mkr))+1}, 'MarkerSize', 10);
end
hold on;
end
if legm(k) == 0
legm(k) = hplot(xvals(1), yvals(1), ...
'--', 'color', cc(mod(k-1,size(cc,1))+1,:), 'LineWidth', 2);
hold on;
end
if numel(mi)==1
hplot(xvals, yvals, ...
['--',mkr{mod(j-1,numel(mkr))+1}], 'color', cc(mod(j-1,size(cc,1))+1,:), ...
'MarkerSize', 10, 'LineWidth', 2);
else
hplot(xvals, yvals, ...
['--',mkr{mod(j-1,numel(mkr))+1}], 'color', cc(mod(k-1,size(cc,1))+1,:), ...
'MarkerSize', 10, 'LineWidth', 2);
end
hold on;
end
end
end
if numel(mi) == 1
legend(nonzeros(legl), labels(legl~=0));
title(num2str(mm(mi), 'm = %d'));
nsamples = [];
if ~isempty(dpsi)
nsamples = cumsum([errs{dpsi}{ni(1),mi}.(xfdname)]);
elseif ~isempty(dpai)
if strcmp(xfdname, 'nssamples')
terr = errs{dpai}{ni(1),mi};
T = terr(1).npsamples;
nsamples = T*mm(mi):T*mm(mi):sum([terr.nssamples]);
else
nsamples = [];
end
end
if ~isempty(nsamples)
set(gca, 'XTick', nsamples);
ylims = get(gca, 'YLim');
for ns = nsamples
hplot([ns,ns], ylims, 'k:');
end
xlim([0,nsamples(end)]);
end
else
legend([legl,legm], [labels,cellstr(num2str(mm(mi)', 'm = %d'))']);
end
ylabel(yfdname, 'Interpreter', 'none');
% figfont;
pause;
if exist('figdir', 'var')
savecurfig(figdir, yfdname);
end
end
close(H);
end