rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_error_domain.m
1 function [mu_grid,error_ma] = plot_error_domain(model, online_data, options)
2 %function [mu_grid,error_ma] = plot_error_domain(model, online_data, options)
3 %
4 % Function plotting the error map over the parameter domain (only 2D)
5 %
6 % Optional fields of option:
7 %
8 % intervals: density of grid for error map in the domain, default [22,22]
9 % figureNr: Figure Nr. for the plot window, default is opening a new
10 % window
11 % mu_grid: if mu_grid already exists it can be given here
12 % error_matrix: if error matrix already exists it can be given here, if not
13 % it is calculated
14 % holdOn: if set to 1 no new figure is drawn but the actual figure is
15 % used
16 % maxValue: maximum error on color scale to ensure
17 % comparability between several plots
18 % transparency: value between 0 and 1 defining the transparency of the
19 % patch
20 % colormap_autumn: flag if the colormap autumn should be used
21 %
22 % Markus Dihlmann 25.03.2010
23 %
24 
25 
26  if~(isfield(model,'verbose'))
27  model.verbose = 20;
28  end
29 
30 
31  if nargin<3
32  options=[];
33  end
34 
35  if ~isfield(options,'intervals')
36  options.intervals=[22,22];
37  end
38 
39  if ~isfield(options,'holdOn')
40  options.holdOn=0;
41  end
42 
43 
44 
45  if ~isfield(options,'transparency')
46  options.transparency=1;
47  end
48 
49  if ~(isfield(options,'mu_grid')&&isfield(options,'error_matrix'))
50  %%Calculate the error matrix and the grid
51  display('Calculating estimated test error');
52  Nrows=options.intervals(1);
53  Ncols=options.intervals(2);
54  gridparams=[];
55  gridparams.range = model.mu_ranges;
56  gridparams.numintervals=[Nrows,Ncols];
57  mu_grid=cubegrid(gridparams);
58  N_test=get(mu_grid,'nvertices');
59  mu_values=get(mu_grid,'vertex');
60 
61  est_error=zeros(1,N_test);
62  %error_matrix=zeros(Nrows+1,Ncols+1);
63  for i=1:N_test
64  %Choose a mu from range by random choice
65  mu = mu_values(i,:);
66  model = set_mu(model,mu');
67  %perform a reduced simulation and take the estiamated error of last
68  %time step
69 
70  rb_sim_data = rb_simulation(model, online_data);
71 
72  %add error to total error
73  est_error(i) = rb_sim_data.DeltaX(end);
74 
75  if(model.verbose>5)
76  if (mod(i,10)==0)
77  disp('...')
78  end
79  end
80  end
81 
82  %normalisation of errors:
83 
84  elementvert = get(mu_grid,'vertexindex');
85  num_elements = get(mu_grid,'nelements');
86  X=zeros(4,num_elements);
87  Y=zeros(4,num_elements);
88  error_ma=zeros(4,num_elements);
89  for i=1:num_elements
90  for j=1:4
91  X(j,i)=mu_values(elementvert(i,j),1);
92  Y(j,i)=mu_values(elementvert(i,j),2);
93  error_ma(j,i)=est_error(elementvert(i,j));
94  end
95  end
96  T=[1,0,0,0;0,1,0,0;0,0,0,1;0,0,1,0];
97  X=T*X;
98  Y=T*Y;
99  error_ma=T*error_ma;
100  else
101  mu_grid = options.mu_grid;
102  mu_values=get(mu_grid,'vertex');
103  error_ma = options.error_matrix;
104  elementvert = get(mu_grid,'vertexindex');
105  num_elements = get(mu_grid,'nelements');
106  X=zeros(4,num_elements);
107  Y=zeros(4,num_elements);
108 
109  for i=1:num_elements
110  for j=1:4
111  X(j,i)=mu_values(elementvert(i,j),1);
112  Y(j,i)=mu_values(elementvert(i,j),2);
113  end
114  end
115  T=[1,0,0,0;0,1,0,0;0,0,0,1;0,0,1,0];
116  X=T*X;
117  Y=T*Y;
118  end
119 
120  %plot patches
121 
122  if(options.holdOn==1)
123  hold on;
124  else
125  if isfield(options,'figureNr')
126  figure(options.figureNr);
127  else
128  figure;
129  end
130  end
131  %normation of color-map
132  if isfield(options,'maxValue');
133  caxis([0,options.maxValue]);
134  end
135  %plot patch
136  if isfield(options,'colormap_autumn')
137  if options.colormap_autumn
138  colormap(flipud(autumn));
139  end
140  end
141 
142  patch(X,Y,error_ma,'LineStyle','none','FaceAlpha',options.transparency);
143  colorbar;
144 
145 end
function r = verbose(level, message, messageId)
This function displays messages depending on a message-id and/or a level. Aditionally you can set/res...
Definition: verbose.m:17
A hierarchical cubegrid of arbitrary dimension.
Definition: cubegrid.m:17