rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
rb_test_indicator.m
Go to the documentation of this file.
1 function test_err = rb_test_indicator(model,...
2  detailed_data,reduced_data,...
3  M_test,savepath)
4 %function test_err = rb_test_indicator(model,[detailed_data],[reduced_data]
5 % M_test,[savepath])
6 %
7 % function determining the test-error-indicators for the given set of
8 % vectors mu (columns in M_test) of the RB simulation with corresponding
9 % RB set. Either the true errors or the error-estimators are
10 % determined. If the true errors are wanted, these are produced
11 % into or read from the directory savepath. The offline_data is
12 % generated, if empty. The detailed data can be ommited if
13 % offline_data is available, and no true 'error' is wanted
14 %
15 % Required fields of model:
16 % RB_error_indicator: 'error' or 'estimator'
17 % error_algorithm : in case of 'error' mode, this algorithm
18 % is called for computing the error between a U and Uappr
19 
20 % Bernard Haasdonk 27.5.2007
21 
22 if isempty(reduced_data)
23  reduced_data = gen_reduced_data(model,detailed_data);
24 end;
25 
26 if ~isfield(model,'N')
27  if isfield(detailed_data,'N')
28  model.N=detailed_data.N;
29  else
30  model.N = size(model.get_rb_from_detailed_data(detailed_data),2);
31  end
32 end;
33 if isfield(model,'rb_problem_type')
34 if isequal(model.rb_problem_type,'nonlin_evol') ...
35  || isequal(model.rb_problem_type, 'richards')
36  if ~isfield(model,'M') || (model.M==-1)
37  model.M = max(cellfun(@(X)(size(X,2)), detailed_data.QM));
38  end;
39 end;
40 end;
41 
42 
43 reduced_data = model.reduced_data_subset(model, reduced_data);
44 
45 
46 switch model.RB_error_indicator
47  case 'error'
48 
49  test_err = rb_test_error(model,...
50  detailed_data, reduced_data, M_test, ...
51  savepath);
52 
53  case 'estimator'
54  test_err = rb_test_estimator(model,...
55  reduced_data,M_test);
56 
57  case 'ei_estimator_test'
58  tic;
59  test_err.estimator = rb_test_estimator(model, ...
60  reduced_data,M_test);
61  t1 = toc;
62  tic;
63  test_err.error = rb_test_error(model, ...
64  detailed_data, reduced_data, M_test, ...
65  savepath);
66  t2 = toc;
67  lambda = test_err.estimator ./ test_err.error;
68  disp(['Evaluation of the reliability lambda=Delta_est/Delta_err of a ',...
69  'posteriori estimator (min, max, mean):']);
70  disp(['min(lambda)=',num2str(min(lambda)), ...
71  ' max(lambda)=',num2str(max(lambda)), ...
72  ' mean(lambda)=', num2str(mean(lambda))]);
73  disp('Evaluation of the runtime gain of posteriori estimator');
74  disp(['t_post=',num2str(t1),' t_err=',num2str(t2)]);
75  if(any(test_err.estimator < test_err.error))
76  disp('Error: a posteriori estimator underestimates the real error');
77  keyboard;
78  end
79  otherwise
80  error('error indicator type unknown');
81 end;
82 
function test_err = rb_test_indicator(model, detailed_data, reduced_data, M_test, savepath)
M_test,[savepath])