rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
rb_test_convergence.m
Go to the documentation of this file.
1 function [max_test_errs, max_mu_index, ...
2  min_test_errs, min_mu_index] = rb_test_convergence(detailed_data,model)
3 %function [max_test_errs, max_mu_index,min_test_errs, min_mu_index] =
4 % rb_test_convergence(detailed_data,model)
5 %
6 % function determining the maximum and minimum test-error (linfty-l2 or
7 % estimator) for the given set of vectors mu (columns in
8 % detailed_data.RB_info.M_test) of the RB simulation with corresponding
9 % RB set. A convergence test is
10 % performed by performing this maximum and minimum
11 % detection for all numbers of RB from 1 to the complete set.
12 % the output is max_test_errs(i): the maximum test-quantity on the given
13 % mu-subset for reduced basis RB(:,1:i). The number of the mu, which
14 % incurs this maximum error is returned in
15 % max_mu_index(i). Similarly for min_test_errs and min_mu_index.
16 %
17 % Required fields of model:
18 % RB_error_indicator: 'error' or 'estimator'
19 % RB_detailed_test_savepath : in case of 'error' this path
20 % either contains the test-samples or they are
21 % generated.
22 % error_algorithm : algorithm computing the true error in
23 % case of 'error' mode
24 % test_N_samples : (optional) number of N samples, which are tested,
25 % i.e. value 11 for a basis of size N=21 will give 11
26 % test-results for the values N = 1,3,5,7,9,11,13,15,17,19,21
27 % an equidistant sampling of the N-interval is
28 % realized. If not specified, all numbers 1:N are tested
29 
30 % Bernard Haasdonk 2.8.2006
31 
32 nmus = size(detailed_data.RB_info.M_test,2);
33 
34 nRBs = size(detailed_data.RB,2);
35 
36 max_test_errs = NaN(nRBs,1);
37 max_mu_index = NaN(nRBs,1);
38 min_test_errs = NaN(nRBs,1);
39 min_mu_index = NaN(nRBs,1);
40 
41 % compute offline data once for complete RB set
42 model.Nmax = nRBs;
43 offline_data = rb_offline_prep(detailed_data,model);
44 
45 if isequal(model.RB_error_indicator,'error')
46  savepath = model.RB_detailed_test_savepath;
47 
48  if isempty(savepath)
49  error('savepath must be provided in case of error as target value!');
50  end;
51  save_detailed_simulations(detailed_data.RB_info.M_test,...
52  savepath,...
53  detailed_data.grid,...
54  model);
55 end;
56 
57 if ~isfield(model,'test_N_samples') || ...
58  isempty(model.test_N_samples) % default: all numbers from N to 1
59  Nsamples = (nRBs:-1:1);
60 else % compute equidistributed sample-number
61  Nsamples = ceil((0:(model.test_N_samples-1))*...
62  (nRBs-1)/(model.test_N_samples-1)+ 0.5);
63  Nsamples = Nsamples(end:-1:1);
64 % keyboard;
65 end;
66 
67 for nRB = Nsamples
68  disp(['testing for nrb = ',num2str(nRB)]);
69  model.N = nRB;
70  reduced_data = rb_online_prep(offline_data,model);
71 
72  for i = 1:nmus
73  model = model.set_mu(detailed_data.RB_info.M_test(:,i),model);
74  simulation_data = rb_simulation(reduced_data,model);
75 
76  if isequal(model.RB_error_indicator,'error')
77  sim_data = load_detailed_simulation(i, ...
78  savepath,...
79  model);
80  U = sim_data.U;
81  Uappr = rb_reconstruction(detailed_data,simulation_data);
82  errs = feval(model.error_algorithm,U,Uappr,detailed_data.grid,model);
83  err = errs(end);
84 
85  elseif isequal(model.RB_error_indicator, 'estimator')
86  err = simulation_data.Delta(end);
87  else
88  error('error indicator type unknown');
89  end;
90  test_err(i) = err;
91  end;
92 
93  [max_test_errs(nRB), max_mu_index(nRB)] = max(test_err);
94  [min_test_errs(nRB), min_mu_index(nRB)] = min(test_err);
95 end;
function [ sim_data , tictoc ] = load_detailed_simulation(m, savepath, params)
load single trajectory of previously saved results.
function save_detailed_simulations(model, model_data, M, savepath)
perform loop over detailed simulations and save results or check consistency with existing saved resu...
function [ max_test_errs , max_mu_index , min_test_errs , min_mu_index ] = rb_test_convergence(detailed_data, model)
rb_test_convergence(detailed_data,model)