-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathvbmc_plot.m
75 lines (56 loc) · 1.97 KB
/
vbmc_plot.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
function vbmc_plot(vp_array,stats)
if nargin < 2; stats = []; end
Nsamples = 1e5;
if ~iscell(vp_array)
temp{1} = vp_array;
vp_array = temp;
end
if numel(vp_array) == 1 && vbmc_isavp(vp_array{1})
X = vbmc_rnd(vp_array{1},Nsamples);
for d = 1:size(X,2); names{d} = ['x_{' num2str(d) '}']; end
cornerplot(X,names);
else
Nbins = 40;
Nvps = numel(vp_array);
D = vp_array{1}.D;
mm = zeros(Nvps,D);
cmap = colormap;
cmap = cmap(mod((1:27:(1+27*64))-1,64)+1,:);
plotmat = [1 1; 1 2; 1 3; 2 2; 2 3; 2 3; 2 4; 2 4; 3 3; 3 4; 3 4; 3 4; 3 5; 3 5; 3 5; 4 4; 4 5; 4 5; 4 5];
nrows = plotmat(D,1);
ncols = plotmat(D,2);
for i = 1:Nvps
if ~isempty(stats) && stats.idx_best == i; best_flag = true; else; best_flag = false; end
ltext{i} = ['vp #' num2str(i)];
if best_flag; ltext{i} = [ltext{i} ' (best)']; end
X = vbmc_rnd(vp_array{i},Nsamples);
mm(i,:) = median(X);
for d = 1:D
subplot(nrows,ncols,d);
if best_flag; lw = 3; else; lw = 1; end
hst(i)=histogram(X(:,d),Nbins,'Normalization','probability','Displaystyle','stairs','LineWidth',lw,'EdgeColor',cmap(i,:));
hold on;
end
end
for i = 1:Nvps
if ~isempty(stats) && stats.idx_best == i; best_flag = true; else; best_flag = false; end
for d = 1:D
subplot(nrows,ncols,d);
if best_flag; lw = 3; else; lw = 1; end
hln(i)=plot(mm(i,d)*[1 1],ylim,'-','LineWidth',lw,'Color',cmap(i,:));
hold on;
end
end
for d = 1:D
subplot(nrows,ncols,d);
xlabel(['x_{' num2str(d) '}']);
set(gca,'TickDir','out');
box off;
if d == D
hleg = legend(hln,ltext{:});
set(hleg,'box','off','location','best');
end
end
set(gcf,'Color','w');
end
end