-
Notifications
You must be signed in to change notification settings - Fork 0
/
iter_figures.m
247 lines (211 loc) · 8.33 KB
/
iter_figures.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
%% Set path string and add paths
clc; clear all; close all;
direc = pwd; if direc(1)=='C'
dpath = 'C:\Users\carle\Documents\MATLAB\NSF DEMS\Phase 1\';
else
dpath = 'E:\Carl\Documents\MATLAB\NSF-DEMS_calibration\';
end
clear direc;
% Add paths
addpath(dpath);
addpath([dpath,'stored_data']);
addpath([dpath,'Example']);
addpath([dpath,'Example\Ex_results']);
%% Heatmaps for posteriors in 3-part iter. calib. on toy sim. example
clc ; clearvars -except dpath ; close all ;
% Load results
load([dpath,'Example\Ex_results\'...
'2018-09-12_iterative_calibration'],...
'all_results');
des_obs = all_results{1}.settings.desired_obs;
h1 = calib_heatmap(des_obs, all_results{1}.samples_os);
pos = h1.Position; h1.Position = pos + [ 0 0 -1/4 * pos(3) 0 ]
pos = h1.Children(4).Position; dist = pos(4); sc=1/7;
set(h1.Children(4),'Position', pos + [-dist*sc -dist*sc dist*sc dist*sc]);
title('Calibration iteration 1/3, \lambda_\delta = 1/256');
xlabel('\theta_1');ylabel('\theta_2');
h2 = calib_heatmap(des_obs, all_results{2}.samples_os);
pos = h2.Position; h2.Position = pos + [ 0 0 -1/4 * pos(3) 0 ]
pos = h2.Children(4).Position; dist = pos(4); sc=1/7;
set(h2.Children(4),'Position', pos + [-dist*sc -dist*sc dist*sc dist*sc]);
title('Calibration iteration 2/3, \lambda_\delta = 16.7');
xlabel('\theta_1');ylabel('\theta_2');
h3 = calib_heatmap(des_obs, all_results{3}.samples_os);
pos = h3.Position; h3.Position = pos + [ 0 0 -1/4 * pos(3) 0 ]
pos = h3.Children(4).Position; dist = pos(4); sc=1/7;
set(h3.Children(4),'Position', pos + [-dist*sc -dist*sc dist*sc dist*sc]);
title('Calibration iteration 3/3, \lambda_\delta = 1784.5');
xlabel('\theta_1');ylabel('\theta_2');
% Save them
set(h1,'Color','white');
set(h2,'Color','white');
set(h3,'Color','white');
% export_fig('FIG_iter_calib_1o3','-png','-m3','-painters',h1);
% export_fig('FIG_iter_calib_2o3','-png','-m3','-painters',h2);
% export_fig('FIG_iter_calib_3o3','-png','-m3','-painters',h3);
%% Get marginal posteriors from toy sim. example at all three levels
clc ; clearvars -except dpath ; close all ;
% Load results
load([dpath,'Example\Ex_results\'...
'2018-09-12_iterative_calibration'],...
'all_results');
samps1 =all_results{1}.samples_os(all_results{1}.settings.burn_in+2:end,:);
samps2 =all_results{2}.samples_os(all_results{2}.settings.burn_in+2:end,:);
samps3 =all_results{3}.samples_os(all_results{3}.settings.burn_in+2:end,:);
samps=cell(3,1); samps{1}=samps1; samps{2}=samps2; samps{3}=samps3;
% Make figures
h1 = figure('rend','painters','pos',[10 10 610 190]) ;
h2 = figure('rend','painters','pos',[10 10 610 190]) ;
h3 = figure('rend','painters','pos',[10 10 610 190]) ;
h=cell(3,1); h{1}=h1; h{2}=h2; h{3}=h3;
% Load true optimum
load([dpath,'Example\Ex_results\'...
'2018-09-11_true_optimum_wrt_0']);
for ii = 1 : 3
%%% Get the marginal plots
%h1 = figure('rend','painters','pos',[10 10 610 160]) ;
set (groot, 'currentfigure', h{ii});
subplot(1,2,1);
histogram(samps{ii}(:,1), 'Normalization','pdf') ;
xlim([0 3]);
unifval = 1/3;
hold on;
%xlabel('\theta_1');
ylims=[0 3.3];%ylim;
plot([0 3], [unifval unifval],'--r','LineWidth',1);
plot([optim(1) optim(1)], [ylims],':g','LineWidth',1.5);
ylim(ylims);
% set(gca, 'XTick', sort([optim(1), get(gca, 'XTick')]));
subplot(1,2,2);
histogram(samps{ii}(:,2), 'Normalization','pdf') ;
xlim([0 6]);
unifval = 1/6;
hold on;
%xlabel('\theta_2');
ylims=[0 12];%ylim;
plot([0 6], [unifval unifval],'--r','LineWidth',1);
plot([optim(2) optim(2)], [ylims],':g','LineWidth',1.5);
ylim(ylims);
% %%% Save
set(h{ii},'Color','white');
figstr = sprintf('FIG_iter_post_marginals_%go3',ii);
export_fig(figstr,'-png','-m3','-painters',h{ii});
end
%% Marginal posteriors from wind turbine appl. at all three levels
clc ; clearvars -except dpath ; close all ;
load([dpath,'stored_data\'...
'2018-09-12_iterative_calibration'],...
'all_results');
samps1 =all_results{1}.samples_os(all_results{1}.settings.burn_in+2:end,:);
samps2 =all_results{2}.samples_os(all_results{2}.settings.burn_in+2:end,:);
samps3 =all_results{3}.samples_os(all_results{3}.settings.burn_in+2:end,:);
samps=cell(3,1); samps{1}=samps1; samps{2}=samps2; samps{3}=samps3;
% Make figures
h1 = figure('rend','painters','pos',[10 10 610 190]) ;
h2 = figure('rend','painters','pos',[10 10 610 190]) ;
h3 = figure('rend','painters','pos',[10 10 610 190]) ;
h=cell(3,1); h{1}=h1; h{2}=h2; h{3}=h3;
for ii = 1 : 3
%%% Get the marginal plots
%h1 = figure('rend','painters','pos',[10 10 610 160]) ;
set (groot, 'currentfigure', h{ii});
subplot(1,2,1);
histogram(samps{ii}(:,1), 'Normalization','pdf') ;
xlim([0.2 0.6]);
unifval = 1/.4;
hold on;
%xlabel('Volume fraction');
ylims=[0 44];%ylim;
plot([0.2 0.6], [unifval unifval],'--r','LineWidth',2);
ylim(ylims);
% set(gca, 'XTick', sort([optim(1), get(gca, 'XTick')]));
subplot(1,2,2);
histogram(samps{ii}(:,2), 'Normalization','pdf') ;
xlim([10 25]);
unifval = 1/15;
hold on;
%xlabel('Thickness (mm)');
ylims=[0 1.16];%ylim;
plot([10 25], [unifval unifval],'--r','LineWidth',2);
ylim(ylims);
%%% Save
set(h{ii},'Color','white');
figstr = sprintf('FIG_wta_iter_post_marginals_%go3',ii);
export_fig(figstr,'-png','-m3','-painters',h{ii});
end
%% Marginal posterior predictive dists from all levels of WTA
clc ; clearvars -except dpath ; close all ;
clc ; clearvars -except dpath ; close all ;
%%% Load prior predictive results and all levels of calib
load([dpath,'stored_data\'...
'2018-09-03_prior_pred_distrib'],...
'prior_pred_dist');
prsamps = prior_pred_dist.prior_pred_pts;
clear prior_pred_dist;
load([dpath,'stored_data\'...
'2018-09-12_iterative_calibration'],...
'all_results');
posamps = cell(3,1);
posamps{1} = all_results{1}.model_output.by_sample_est(...
all_results{1}.settings.burn_in+2:end,:) ;
posamps{2} = all_results{2}.model_output.by_sample_est(...
all_results{2}.settings.burn_in+2:end,:) ;
posamps{3} = all_results{3}.model_output.by_sample_est(...
all_results{3}.settings.burn_in+2:end,:) ;
des_obs = all_results{1}.settings.desired_obs;
des_obs_upd = all_results{3}.settings.desired_obs;
clear all_results;
f=cell(3,1);
%%% Loop through levels, creating a figure for each
for ii = 1:3
f{ii}=figure('pos',[10 10 720.0000 180]);
% Deflection
subplot(1,3,1);
histogram(posamps{ii}(:,1),'Normalization','pdf','Edgecolor','none');
hold on;
histogram(prsamps(:,1),'Normalization','pdf','Edgecolor','none');
text(0.485,.875,...
'Deflection','VerticalAlignment','bottom','Units','normalized');
% text(1.715,102,'Rotation','VerticalAlignment','bottom');
% title('Deflection');
xlim([0.6 0.85]);
ylim([0 225]);
line([des_obs(1) des_obs(1)],ylim,'Color','black','Linestyle',':',...
'linewidth',1);
line([des_obs_upd(1) des_obs_upd(1)],ylim,...
'Color','red','Linestyle','--','linewidth',1);
% Rotation
subplot(1,3,2);
histogram(posamps{ii}(:,2),'Normalization','pdf','Edgecolor','none');
hold on;
histogram(prsamps(:,2),'Normalization','pdf','Edgecolor','none');
text(0.55,.875,...
'Rotation','VerticalAlignment','bottom','Units','normalized');
% title('Rotation');
xlim([0.075,0.105])
ylim([0 1625]);
line([des_obs(2) des_obs(2)],ylim,'Color','black','Linestyle',':',...
'linewidth',1);
line([des_obs_upd(2) des_obs_upd(2)],ylim,...
'Color','red','Linestyle','--','linewidth',1);
% Cost
subplot(1,3,3);
histogram(posamps{ii}(:,3),'Normalization','pdf','Edgecolor','none');
hold on;
histogram(prsamps(:,3),'Normalization','pdf','Edgecolor','none');
text(0.72,.875,...
'Cost','VerticalAlignment','bottom','Units','normalized');
% title('Cost');
ylim([0 .1100]);
line([des_obs(3) des_obs(3)],ylim,'Color','black','Linestyle',':',...
'linewidth',1);
line([des_obs_upd(3) des_obs_upd(3)],ylim,...
'Color','red','Linestyle','--','linewidth',1);
% Add suptitle
%st=suptitle('Prior (red) and posterior (blue) predictive distributions');
%st.Position=[0.5 -.1 0];
%%% Save
set(f{ii}, 'Color','white');
figstr = sprintf('FIG_iter_prior_vs_posterior_dist_%go3',ii);
export_fig(figstr,'-png', '-m3', '-painters');
end