-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotStats.m
71 lines (61 loc) · 1.54 KB
/
plotStats.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
function plotStats(stats,paras)
if ~isfield(paras,'expDir')
paras.expDir = './output/';
end
%
modelFigPath = fullfile(paras.expDir, 'net-train.pdf') ;
epoch = numel(stats.train);
testt = paras.teststep;
%%
switchFigure(1) ; clf ;
plots = setdiff(...
cat(2,...
fieldnames(stats.train)', ...
fieldnames(stats.val)'), {'num', 'time'}) ;
for p = plots
p = char(p) ;
values = zeros(0, epoch) ;
leg = {} ;
%
f = char('train');
tmp = [stats.(f).(p)];
ind_train = (1:epoch)';
values(end+1,ind_train) = tmp(1,:)';
leg{end+1} =f;
%
f = char('val');
tmp = [stats.(f).(p)];
ind_val = (testt:testt:epoch)';
values(end+1,ind_val) = tmp(1,:)';
leg{end+1} =f;
%
% for f = {'train', 'val'}
% f = char(f) ;
% if isfield(stats.(f), p)
% tmp = [stats.(f).(p)] ;
% values(end+1,:) = tmp(1,:)' ;
% leg{end+1} = f ;
% end
% end
subplot(1,numel(plots),find(strcmp(p,plots))) ;
%plot(1:epoch, values','o-') ;
hold on;
plot(ind_train, values(1,ind_train)','o-') ;
plot(ind_val, values(2,ind_val)','o-') ;
xlabel('epoch') ;
title(p) ;
legend(leg{:}) ;
grid on ;
end
drawnow ;
print(1, modelFigPath, '-dpdf') ;
% -------------------------------------------------------------------------
function switchFigure(n)
% -------------------------------------------------------------------------
if get(0,'CurrentFigure') ~= n
try
set(0,'CurrentFigure',n) ;
catch
figure(n) ;
end
end