rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
step7_error_landscape.m
Go to the documentation of this file.
1 % script generating error landscapes by computing the true error of reduced
2 % simulations vs. detailed simulations for given test parameters over differing
3 % basis sizes.
4 %
5 % The generated cell array 'output' can later be visualized with
7 %
8 % required variables that need to be set:
9 % - 'basis_gen'
10 % - 'detailed_data'
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
15 % plots. See also couple_N_and_M_by_c() for more
16 % information.
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
20 % structure is saved.
21 %
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
26 % set
27 % -# 'train_set_coupled' -- error plot over c where c is the parameter
28 % of couple_N_and_M_by_c() for training parameter set
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.
48 % .
49 % By default all error landscapes are selected.
50 
51 
52 if ~exist('error_plots','var')
53  error_plots = {};
54 end
55 
56 disp('warning: takes a few hours!');
57 
58 if basis_gen.verbose < 20 && ~basis_gen.debug
59  warning('off','MATLAB:nearlySingularMatrix');
60 end
61 
62 sample_size = [Nsize, Msize];
63 
64 % produce reduced data
65 reduced_data = gen_reduced_data(basis_gen,detailed_data);
66 i=0;
67 sconf = struct('pf',[],'max',[],'sample_size',[],'mode',[],'testdir',[],...
68  'run_name_infix',[],'pf_descr',[],'testdir_infix',[]);
69 
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);
73 %end
74 
75 Nmax = get_rb_size(detailed_data);
76 Mmax = get_ei_size(detailed_data);
77 
78 info = find_active_info(detailed_data);
79 
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
83  i=i+1;
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_';
90 end
91 
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
94  % (N,M)=c*(Nmax,Mmax)
95  i=i+1;
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_';
102 end
103 
104 if isempty(error_plots) || ismember('error', error_plots)
105  % error landscape over N and M for a new test set of mu vectors.
106  i=i+1;
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 = '';
114 end
115 
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)
119  i=i+1;
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_';
127 end
128 
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
132  % mu vectors.
133  i=i+1;
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 = '';
141 end
142 
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)
147  i=i+1;
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_';
155 end
156 
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
161  % vectors.
162  i=i+1;
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 = '';
170 end
171 
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)
177  i=i+1;
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_';
185 end
186 
187 output = cell(size(sconf));
188 
189 if exist('M_by_N_ratio', 'var')
190  params.M_by_N_ratio = M_by_N_ratio;
191 end
192 
193 % produce error landscapes for all sconf configurations above
194 %parfor i = 1:length(sconf)
195 for i = 1:length(sconf)
196  tmp_params = params;
197  range_params = [];
198  range_params.plot_fields = sconf(i).pf;
199  if isempty(sconf(i).max)
200  range_params.samples = sconf(i).samples;
201  else
202  range_params.max = sconf(i).max;
203  range_params.sample_size = sconf(i).sample_size;
204  end
205  if ~isempty(sconf(i).pf_descr)
206  range_params.plot_field_descr = sconf(i).pf_descr;
207  end
208  if ~isempty(sconf(i).mu_set_size)
209  range_params.mu_set_size = sconf(i).mu_set_size;
210  end
211  if ~isempty(sconf(i).mu_set)
212  range_params.mu_set = sconf(i).mu_set;
213  end
214 % if ~isempty(sconf(i).testdir)
215 % testdir = sconf(i).testdir;
216 % else
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';
223 
224  output{i}=stochastic_error_estimation(basis_gen, detailed_data, ...
225  reduced_data, ...
226  range_params, tmp_params);
227 end
228 
229 %basis_gen.Mstrich = oldMstrich;
230 %clear('old_model');
231 
232 save(params.step7_outputfile, 'output');
233 
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()