-
Notifications
You must be signed in to change notification settings - Fork 0
/
inferenceStat.m
65 lines (54 loc) · 1.33 KB
/
inferenceStat.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
function stop = inferenceStat(x,iterationType,i,funEvals,f,t,gtd,g,d,optCond,varargin)
% plot function for inference optimization callback
persistent obj;
persistent prevX;
persistent changeX;
persistent diff;
if i == 0
obj = [];
prevX = 0;
changeX = [];
diff = [];
end
obj(end+1) = f;
changeX(end+1) = norm(x - prevX);
prevX = x;
interval = inf;
window = 500;
if mod(i-1, interval) == 0
subplot(411);
if any(obj <= 0)
plot(obj);
else
semilogy(obj);
end
ylabel('objective');
xlabel('iteration');
set(gca, 'FontSize', 16);
subplot(412);
inds = max(1, length(obj) - window):length(obj);
plot(inds, obj(inds));
ylabel('objective');
xlabel(sprintf('last %d iterations', window));
title(sprintf('norm of gradient: %d', norm(g)));
set(gca, 'FontSize', 16);
subplot(413);
semilogy(changeX);
ylabel('Change in x');
xlabel('Iteration');
title(sprintf('Optimality condition %d', optCond));
subplot(414);
cla
if ~isempty(varargin)
func = varargin{1};
diff(end+1) = abs(fastDerivativeCheck(func, x)) / norm(g);
end
plot(diff);
title('Difference between numerical versus user-supplied derivative');
% if diff(end) > 1e10
% keyboard;
% end
%
drawnow;
end
stop = false;