rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
step8_estimator_landscape.m
Go to the documentation of this file.
1 % script generating landscapes plot data by computing the error estimator of
2 % reduced simulations for given test parameters over differing basis sizes.
3 %
4 % The generated cell array 'output' can later be visualized with
6 %
7 % required variables that need to be set:
8 % - 'basis_gen'
9 % - 'detailed_data'
10 % - 'Nsize' : number of reduced basis sizes to be tested.
11 % - 'Msize' : number of colletaral reduced basis sizes to be tested.
12 % - 'Mstrich_samples' : vector of values that are assigned to M\' for plots
13 % where M\' varies.
14 % - 'csample' : vector of increasing values between 0 and 1 indicating a
15 % set of reduced basis sizes to be tested for coupled
16 % plots. See also couple_N_and_M_by_c() for more
17 % information.
18 % - 'cdescr' : description text for coupled plots.
19 % - 'mu_set_size' : default size of test parameter set.
20 % - 'model.RB_detailed_train_savepath' : path to detailed simulations
21 % for train parameter set.
22 % - 'params.step8_outputfile' : file name where the generated output
23 % structure is saved.
24 %
25 % optional variables that can be set:
26 % - 'estimator_plots' : cell array of strings specifying which test cases
27 % shall be handled by the script. Possible choices are
28 % -# 'Mstrich_1_coupled' -- plot of error estimates over 'c', where 'c'
29 % couples 'N' and 'M' by couple_N_and_M_by_c() and
30 % 'Mstrich' is set to 1 .
31 % -# 'Mstrich_max_coupled' -- plot of error estimates over 'c', where 'c'
32 % couples 'N' and 'M' by couple_N_and_M_by_c() and
33 % 'Mstrich' is set to maximum value in
34 % 'Mstrich_samples'.
35 % -# 'Mstrich_1' -- landscape plot over 'N' and 'M' and 'Mstrich' is
36 % set to 1.
37 % -# 'Mstrich_max' -- landscape plot over 'N' and 'M' and 'Mstrich' is
38 % set to maximum value in array 'Mstrich_samples'.
39 % -# 'Mmax_train' -- landscape plot over 'N' and 'Mstrich' with 'M' set to
40 % maximum possible value for test parameter set used
41 % in reduced basis generation.
42 % -# 'coupled' -- landscape plot over 'c' and 'Mstrich' where 'c' couples
43 % 'N' and 'M' by couple_N_and_M_by_c().
44 % -# 'Mmax' -- landscape plot over 'N' and 'Mstrich' with 'M' set to
45 % maximum possible value.
46 % -# 'Nmax' -- landscape plot over 'M' and 'Mstrich' with 'N' set to
47 % maximum reduced basis size.
48 % .
49 %
50 % By default all estimator landscapes are selected.
51 
52 if ~exist('estimator_plots','var')
53  estimator_plots = {};
54 end
55 
56 Nmax = get_rb_size(detailed_data);
57 Mmax = get_ei_size(detailed_data);
58 
59 info = find_active_info(detailed_data);
60 
61 disp('warning: takes a few hours!');
62 
63 if basis_gen.verbose < 20 && ~basis_gen.debug
64  warning('off','MATLAB:nearlySingularMatrix');
65 end
66 
67 % reduced basis sizes to be tested (depends on Nsize)
68 Nsamples = 1+round((0:Nsize-1) .* (Nmax-1) ./ (Nsize-1));
69 % collateral reduced basis sizes to be tested (depends on Msize)
70 Msamples = 1+round((0:Msize-1) .* (Mmax-1-max(Mstrich_samples)) ./ (Msize-1));
71 
72 % produce reduced data
73 reduced_data = gen_reduced_data(basis_gen,detailed_data);
74 
75 i=0;
76 sconf = struct('pf',[],'samples',[],'pf_descr',[],'Mstrich',[],...
77  'M',[],'N',[],'run_name_infix',[],'mu_set',[],...
78  'max',[]);
79 if isempty(estimator_plots) || ismember('Mstrich_1_coupled', estimator_plots)
80  % plot of error estimates over 'c', where 'c' couples 'N' and 'M' by `(N,M) =
81  % c (Nmax, Mmax)` and 'Mstrich' is set to 1
82  i=i+1;
83  sconf(i).pf = { @couple_N_and_M_by_c };
84  sconf(i).samples = {csample};
85  sconf(i).pf_descr = {cdescr};
86  sconf(i).Mstrich = 1;
87  sconf(i).run_name_infix = 'coupled_Mstrich_1_';
88 end
89 
90 if isempty(estimator_plots) || ismember('Mstrich_max_coupled', estimator_plots)
91  % plot of error estimates over 'c', where 'c' couples 'N' and 'M' by `(N,M) =
92  % c (Nmax, Mmax)` and 'Mstrich' is set to its maximum value
93  i=i+1;
94  sconf(i).pf = { @couple_N_and_M_by_c };
95  sconf(i).samples = {csample};
96  sconf(i).pf_descr = {cdescr};
97  sconf(i).Mstrich = max(Mstrich_samples);
98  sconf(i).run_name_infix = 'coupled_Mstrich_Mmax_';
99 end
100 
101 if isempty(estimator_plots) || ismember('Mmax_train', estimator_plots)
102 
103  i=i+1;
104  sconf(i).pf = { 'N' };
105  sconf(i).samples = { Nsamples };
106  sconf(i).mu_set = info.M_train.sample;
107  sconf(i).pf_descr = { 'N' };
108  sconf(i).Mstrich = max(Mstrich_samples);
109  sconf(i).M = get_ei_size(detailed_data)-sconf(i).Mstrich;
110  sconf(i).run_name_infix = 'N_Mstrich_Mmax_train_set';
111 end
112 
113 if isempty(estimator_plots) || ismember('Mstrich_1', estimator_plots)
114  % plot of error estimates over 'N' and 'M', where and 'Mstrich' is set to
115  % one.
116  i=i+1;
117  sconf(i).pf = { 'N', 'M' };
118  sconf(i).max = [ Nmax, Mmax-1 ];
119  sconf(i).sample_size = [ Nsize, Msize ];
120  sconf(i).Mstrich = 1;
121  sconf(i).run_name_infix = 'Mstrich_1_';
122 end
123 
124 if isempty(estimator_plots) || ismember('Mstrich_max', estimator_plots)
125  % plot of error estimates over 'N' and 'M', where and 'Mstrich' is set to
126  % maximum.
127  i=i+1;
128  sconf(i).pf = { 'N', 'M' };
129  sconf(i).max = [ Nmax, Mmax - max(Mstrich_samples) ];
130  sconf(i).sample_size = [ Nsize, Msize ];
131  sconf(i).Mstrich = max(Mstrich_samples);
132  sconf(i).run_name_infix = 'Mstrich_max_';
133 end
134 
135 if isempty(estimator_plots) || ismember('coupled', estimator_plots)
136  % plot of error estimates over 'c' and 'Mstrich', where 'c' couples 'N' and
137  % 'M' by `(N,M) = c (Nmax, Mmax)`.
138  i=i+1;
139  sconf(i).pf = { 'Mstrich', @couple_N_and_M_by_c };
140  sconf(i).samples = { Mstrich_samples, csample };
141  sconf(i).pf_descr = { 'M''', cdescr };
142  sconf(i).run_name_infix = 'coupled_Mstrich_';
143 end
144 
145 if isempty(estimator_plots) || ismember('Mmax', estimator_plots)
146  % plot of error estimates over 'N' and 'Mstrich'
147  i=i+1;
148  sconf(i).pf = { 'N', 'Mstrich' };
149  sconf(i).samples = { Nsamples, Mstrich_samples };
150  sconf(i).pf_descr = { 'N', 'M''' };
151  sconf(i).run_name_infix = 'N_Mstrich_';
152  sconf(i).M = get_ei_size(detailed_data)-max(Mstrich_samples);
153 end
154 
155 if isempty(estimator_plots) || ismember('Nmax', estimator_plots)
156  % plot of error estimates over 'M' and 'Mstrich'
157  i=i+1;
158  sconf(i).pf = { 'M', 'Mstrich' };
159  sconf(i).samples = { Msamples, Mstrich_samples };
160  sconf(i).pf_descr = { 'M', 'M''' };
161  sconf(i).run_name_infix = 'M_Mstrich_';
162  sconf(i).N = get_rb_size(detailed_data);
163 end
164 
165 if exist('M_by_N_ratio', 'var')
166  params.M_by_N_ratio = M_by_N_ratio;
167 end
168 
169 output = cell(1,length(sconf));
170 % produce plots specified by the configuration structure 'sconf'
171 for i = 1:length(sconf)
172  range_params = [];
173  range_params.plot_fields = sconf(i).pf;
174  if isempty(sconf(i).max)
175  range_params.samples = sconf(i).samples;
176  else
177  range_params.max = sconf(i).max;
178  range_params.sample_size = sconf(i).sample_size;
179  end
180  if ~isempty(sconf(i).pf_descr)
181  range_params.plot_field_descr = sconf(i).pf_descr;
182  end
183  if ~isempty(sconf(i).Mstrich)
184  basis_gen.Mstrich = sconf(i).Mstrich;
185  end
186  if ~isempty(sconf(i).M)
187  basis_gen.M = sconf(i).M;
188  end
189  if ~isempty(sconf(i).N)
190  basis_gen.N = sconf(i).N;
191  end
192  if ~isempty(sconf(i).mu_set)
193  range_params.mu_set = sconf(i).mu_set;
194  testdir = [ basis_gen.model.name, '_' , sconf(i).run_name_infix, ...
195  '_train' ];
196  else
197  range_params.mu_set_size = mu_set_size;
198  testdir = [ basis_gen.model.name, '_', sconf(i).run_name_infix, '_', ...
199  num2str(range_params.mu_set_size) ];
200  end
201  params.run_name = [ testdir, '_step8'];
202  params.mode = 'estimator';
203 % params.mode = 'check';
204 
205  output{i}=stochastic_error_estimation(basis_gen, detailed_data, ...
206  reduced_data, ...
207  range_params, params);
208 
209  save([params.step8_outputfile,'_tmp'], 'output');
210 end
211 save(params.step8_outputfile, 'output');
function plot_error_landscape(output)
plots an output structure generated by stochastic_error_estimation()