rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Default.m
1 classdef Default < Greedy.Plugin.Interface
2  % Default implementation of a Greedy.Plugin.Interface interface class
3 
4  properties (Transient)
5  % temporary handle to the last object of type Greedy.User.ReducedData
6  % computed by prepare_reduced_data().
7  reduced_data = [];
8  end
9 
10  properties (Dependent)
11 
13  %
15  %
16  needs_preparation;
17  end
18 
19  properties
20 
21  % @copybrief .Greedy.Plugin.Interface.indicator_mode
22  %
23  % @copydetails .Greedy.Plugin.Interface.indicator_mode
24  indicator_mode = 'error';
25 
26  % boolean flag indicating whether the `L^2(\Omega)`-norm is used by
27  % compute_error().
28  %
29  % Otherwise the `L^{\infty}(\Omega)`-norm is applied.
30  use_l2_error = true;
31 
33  %
35  relative_error = false;
36  end
37 
38  methods
39 
40  function ged = Default(generator)
41  % function ged = Default(generator)
42  % constructor for a greedy extension object
43  %
44  % Parameters:
45  % generator: object of type SnapshotsGenerator.Cached generating the
46  % (high dimensional) basis functions
47  ged = ged@Greedy.Plugin.Interface(generator);
48  end
49 
50  function need_prepare = get.needs_preparation(this)
51  need_prepare = isequal(this.indicator_mode, 'error');
52  end
53 
54  function [max_errs, max_err_sequence, max_mu_index] = ...
55  error_indicators(this, rmodel, detailed_data, parameter_set, reuse_reduced_data)
56  % function [max_errs, max_err_sequence, max_mu_index] = error_indicators(this, rmodel, detailed_data, parameter_set, reuse_reduced_data);
58  %
60  %
61  % Parameters:
62  % rmodel: an object of type .Greedy.User.IReducedModel
63  % parameter_set : an object of type ParameterSampling.Interface
64  % detailed_data: of type .Greedy.User.IDetailedData
65  %
66  % @note This method is controlled by the indicator_mode variable:
67  %
68  % If 'indicator_mode' equals
69  % - 'estimator', the method error_estimators() is called
70  % - 'error', compute_error() is used to compute "true" errors.
71 
72  if nargin < 5 || isempty(reuse_reduced_data)
73  reuse_reduced_data = false;
74  end
75 
76  if ~reuse_reduced_data
77  prepare_reduced_data(this, rmodel, detailed_data);
78  end
79 
80  if isequal(this.indicator_mode, 'error')
81  nmus = size(parameter_set, 1);
82 
83  tmperrs = cell(1, nmus);
84  tmpmaxerr = zeros(1, nmus);
85 
86  rd = this.reduced_data;
87  %parfor i = 1:nmus
88  for i = 1:nmus
89  fprintf('.');
90  trmodel = rmodel;
91  tthis = this;
92  trd = rd;
93  set_mu(trmodel, parameter_set(i,:));
94 
95  tmperrs{i} = compute_error(tthis, trmodel, trd, detailed_data);
96  tmpmaxerr(i) = max(tmperrs{i});
97  end
98 
99  max_errs = tmpmaxerr;
100 
101  [dummy, max_mu_index] = max(tmpmaxerr);
102  max_err_sequence = tmperrs{max_mu_index};
103 
104  else
105  [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, parameter_set);
106  end
107  end
108 
109  function errs = compute_error(this, rmodel, reduced_data, detailed_data)
110  % function errs = compute_error(this, rmodel, detailed_data)
112  %
114  %
115  % Parameters:
116  % rmodel: of type .Greedy.User.IReducedModel
117  % detailed_data: of type .Greedy.User.IDetailedData
118  % reduced_data: of type .Greedy.User.ReducedData
119 
120  mu = get_mu(rmodel);
121  dmodel = rmodel.detailed_model;
122  set_mu(dmodel, mu);
123 
124  model_data = detailed_data.model_data;
125 
126  U = generate(this.generator, dmodel, model_data);
127  Uapprox = generate_reduced(this, rmodel, reduced_data, detailed_data, U);
128 
129  if isfield(model_data, 'grid')
130  grid = model_data.grid;
131  else
132  grid = [];
133  end
134 
135  dmodel = rmodel.detailed_model;
136 
137  if this.use_l2_error
138  errs = dmodel.l2_error_sequence_algorithm(U, Uapprox, model_data);
139  if this.relative_error
140  errs = errs./dmodel.l2_error_sequence_algorithm(U, 0, model_data);
141  end
142  else
143  errs = dmodel.linfty_error_sequence_algorithm(U, Uapprox, []);
144  if trelative_error
145  errs = errs./dmodel.linfty_error_sequence_algorithm(U, 0, []);
146  end
147  end
148  end
149 
150  end
151 
152  methods(Abstract)
153 
154  % function [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, M_train);
155  % computes a posteriori error estimators for the reduced simulations for
156  % every parameter vector from a given parameter set `{\cal
157  % M}_{\text{train}}`.
158  %
159  % An a posteriori error estimator estimates an error
160  % ``\eta^k(\mu) \geq \| v_h(t^k;\mu) - v_{\text{red}}(t^k;\mu) \|``
161  % for every time step `0\leq t^0, \ldots, t^K = T` and every parameter `\mu
162  % \in {\cal M}`. The norm is a problem specific norm determined by the
163  % options in 'rmodel'.
164  %
165  % This function's main use is to find a parameter vector
166  % ``\mu_{\max} = \arg \sup_{\mu \in {\cal M}_{\text{train}} } \max_{k=0,\ldots,K} \eta^k(\mu).``
167  %
168  % @note The estimator must only depend on low dimensional data as computed
169  % by the prepare_reduced_data() method such that it is efficiently
170  % computable.
171  %
172  % Parameters:
173  % rmodel: an object of type .Greedy.User.IReducedModel specifying the
174  % basis generation process.
175  % detailed_data: of type .Greedy.User.IDetailedData
176  % M_train: a set of parameter vectors `{\cal M}_{\text{train}}` as
177  % returned by ParameterSampling.Interface.space .
178  %
179  % Return values:
180  % max_errs: a matrix of size 'n_parameters x model.nt+1' storing the
181  % error indicator `\eta^k(\mu)` for every `k=0,\ldots,K` and
182  % `\mu \in {\cal M}_{\text{train}}`.
183  % max_err_sequence: a sequence of error indicators `\eta^k(\mu_{\max})`
184  % for every `k=0,\ldots,K`.
185  % max_mu_index: the index of the parameter vector `\mu_{\max}` in the
186  % 'parameter_set.set' matrix.
187  %
188  [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, M_train);
189 
190  end
191 end
virtual function errs = compute_error(Greedy.User.IReducedModel rmodel,Greedy.User.ReducedData reduced_data,Greedy.User.IDetailedData detailed_data)
computes the "true" error between a reduced and a detailed function .
Interface class for extension algorithms which define the basis extension routines used by the abstra...
Definition: Interface.m:19
Interface for the storage and generation of detailed data that can be used to build reduced basis fun...
Definition: Cached.m:18
virtual function [ max_errs , max_err_sequence , max_mu_index ] = error_indicators(Greedy.User.IReducedModel rmodel,Greedy.User.IDetailedData detailed_data, parameter_set, reuse_reduced_data)
computes error indicators for the reduced simulations for every parameter vector from a given paramet...
relative_error
boolean flag specifying whether we want to use the relative error for error_indicators() and compute_...
Definition: Interface.m:58
a default reduced data implementation which stores a data tree object copying the structure of a Gree...
Definition: ReducedData.m:19
needs_preparation
boolean indicating whether the prepare_reduced_data() method needs to be computed before error_indica...
Definition: Interface.m:89
Interface for parameter sampling classes producing discrete parameter sample in the parameter space ...
Definition: Interface.m:18
Specialization plugins for the greedy algorithm.
Definition: Default.m:2
Cacheable generators of detailed data snapshots.
Definition: Cached.m:1
Default implementation of a Greedy.Plugin.Interface interface class.
Definition: Default.m:19
Customizable implementation of an abstract greedy algorithm.
Definition: DuneRBLeafNode.m:1