rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
calculate_test_estimator.m
1 function [epsilon_test,epsilon_max,rb_sim_av_time,std_dev] = calculate_test_estimator(model, reduced_data)
2  %
3  % computes run-times and error estimators for a test sample of size
4  % 'N_test = 10' and collects statistical data on these magnitudes.
5  %
6  % Additionally, a scatter plot of the errors over the first two dimensions of
7  % the parameter domain is generated.
8  %
9  % Return values:
10  % epsilon_test: mean value of error estimators
11  % epsilon_max: max value of error estimators
12  % rb_sim_av_time: mean run-time of reduced simulations
13  % std_dev: standard deviation of error estimators
14  %
15  display('Calculating estimated test error');
16  N_test=25;%amount of Tests
17  rand('state',model.random_seed);
18 
19  if isfield(model,'N_test')
20  N_test = model.N_test;
21  end
22  disp(['Nr. of Test points: ',num2str(N_test)]);
23  random_mu = rand_uniform(N_test, model.mu_ranges);
24 
25  error_max=0;
26  rb_sim_time=0;
27  est_error=zeros(1,N_test);
28  for i=1:N_test
29  %Choose a mu from range by random choice
30  mu = random_mu(:,i);
31  model = set_mu(model,mu);
32  %perform a reduced simulation and take the estiamated error of last
33  %time step
34  rb_sim_timer = tic;
35  rb_sim_data = rb_simulation(model, reduced_data);
36  rb_sim_time = rb_sim_time + toc(rb_sim_timer);
37  %add error to total error
38  if isfield(rb_sim_data,'DeltaX')
39  est_error(i) = rb_sim_data.DeltaX(end);
40  elseif isfield(rb_sim_data,'Delta')
41  est_error(i) = rb_sim_data.Delta(end);
42  end
43 
44  if~(isfield(model,'verbose'))
45  model.verbose = 20;
46  end
47 
48 
49  if(model.verbose>5)
50  if (mod(i,10)==0)
51  disp('...')
52  end
53  end
54  end
55 
56 
57  %calculate average estimated error
58  epsilon_test = sum(est_error)/N_test;
59  epsilon_max=max(est_error);
60  rb_sim_av_time = rb_sim_time/N_test;
61  std_dev=std(est_error);
62  %Visualisation of error map on parameter domain
63 
64  sizeMu = size(random_mu);
65  if (sizeMu(1) == 3)
66  %figure;
67  % scatter3(random_mu(1,:),random_mu(2,:), random_mu(3,:),40,est_error,'filled');
68  %colorbar;
69  elseif (sizeMu(1) ==2)
70  figure;
71  scatter(random_mu(1,:),random_mu(2,:),40,est_error,'filled');
72  colorbar;
73  end
74 
75 end