1 % script generating error landscapes by computing the
true error of reduced
2 % simulations vs. detailed simulations
for given test parameters over differing
5 % The generated cell array
'output' can later be visualized with
8 % required variables that need to be set:
11 % -
'Nsize' : number of reduced basis sizes to be tested.
12 % -
'Msize' : number of colletaral reduced basis sizes to be tested.
13 % -
'csample' : vector of increasing values between 0 and 1 indicating a
14 % set of reduced basis sizes to be tested
for coupled
17 % - 'cdescr' : description text for coupled plots.
18 % - 'mu_set_size' : default size of test parameter set.
19 % - 'params.step7_outputfile' : file name where the generated output
22 % optional variables that can be set:
23 % - 'error_plots' : cell array of strings specifying which test cases shall
24 % be handled by the script. Possible choices are
25 % -
# 'train_set' -- error landscape over N and M for training parameter
27 % -#
'train_set_coupled' -- error plot over c where c is the parameter
29 % -
# 'error' -- error landscape over N and M
30 % -#
'error_coupled -- error plot over c where c is the parameter of
31 % couple_N_and_M_by_c()
32 % -# 'error_ei
' -- error landscape over N and M for error between
33 % reduced and detailed_simulation with empirically
34 % interpolated operators.
35 % -# 'error_ei_coupled
' -- error landscape over c where c is the
36 % parameter of couple_N_and_M_by_c() for error between
37 % reduced and detailed_simulation with empirically
38 % interpolated operators.
39 % -# 'error_ei_rb_proj
' -- error landscape over N and M for error between
40 % reduced and detailed_simulation with empirically
41 % interpolated operators with a subsequent projection on
42 % the reduced basis space in each time step.
43 % -# 'error_ei_rb_proj_coupled
' -- error landscape over c where c is the
44 % parameter of couple_N_and_M_by_c() for error between
45 % reduced and detailed_simulation with empirically
46 % interpolated operators with a subsequent projection on
47 % the reduced basis space in each time step.
49 % By default all error landscapes are selected.
52 if ~exist('error_plots
','var
')
56 disp('warning: takes a few hours!
');
58 if basis_gen.verbose < 20 && ~basis_gen.debug
59 warning('off
','MATLAB:nearlySingularMatrix
');
62 sample_size = [Nsize, Msize];
64 % produce reduced data
65 reduced_data = gen_reduced_data(basis_gen,detailed_data);
67 sconf = struct('pf
',[],'max
',[],'sample_size
',[],'mode
',[],'testdir
',[],...
68 'run_name_infix
',[],'pf_descr
',[],'testdir_infix
',[]);
70 %if isempty(error_plots) || ismember('train_set
', error_plots) ...
71 % || ismember('train_set_coupled
', error_plots)
72 % basis_gen.detailed_gen.prepare(basis_gen, detailed_data, detailed_data.info.M_train.sample);
75 Nmax = get_rb_size(detailed_data);
76 Mmax = get_ei_size(detailed_data);
78 info = find_active_info(detailed_data);
80 if isempty(error_plots) || ismember('train_set
', error_plots)
81 % sconf = struct('pf
',repmat({[]}, 6,1));
82 % error landscape over N and M for training set
84 sconf(i).pf = { 'N
', 'M
' };
85 sconf(i).max = [Nmax, Mmax];
86 sconf(i).sample_size = sample_size;
87 sconf(i).mode = 'error
';
88 sconf(i).mu_set = info.M_train.sample;
89 sconf(i).run_name_infix = 'train_set_
';
92 if isempty(error_plots) || ismember('train_set_coupled
', error_plots)
93 % error landscape over c for training set, where c couples N and M by
96 sconf(i).pf = { @couple_N_and_M_by_c };
97 sconf(i).samples = {csample};
98 sconf(i).pf_descr = {cdescr};
99 sconf(i).mode = 'error
';
100 sconf(i).mu_set = info.M_train.sample;
101 sconf(i).run_name_infix = 'train_set_coupled_
';
104 if isempty(error_plots) || ismember('error
', error_plots)
105 % error landscape over N and M for a new test set of mu vectors.
107 sconf(i).pf = { 'N
', 'M
' };
108 sconf(i).max = [Nmax, Mmax];
109 sconf(i).sample_size = sample_size;
110 sconf(i).mu_set_size = mu_set_size;
111 sconf(i).mode = 'error
';
112 % sconf(i).testdir_infix = num2str(sconf(i).mu_set_size);
113 sconf(i).run_name_infix = '';
116 if isempty(error_plots) || ismember('error_coupled
', error_plots)
117 % error landscape over c for a test set of mu vectors, where c couples N
118 % and M by (N,M)=c*(Nmax,Mmax)
120 sconf(i).pf = { @couple_N_and_M_by_c };
121 sconf(i).samples = {csample};
122 sconf(i).mu_set_size = mu_set_size;
123 sconf(i).pf_descr = {cdescr};
124 sconf(i).mode = 'error
';
125 % sconf(i).testdir_infix = num2str(sconf(i).mu_set_size);
126 sconf(i).run_name_infix = 'coupled_
';
129 if isempty(error_plots) || ismember('error_ei
', error_plots)
130 % error landscape for error between reduced and detailed simulation with
131 % empirically interpolated operators over N and M for a new test set of
134 sconf(i).pf = { 'N
', 'M
' };
135 sconf(i).max = [Nmax, Mmax];
136 sconf(i).sample_size = sample_size;
137 sconf(i).mu_set_size = mu_set_size;
138 sconf(i).mode = 'error_to_ei
';
139 % sconf(i).testdir_infix = ['ei_
', num2str(sconf(i).mu_set_size)];
140 sconf(i).run_name_infix = '';
143 if isempty(error_plots) || ismember('error_ei_coupled
', error_plots)
144 % error landscape for error between reduced and detailed simulation with
145 % empirically interpolated operators over c for a test set of mu vectors,
146 % where c couples N and M by (N,M)=c*(Nmax,Mmax)
148 sconf(i).pf = { @couple_N_and_M_by_c };
149 sconf(i).samples = {csample};
150 sconf(i).pf_descr = {cdescr};
151 sconf(i).mu_set_size = mu_set_size;
152 sconf(i).mode = 'error_to_ei
';
153 % sconf(i).testdir_infix = ['ei_
', num2str(sconf(i).mu_set_size)];
154 sconf(i).run_name_infix = 'coupled_
';
157 if isempty(error_plots) || ismember('error_ei_rb_proj
', error_plots)
158 % error landscape for error between reduced and detailed simulation with
159 % empirically interpolated operators and an additional projection on the
160 % RB space after each time step, over N and M for a new test set of mu
163 sconf(i).pf = { 'N
', 'M
' };
164 sconf(i).max = [Nmax, Mmax];
165 sconf(i).sample_size = sample_size;
166 sconf(i).mu_set_size = mu_set_size;
167 sconf(i).mode = 'error_to_ei_rb_proj
';
168 % sconf(i).testdir_infix = ['ei_rb_proj_
', num2str(sconf(i).mu_set_size)];
169 sconf(i).run_name_infix = '';
172 if isempty(error_plots) || ismember('error_ei_rb_proj_error_plots
', error_plots)
173 % error landscape for error between reduced and detailed simulation with
174 % empirically interpolated operators and an additional projection on the
175 % RB space after each time step, over c for a test set of mu vectors,
176 % where c couples N and M by (N,M)=c*(Nmax,Mmax)
178 sconf(i).pf = { @couple_N_and_M_by_c };
179 sconf(i).samples = {csample};
180 sconf(i).mu_set_size = mu_set_size;
181 sconf(i).pf_descr = {cdescr};
182 sconf(i).mode = 'error_to_ei_rb_proj
';
183 % sconf(i).testdir_infix = ['ei_rb_proj_
', num2str(sconf(i).mu_set_size)];
184 sconf(i).run_name_infix = 'coupled_
';
187 output = cell(size(sconf));
189 if exist('M_by_N_ratio
', 'var
')
190 params.M_by_N_ratio = M_by_N_ratio;
193 % produce error landscapes for all sconf configurations above
194 %parfor i = 1:length(sconf)
195 for i = 1:length(sconf)
198 range_params.plot_fields = sconf(i).pf;
199 if isempty(sconf(i).max)
200 range_params.samples = sconf(i).samples;
202 range_params.max = sconf(i).max;
203 range_params.sample_size = sconf(i).sample_size;
205 if ~isempty(sconf(i).pf_descr)
206 range_params.plot_field_descr = sconf(i).pf_descr;
208 if ~isempty(sconf(i).mu_set_size)
209 range_params.mu_set_size = sconf(i).mu_set_size;
211 if ~isempty(sconf(i).mu_set)
212 range_params.mu_set = sconf(i).mu_set;
214 % if ~isempty(sconf(i).testdir)
215 % testdir = sconf(i).testdir;
217 tmp_params.run_name = [basis_gen.model.name, '_
', ...
218 sconf(i).mode, '_
', ...
219 sconf(i).run_name_infix, 'step7
'];
220 disp(tmp_params.run_name);
221 tmp_params.mode = sconf(i).mode;
222 %tmp_params.mode = 'check
';
224 output{i}=stochastic_error_estimation(basis_gen, detailed_data, ...
226 range_params, tmp_params);
229 %basis_gen.Mstrich = oldMstrich;
232 save(params.step7_outputfile, 'output
');
function model = couple_N_and_M_by_c(model, c)
modifies the reduced basis size fields of model by a single variable.
function plot_error_landscape(output)
plots an output structure generated by stochastic_error_estimation()