forked from MBB-team/VBA-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VBA_displayGrads.m
61 lines (56 loc) · 1.74 KB
/
VBA_displayGrads.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
function [hf] = VBA_displayGrads(J,J2,flag,fname,flagFun)
% eyeball the difference between two arbitrary matrices
try; flag; catch; flag = ''; end
try; fname; catch; fname = []; end
try; flagFun; catch; flagFun = ''; end
try; sfn = func2str(fname); catch; sfn = fname; end
switch flagFun
case 'f'
str = [' (evolution function: ',sfn,')'];
case 'g'
str = [' (observation function: ',sfn,')'];
case 'fg'
str = [' (N-lagged observation function: ',sfn,')'];
otherwise
str = [];
end
switch flag
case 'Jacobian'
hf0 = findobj('tag','checkGrads');
set(hf0,'tag',' ');
hf(1) = figure('name',[flag,str],'tag','checkGrads');
case 'Gradients wrt parameters'
hf(1) = figure('name',[flag,str]);
hf1 = findobj('tag','checkGrads');
if ~isempty(hf1)
pos = get(hf1,'position');
pos = [pos(1)-0.5*pos(3) pos(2) pos(3) pos(4)];
set(hf1,'position',pos);
pos2 = get(hf(1),'position');
set(hf(1),'position',[1.02*sum(pos([1,3])), pos2(2:4)])
end
otherwise
hf(1) = figure('name',[flag,str]);
end
if isempty(J)
ha = axes('parent',hf);
imagesc(J2,'parent',ha),colorbar
xlabel(ha,'numerical')
else
ha = subplot(2,2,1,'parent',hf(1));
plot(ha,J(:),J2(:),'b.')
grid(ha,'on')
axis(ha,'tight')
xlabel(ha,'analytic')
ylabel(ha,'numerical')
ha = subplot(2,2,2,'parent',hf(1));
imagesc(J-J2,'parent',ha),colorbar
xlabel(ha,'analytic-numerical')
ha = subplot(2,2,3,'parent',hf(1));
imagesc(J,'parent',ha),colorbar
xlabel(ha,'analytic')
ha = subplot(2,2,4,'parent',hf(1));
imagesc(J2,'parent',ha),colorbar
xlabel(ha,'numerical')
end
try; getsubplots; end