rbmatlab 0.10.01
|
00001 classdef Default < Greedy.Plugin.Interface 00002 % Default implementation of a Greedy.Plugin.Interface interface class 00003 00004 properties (Transient) 00005 % temporary handle to the last object of type Greedy.User.ReducedData 00006 % computed by prepare_reduced_data(). 00007 reduced_data = []; 00008 end 00009 00010 properties (Dependent) 00011 00012 % @copybrief Greedy.Plugin.Interface.needs_preparation 00013 % 00014 % @copydetails Greedy.Plugin.Interface.needs_preparation 00015 % 00016 needs_preparation; 00017 end 00018 00019 properties 00020 00021 % @copybrief .Greedy.Plugin.Interface.indicator_mode 00022 % 00023 % @copydetails .Greedy.Plugin.Interface.indicator_mode 00024 indicator_mode = 'error'; 00025 00026 % boolean flag indicating whether the `L^2(\Omega)`-norm is used by 00027 % compute_error(). 00028 % 00029 % Otherwise the `L^{\infty}(\Omega)`-norm is applied. 00030 use_l2_error = true; 00031 00032 % @copybrief Greedy.Plugin.Interface.relative_error 00033 % 00034 % @copydetails Greedy.Plugin.Interface.relative_error 00035 relative_error = false; 00036 end 00037 00038 methods 00039 00040 function ged = Default(generator) 00041 % function ged = Default(generator) 00042 % constructor for a greedy extension object 00043 % 00044 % Parameters: 00045 % generator: object of type SnapshotsGenerator.Cached generating the 00046 % (high dimensional) basis functions 00047 ged = ged@Greedy.Plugin.Interface(generator); 00048 end 00049 00050 function need_prepare = get.needs_preparation(this) 00051 need_prepare = isequal(this.indicator_mode, 'error'); 00052 end 00053 00054 function [max_errs, max_err_sequence, max_mu_index] = ... 00055 error_indicators(this, rmodel, detailed_data, parameter_set, reuse_reduced_data) 00056 % function [max_errs, max_err_sequence, max_mu_index] = error_indicators(this, rmodel, detailed_data, parameter_set, reuse_reduced_data); 00057 % @copybrief Greedy.Plugin.Interface.error_indicators() 00058 % 00059 % @copydetails Greedy.Plugin.Interface.error_indicators() 00060 % 00061 % Parameters: 00062 % rmodel: an object of type .Greedy.User.IReducedModel 00063 % parameter_set : an object of type ParameterSampling.Interface 00064 % detailed_data: of type .Greedy.User.IDetailedData 00065 % 00066 % @note This method is controlled by the indicator_mode variable: 00067 % 00068 % If 'indicator_mode' equals 00069 % - 'estimator', the method error_estimators() is called 00070 % - 'error', compute_error() is used to compute "true" errors. 00071 00072 if nargin < 5 || isempty(reuse_reduced_data) 00073 reuse_reduced_data = false; 00074 end 00075 00076 if ~reuse_reduced_data 00077 prepare_reduced_data(this, rmodel, detailed_data); 00078 end 00079 00080 if isequal(this.indicator_mode, 'error') 00081 nmus = size(parameter_set, 1); 00082 00083 tmperrs = cell(1, nmus); 00084 tmpmaxerr = zeros(1, nmus); 00085 00086 rd = this.reduced_data; 00087 %parfor i = 1:nmus 00088 for i = 1:nmus 00089 fprintf('.'); 00090 trmodel = rmodel; 00091 tthis = this; 00092 trd = rd; 00093 set_mu(trmodel, parameter_set(i,:)); 00094 00095 tmperrs{i} = compute_error(tthis, trmodel, trd, detailed_data); 00096 tmpmaxerr(i) = max(tmperrs{i}); 00097 end 00098 00099 max_errs = tmpmaxerr; 00100 00101 [dummy, max_mu_index] = max(tmpmaxerr); 00102 max_err_sequence = tmperrs{max_mu_index}; 00103 00104 else 00105 [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, parameter_set); 00106 end 00107 end 00108 00109 function errs = compute_error(this, rmodel, reduced_data, detailed_data) 00110 % function errs = compute_error(this, rmodel, detailed_data) 00111 % @copybrief Greedy.Plugin.Interface.compute_error() 00112 % 00113 % @copydetails Greedy.Plugin.Interface.compute_error() 00114 % 00115 % Parameters: 00116 % rmodel: of type .Greedy.User.IReducedModel 00117 % detailed_data: of type .Greedy.User.IDetailedData 00118 % reduced_data: of type .Greedy.User.ReducedData 00119 00120 mu = get_mu(rmodel); 00121 dmodel = rmodel.detailed_model; 00122 set_mu(dmodel, mu); 00123 00124 model_data = detailed_data.model_data; 00125 00126 U = generate(this.generator, dmodel, model_data); 00127 Uapprox = generate_reduced(this, rmodel, reduced_data, detailed_data, U); 00128 00129 if isfield(model_data, 'grid') 00130 grid = model_data.grid; 00131 else 00132 grid = []; 00133 end 00134 00135 dmodel = rmodel.detailed_model; 00136 00137 if this.use_l2_error 00138 errs = dmodel.l2_error_sequence_algorithm(U, Uapprox, model_data); 00139 if this.relative_error 00140 errs = errs./dmodel.l2_error_sequence_algorithm(U, 0, model_data); 00141 end 00142 else 00143 errs = dmodel.linfty_error_sequence_algorithm(U, Uapprox, []); 00144 if this.relative_error 00145 errs = errs./dmodel.linfty_error_sequence_algorithm(U, 0, []); 00146 end 00147 end 00148 end 00149 00150 end 00151 00152 methods(Abstract) 00153 00154 % function [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, M_train); 00155 % computes a posteriori error estimators for the reduced simulations for 00156 % every parameter vector from a given parameter set `{\cal 00157 % M}_{\text{train}}`. 00158 % 00159 % An a posteriori error estimator estimates an error 00160 % ``\eta^k(\mu) \geq \| v_h(t^k;\mu) - v_{\text{red}}(t^k;\mu) \|`` 00161 % for every time step `0\leq t^0, \ldots, t^K = T` and every parameter `\mu 00162 % \in {\cal M}`. The norm is a problem specific norm determined by the 00163 % options in 'rmodel'. 00164 % 00165 % This function's main use is to find a parameter vector 00166 % ``\mu_{\max} = \arg \sup_{\mu \in {\cal M}_{\text{train}} } \max_{k=0,\ldots,K} \eta^k(\mu).`` 00167 % 00168 % @note The estimator must only depend on low dimensional data as computed 00169 % by the prepare_reduced_data() method such that it is efficiently 00170 % computable. 00171 % 00172 % Parameters: 00173 % rmodel: an object of type .Greedy.User.IReducedModel specifying the 00174 % basis generation process. 00175 % detailed_data: of type .Greedy.User.IDetailedData 00176 % M_train: a set of parameter vectors `{\cal M}_{\text{train}}` as 00177 % returned by ParameterSampling.Interface.space . 00178 % 00179 % Return values: 00180 % max_errs: a matrix of size 'n_parameters x model.nt+1' storing the 00181 % error indicator `\eta^k(\mu)` for every `k=0,\ldots,K` and 00182 % `\mu \in {\cal M}_{\text{train}}`. 00183 % max_err_sequence: a sequence of error indicators `\eta^k(\mu_{\max})` 00184 % for every `k=0,\ldots,K`. 00185 % max_mu_index: the index of the parameter vector `\mu_{\max}` in the 00186 % 'parameter_set.set' matrix. 00187 % 00188 [max_errs, max_err_sequence, max_mu_index] = error_estimators(this, rmodel, detailed_data, M_train); 00189 00190 end 00191 end