rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
DetailedData.m
1 classdef DetailedData < Greedy.User.IDetailedData
2  % class generating the reduced basis space for the LinEvol problem with a
3  % Greedy algorithm.
4  %
5  % Parameters given by the constructor argument 'bg_descr' of type
6  % BasisGenDescr can control the
7  % - trainings sample (#train_sample_mode, #train_num_intervals, #train_seed)
8  % - trainings sample refinement (#refinement_mode, #max_refinement_level,
9  % #refinement_theta, #val_size, #val_seed, #stop_max_val_train_ratio)
10  % - the error indicator (#indicator_mode)
11  % - greedy variant selection by #Mmax_small
12  % - PODEI-greedy ('Mmax_small > 0'): #small_train_num_intervals,
13  % #epsilon_M_by_N_r,
14  % #maximum_temporary_error_growth_factor,
15  % #ei_minimum_residual,
16  % #extension_M_by_N_r,
17  % #ei_epsilon_small
18  % - subsequent generation of EI by EI-greedy and RB by POD-greedy. ('Mmax_small == 0')
19  % .
20  % - general EI extension controls (#noof_ei_extensions) and
21  % - general greedy controls (#stop_Nmax, #stop_Mmax, #stop_timeout,
22  % #stop_epsilon, #stop_max_val_train_ratio)
23 
24  properties (Dependent, SetAccess=private)
25  % a basis generation algorithm of type Greedy.Interface used to generated
26  % the reduced basis space.
27  bg_algorithm;
28  end
29 
30  properties (Access=private)
31  rb_generator;
32 
33  ei_generators = {};
34  end
35 
36  properties
37  % flag indicating whether the parameter sampling for the training set
38  % `M_{\text{train}}` type.
39  %
40  % Possible values:
41  % - 'uniform': (default) for a ParameterSampling.Uniform
42  % - 'random': for a ParameterSampling.Random
43  train_sample_mode = 'uniform';
44 
45  % number of intervals in the ParameterSampling.Uniform respectively number
46  % of vectors in the ParameterSampling.Random for the training set
47  % `M_{\text{train}}` of the parameter space `{\cal M}`.
48  train_num_intervals = 3;
49 
50  % If 'train_sample_mode == random', a ParameterSampling.Random is generated
51  % for the training set `M_{\text{val}}` with size #train_num_intervals and
52  % seed 'train_seed'.
53  train_seed = 4321;
54 
56  %
57  % Possible values are:
58  % - 'uniform': the parameter sampling is refined uniformly
59  % - 'adaptive': the parameter sampling is refined adaptively, such that
60  % only regions of the parameter space with high estimated
61  % errors are refined.
62  % - 'none': no Greedy.TrainingSetAdaptation object is created
63  refinement_mode = 'adaptive';
64 
66  %
68  max_refinement_level = 5;
69 
71  %
73  refinement_theta = 0.2;
74 
75  % If this value is non-zero, a ParameterSampling.Random is generated for the
76  % validation set `M_{\text{val}}` with size #val_size and seed #val_seed.
77  val_size = 10;
78 
79  % If the value of 'val_size' is non-zero, a ParameterSampling.Random is
80  % generated for the validation set `M_{\text{val}}` with size #val_size
81  % and seed 'val_seed'.
82  val_seed = 1234;
83 
84  % number of intervals in the ParameterSampling.Uniform for the @em small
85  % training set `M_{\text{small}}` for the generation of an initial
86  % collateral reduced basis space.
87  %
88  % See #Mmax_small for details.
89  small_train_num_intervals = 2;
90 
91  % sets the Greedy.Plugin.PODEI.Mmax_small member
92  %
93  % In order to use the estimator of a nonlinear evolution equation for a
94  % basis extension with a greedy search in the parameter space, a collateral
95  % reduced basis space for all existing operators needs to be present. For
96  % this reason at the beginning of the basis generation algorithm, a
97  % collateral reduced bases of size at most #Mmax_small is generated
98  %
99  % It uses an an Greedy.Plugin.EI instance with training set of size
100  % #small_train_num_intervals as extension algorithm for a
102  % limit is set to #ei_epsilon_small.
103  %
104  % If #Mmax_small is equal to '0', the initial collateral reduced bases are
105  % generated with stopping parameters #stop_Mmax and #stop_epsilon '*'
106  % #epsilon_M_by_N_r, and the PODGreedyAlgorithm afterwards only extends the
107  % reduced basis space.
108  Mmax_small = 10;
109 
110  % ratio between the stop epsilon criterion for collateral reduced basis
111  % spaces and reduced basis spaces.
112  %
113  % This option is only used in case 'Mmax_small == 0'. See #Mmax_small for
114  % details.
115  %
116  % Its purpose is to make the collateral reduced basis space more refined
117  % than the reduced basis space. This is necessary as the best possible
118  % error for the basis generation of the reduced basis space @em depends on
119  % the quality of the collateral reduced basis space.
120  epsilon_M_by_N_r = 1e-4;
121 
122  % maximum factor between the current maximum indicator and the smallest
123  % maximum error indicator during previous extensions
124  %
126  maximum_temporary_error_growth_factor = 0;
127 
128  % sets the GreedyPlugin.EI.minimum_residual
129  %
130  % This option is only used in case 'Mmax_small > 0'. See #Mmax_small for
131  % details.
132  ei_minimum_residual = 1e-8;
133 
135  %
136  % This option is only used in case 'Mmax_small > 0'. See #Mmax_small for
137  % details.
138  extension_M_by_N_r = 4;
139 
140  % maximum error between operator interpolations at which the initial value
141  % greedy is stopped.
142  %
143  % See #Mmax_small for details.
144  ei_epsilon_small = 1e-2;
145 
146  % sets the Greedy.Plugin.EI.stop_Mmax option
147  stop_Mmax = 200;
148 
149  % sets the Greedy.Plugin.PODEI.stop_Nmax option
150  stop_Nmax = 50;
151 
153  indicator_mode = 'estimator';
154 
155  % sets the Greedy.Algorithm.stop_epsilon option
156  stop_epsilon = 1e-5;
157 
159  stop_max_val_train_ratio = 1.2;
160 
161  % sets the Greedy.Algorithm.stop_timeout option
162  stop_timeout = 12*60*60;
163 
164  % sets the number of ei extensions
165  %
166  % See Greedy.Plugin.EI.noof_ei_extensions for details.
167  noof_ei_extensions = 1;
168  end
169 
170  methods
171  function dd = DetailedData(rmodel, model_data)
172  % function dd = DetailedData(rmodel, model_data)
173  % constructor constructing the reduced basis spaces and storing it in a
174  % DataTree.
175  %
176  % Parameters:
177  % rmodel: of type LinEvol.ReducedModel
178 
179  dd = dd@Greedy.User.IDetailedData(rmodel.bg_descr, model_data);
181  dd.rb_generator = SnapshotsGenerator.Trajectories(rmodel.detailed_model);
182 
183  dmodel = rmodel.detailed_model;
184 
185  opstrings = cellfun(@func2str, dmodel.descr.ei_space_operators, 'UniformOutput', false);
186  opcandidates(1).id = 'implicit';
187  opcandidates(1).op = dmodel.descr.L_I_local_ptr;
188  opcandidates(2).id = 'explicit';
189  opcandidates(2).op = dmodel.descr.L_E_local_ptr;
190 
191  for i = 1:length(opcandidates)
192 
193  if ~isempty(intersect(opstrings, func2str(opcandidates(i).op)))
194  ei_generator = SnapshotsGenerator.SpaceOpEvals(dmodel, opcandidates(i).id, dd.rb_generator, opcandidates(i).op);
195  dd.ei_generators = [ dd.ei_generators, ei_generator ];
196  end
197  end
198 
199  dd.datatree = gen_detailed_data(dd.bg_algorithm, rmodel, model_data);
200  end
201 
202  end
203 
204  methods
206  function basis_gen = get.bg_algorithm(this)
207  % generates a default @ref Greedy.Interface "basis generation object" for
208  % linear evolution problems as given by a DetailedModel.
209  %
210  % This function generates a Greedy.Interface implementation, with either
211  % a subsequent generation of empirical interpolation bases spaces for all
212  % operators and a reduced basis space afterwards, @b or a combined
213  % generation of all reduced spaces with the GreedyPlugin.PODEI variant
214  % of the GreedyAlgorithm.
215  %
216 
217  if isequal(this.train_sample_mode, 'uniform')
218  M_train = ParameterSampling.Uniform(this.train_num_intervals);
219  elseif isequal(this.train_sample_mode, 'random')
220  M_train = ParameterSampling.Random(this.train_num_intervals, this.train_seed);
221  else
222  error('unknown train_sample_mode');
223  end
224  if this.val_size > 0
225  M_val = ParameterSampling.Random(this.val_size, this.val_seed);
226  else
227  M_val = [];
228  end
229 
230  rb_ext = Greedy.Plugin.POD(this.rb_generator);
231  rb_ext.indicator_mode = this.indicator_mode;
232  rb_ext.stop_Nmax = this.stop_Nmax;
233 
234  ei_ext_array = cell(1, length(this.ei_generators));
235  for i = 1:length(this.ei_generators)
236  ei_ext_array{i} = Greedy.Plugin.EI(this.ei_generators(i));
237  end
238  if length(ei_ext_array) > 1
239  ei_ext = [ ei_ext_array{:} ];
240  else
241  ei_ext = ei_ext_array{1};
242  end
243 
244  ei_ext.stop_Mmax = this.stop_Mmax;
245 
246  ei_ext.noof_extensions = this.noof_ei_extensions;
248 
249 
250  if this.Mmax_small > 0
251 
252  ei_ext.minimum_residual = this.ei_minimum_residual;
253 
254  M_train_small = ParameterSampling.Uniform(this.small_train_num_intervals);
255  ei_greedy_small = Greedy.Algorithm(ei_ext, M_train_small);
256  ei_greedy_small.stop_epsilon = this.ei_epsilon_small;
257 
258  all_ext = Greedy.Plugin.PODEI(rb_ext, ei_ext, ei_greedy_small, this.Mmax_small);
259  all_ext.M_by_N_ratio = this.extension_M_by_N_r;
260  all_ext.maximum_temporary_error_growth_factor = this.maximum_temporary_error_growth_factor;
261 
262  if this.extension_M_by_N_r > 0
263  all_ext.skip_rb_after_bad_extension = false;
264  all_ext.discard_last_rb_after_bad_extension = false;
265  all_ext.skip_ei_after_bad_extension = false;
266  end
267 
268  pod_greedy = Greedy.Algorithm(all_ext, M_train, M_val);
269 
270  pod_greedy.val_train_ratio_seq_for_break = 2;
271  else
272  ei_greedy = Greedy.Algorithm(ei_ext, M_train);
273  ei_greedy.stop_epsilon = this.stop_epsilon * this.epsilon_M_by_N_r;
274 
275  pod_greedy = Greedy.Algorithm(rb_ext, M_train, M_val);
276 
277  pod_greedy.val_train_ratio_seq_for_break = 1;
278  end
279 
280  pod_greedy.stop_epsilon = this.stop_epsilon;
281  pod_greedy.stop_max_val_train_ratio = this.stop_max_val_train_ratio;
282  pod_greedy.stop_timeout = this.stop_timeout;
283 
284  if isa(M_train, 'ParameterSampling.IRefineable')
285 
286  if ~isequal(this.refinement_mode, 'none')
287  pod_greedy = Greedy.TrainingSetAdaptation(pod_greedy);
288  pod_greedy.refinement_mode = this.refinement_mode;
289  pod_greedy.max_refinement_level = this.max_refinement_level;
290  end
291 
292  if isequal(this.refinement_mode, 'adaptive')
293  pod_greedy.refinement_theta = this.refinement_theta;
294  end
295 
296  end
297 
298  if this.Mmax_small > 0
299  basis_gen = pod_greedy;
300  else
301  basis_gen = [ei_greedy, pod_greedy];
302  end
303 
304  end
305 
306  function rb_size = get_rb_size(this, rmodel)
307  leaf_dd = get_leaf(this, rmodel);
308  rb_size = get_rb_size(leaf_dd);
309  end
310 
311  end
312 end
313 
IDetailedModel implementation for a non linear evolution problem.
Definition: DetailedModel.m:18
reduced model for linear evolution problems as given by a LinEvol.DetailedModel.
Definition: ReducedModel.m:18
function isbad = indicate_bad_basis_extension(IDetailedData detailed_data)
indicates whether the last basis extension was bad
Definition: PODEI.m:720
refinement_mode
string specifying the method type for the adaptation of the parameter sampling. uniform or adaptive ...
val_train_ratio_seq_for_break
number of subsequent cases where the max_err_val_train_ratio is too high that is needed in order to b...
Definition: Algorithm.m:150
indicator_mode
string specifying which indicators shall be used by the error_indicators() method.
Definition: PODEI.m:91
Mmax_small
number of collateral reduced of the initial collateral reduced basis.
Definition: PODEI.m:114
Greedy.Plugin.Interface implementation that extends in each basis extension step, the reduced basis space and/or the collateral reduced basis space(s).
Definition: PODEI.m:19
M_by_N_ratio
forced ratio between the sizes of the colletaral and the regular reduced basis space ...
Definition: PODEI.m:147
max_refinement_level
maximum number of refinement levels in the refineable trainings parameter set
class generating the reduced basis space for the LinEvol problem with a Greedy algorithm.
Definition: DetailedData.m:18
Implementation of a SnapshotsGenerator.Cached for reduced basis generation. The generate() method ret...
Definition: Trajectories.m:18
default greedy basis generation class
Definition: Algorithm.m:18
stop_max_val_train_ratio
positive double value specifying the maximum ratio between the maximum error indicator over the valid...
Definition: Algorithm.m:135
refinement_theta
ratio of elements which are refined during an adaptive refinement step
Reduced basis implementation for linear evolution equations.
Parameter sampling sets.
Definition: Interface.m:1
Struct with control fields for the reduced basis generation.
Definition: dummyclasses.c:56
stop_epsilon
double specifying the maximum error indicator for which the basis generation shall be stopped...
Definition: Algorithm.m:115
stop_timeout
integer specifying the number of seconds after which the basis generation shall be stopped...
Definition: Algorithm.m:125
Parameter sampling class with uniformly distributed parameters in the parameter space.
Definition: Uniform.m:18
Specialization plugins for the greedy algorithm.
Definition: Default.m:2
an interface specialization for detailed data objects used with the Greedy algorithm.
Definition: IDetailedData.m:19
Interface classes to be implemented by the Greedy.Algorithm user.
Cacheable generators of detailed data snapshots.
Definition: Cached.m:1
Plugin for the Greedy.Algorithm class generating a collateral reduced basis space plus interpolation ...
Definition: EI.m:19
Parameter sampling class producing randomly distributed parameter samples in sparameter space ...
Definition: Random.m:18
greedy basis generation extension which adaptively refines the trainings parameter set...
stop_Mmax
maximum number of generated collateral reduced basis vectors.
Definition: EI.m:71
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1