rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
plot_basisgen_results.m
1 function plot_basisgen_results(fns, params)
2 %function plot_basisgen_results(fns[, params])
3 %
4 % function plotting of basis generation results generated
5 % by basisgen_main. Fns is a cell array with names of the
6 % basisgen-files assumed to exist in $(RBMATLABTEMP)/basisgen
7 % Some fields in params can be used to select the produced plots.
8 % by default all plots are generated
9 %
10 % required fields of params:
11 % plot_train_times: flag indicating, whether the train times are
12 % to be compared
13 % plot_train_estimators: flag indicating, whether the train
14 % error estimators are to be compared
15 % plot_test_estimators: flag indicating, whether the test
16 % error estimators are to be compared
17 % plot_test_errors: flag indicating, whether the test
18 % error estimators are to be compared
19 % plot_legends : cell array of legends to be used
20 % plot_linestyles : cell array of linestyles to be used
21 % plot_linecolors : cell array of linecolors
22 % plot_linewidths : vector of linewidths
23 
24 % Bernard Haasdonk 7.6.2007
25 
26 if nargin<2
27  params = [];
28 end;
29 
30 if ~isfield(params,'plot_train_times')
31  params.plot_train_times = 1;
32 end;
33 
34 if ~isfield(params,'plot_train_estimators')
35  params.plot_train_estimators = 1;
36 end;
37 
38 if ~isfield(params,'plot_test_estimators')
39  params.plot_test_estimators = 1;
40 end;
41 
42 if ~isfield(params,'plot_test_errors')
43  params.plot_test_errors = 1;
44 end;
45 
46 if ~isfield(params,'fontsize')
47  params.fontsize = 10;
48 end;
49 
50 if ~isfield(params,'plot_legends_location')
51  legends_location = 'NorthEast';
52 else
53  legends_location = params.plot_legends_location;
54 end;
55 
56 %fns = {'RB_random_fixed_50_tested',...
57 % 'RB_random_fixed_100_tested',...
58 % 'RB_uniform_fixed_49_tested',...
59 % 'RB_uniform_fixed_100_tested',...
60 % 'RB_uniform_refined_3_3_tested',...
61 % 'RB_adaptive_refined_3_3_tested'};
62 %fns = { 'RB_random_fixed_100_tested',...
63 % 'RB_uniform_fixed_100_tested',...
64 % 'RB_uniform_refined_3_3_tested',...
65 % 'RB_adaptive_refined_3_3_tested'};
66 %fns = {'RB_uniform_fixed_100_tested',...
67 % 'RB_uniform_refined_3_3_tested',...
68 % 'RB_adaptive_refined_3_3_tested'};
69 %fns = {'RB_uniform_fixed_100',...
70 % 'RB_adaptive_refined_2_2'};
71 
72 %fns= {'RB_uniform_fixed_16_tested', ...
73 % 'RB_uniform_fixed_64_tested', ...
74 % 'RB_uniform_fixed_256_tested', ...
75 % 'RB_uniform_fixed_1024_tested'};
76 
77 if isempty(fns)
78  fns = { ...
79  'RB_random_fixed_16_tested', ...
80  'RB_random_fixed_64_tested', ...
81  'RB_random_fixed_256_tested', ...
82  'RB_random_fixed_1024_tested'};
83 end;
84 %fns = {'RB_adaptive_refined_2_2_r1_tested', ...
85 % 'RB_adaptive_refined_2_2_r2_tested', ...
86 % 'RB_adaptive_refined_2_2_r5_tested', ...
87 % 'RB_adaptive_refined_2_2_r10_tested'};
88 
89 %fns = {'RB_uniform_fixed_49',...
90 % 'RB_uniform_fixed_longt_49'};
91 %compute_RB_methods = {'RB_random_fixed_100'};
92 
93 %fns = {'RB_adaptive_refined_tested',...
94 % 'RB_uniform_fixed_tested','RB_uniform_refined_tested'};
95 
96 data = {};
97 for fnum = 1:length(fns);
98  data{fnum} = load(fullfile(getenv('PDEMATLABTEMP'),'basisgen',fns{fnum}));
99 end;
100 
101 
102 
103 % plot_legends : cell array of legends to be used
104 % plot_linestyles : cell array of linestyles to be used
105 % plot_linecolors : cell array of linecolors
106 % plot_linewidths : vector of linewidths
107 
108 if ~isfield(params,'plot_legends');
109  % generate legends (without final '_tested'):
110  lfns = fns;
111  for fnum = 1:length(fns);
112  fn = fns{fnum};
113  i = findstr(fn,'_');
114  for j = length(i):-1:1
115  fn = [fn(1:(i(j)-1)),'\_',fn(i(j)+1:end)];
116  end;
117  i = findstr(fn,'\_tested');
118  if ~isempty(i)
119  fn = fn(1:(i(1)-1));
120  end;
121  lfns{fnum} = fn;
122  end;
123 else
124  lfns = params.plot_legends;
125 end;
126 
127 
128 if params.plot_train_times
129 
130  % plot of computation times
131  times = [];
132  for fnum = 1:length(fns);
133  l = length(data{fnum}.detailed_data.RB_info.toc_value_sequence);
134  if size(times,2)> l
135  times = [times;data{fnum}.detailed_data.RB_info.toc_value_sequence, ...
136  NaN * ones(1,size(times,2)-l)];
137  else
138  times = [times, NaN * ones(size(times,1),l-size(times,2));...
139  data{fnum}.detailed_data.RB_info.toc_value_sequence];
140  end;
141  end;
142  figure;
143  p = plot(times');
144  for i = 1:length(p)
145  if isfield(params,'plot_linecolors')
146  set(p(i),'color',params.plot_linecolors{i});
147  end;
148  if isfield(params,'plot_linewidths')
149  set(p(i),'Linewidth',params.plot_linewidths(i));
150  end;
151  if isfield(params,'plot_linestyles')
152  set(p(i),'Linestyle',params.plot_linestyles{i});
153  end;
154  end;
155 
156  title('computation time')
157  xlabel('num basis functions N');
158  ylabel('computation time [s]')
159  legend(lfns,'location',legends_location);
160 end;
161 
162 if params.plot_train_estimators
163  % plot of train-indicator decrease
164  estimators = [];
165  for fnum = 1:length(fns);
166  l = length(data{fnum}.detailed_data.RB_info.max_err_sequence);
167  if size(estimators,2)> l
168  estimators = [estimators;data{fnum}.detailed_data.RB_info.max_err_sequence, ...
169  NaN * ones(1,size(estimators,2)-l)];
170  else
171  estimators = [estimators, NaN * ones(size(estimators,1),...
172  l-size(estimators,2));...
173  data{fnum}.detailed_data.RB_info.max_err_sequence];
174  end;
175  end;
176  figure, p = plot(estimators');
177  for i = 1:length(p)
178  if isfield(params,'plot_linecolors')
179  set(p(i),'color',params.plot_linecolors{i});
180  end;
181  if isfield(params,'plot_linewidths')
182  set(p(i),'Linewidth',params.plot_linewidths(i));
183  end;
184  if isfield(params,'plot_linestyles')
185  set(p(i),'Linestyle',params.plot_linestyles{i});
186  end;
187  end;
188 
189 
190  title('train error-indicator value decrease')
191  xlabel('num basis functions N');
192  ylabel('maximum indicator values')
193  set(gca,'Yscale','log');
194  legend(lfns,'location',legends_location);
195 end;
196 
197 max_test_error_available = zeros(length(fns));
198 max_test_estimator_available = zeros(length(fns));
199 min_test_estimator_available = zeros(length(fns));
200 min_test_error_available = zeros(length(fns));
201 for fnum = 1:length(fns);
202  if isfield(data{fnum}.detailed_data.RB_info, ...
203  'max_test_error_sequence')
204  max_test_error_available(fnum) = 1;
205  end;
206  if isfield(data{fnum}.detailed_data.RB_info, ...
207  'max_test_estimator_sequence')
208  max_test_estimator_available(fnum) = 1;
209  end;
210  if isfield(data{fnum}.detailed_data.RB_info, ...
211  'min_test_estimator_sequence')
212  min_test_estimator_available(fnum) = 1;
213  end;
214  if isfield(data{fnum}.detailed_data.RB_info, ...
215  'min_test_error_sequence')
216  min_test_error_available(fnum) = 1;
217  end;
218 end;
219 
220 %--------------------------------------------------------------------------
221 
222 % plot of max test-estimator decrease
223 if params.plot_test_estimators
224  estimators = [];
225  estimatorsX = [];
226  estimatorsY = [];
227  fi = find(max_test_estimator_available);
228  for fnum = 1:length(fi);
229  max_seq = data{fi(fnum)}.detailed_data.RB_info.max_test_estimator_sequence;
230 % l = length(max_seq);
231 % if size(estimators,2)> l
232 % estimators = ...
233 % [estimators;...
234 % max_seq(:)',...
235 % NaN * ones(1,size(estimators,2)-l)];
236 % else
237 % estimators = [estimators, ...
238 % NaN * ones(size(estimators,1),...
239 % l-size(estimators,2));...
240 % max_seq(:)'];
241 % end;
242 
243  max_seqX = find(~isnan(max_seq));
244  max_seqY = max_seq(max_seqX);
245  l = length(max_seqX);
246  if size(estimatorsX,2)> l
247  estimatorsX = ...
248  [estimatorsX;...
249  max_seqX(:)',...
250  NaN * ones(1,size(estimatorsX,2)-l)];
251  estimatorsY = ...
252  [estimatorsY;...
253  max_seqY(:)',...
254  NaN * ones(1,size(estimatorsY,2)-l)];
255  else
256  estimatorsX = [estimatorsX, ...
257  NaN * ones(size(estimatorsX,1),...
258  l-size(estimatorsX,2));...
259  max_seqX(:)'];
260  estimatorsY = [estimatorsY, ...
261  NaN * ones(size(estimatorsY,1),...
262  l-size(estimatorsY,2));...
263  max_seqY(:)'];
264  end;
265 
266  end;
267  if ~isempty(fi)
268  figure;
269  % if isempty(isnan(estimators))
270  % p = plot(estimators');
271  % else
272  % p = plot(estimators','x');
273  % end;
274  p = plot(estimatorsX',estimatorsY','x');
275  for i = 1:length(p)
276  if isfield(params,'plot_linecolors')
277  set(p(i),'color',params.plot_linecolors{fi(i)});
278  end;
279  if isfield(params,'plot_linewidths')
280  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
281  end;
282  if isfield(params,'plot_linestyles')
283  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
284  end;
285  end;
286 
287  title('test estimator values decrease','Fontsize',params.fontsize)
288  xlabel('num basis functions N','Fontsize',params.fontsize);
289  ylabel('maximum test estimator values Delta_N','Fontsize',params.fontsize)
290  set(gca,'Yscale','log');
291  legend(lfns(fi),'location',legends_location,'Fontsize',params.fontsize);
292  end;
293 end;
294 
295 
296 % plot of min test-estimator decrease
297 if params.plot_test_estimators
298  estimators = [];
299  fi = find(min_test_estimator_available);
300  for fnum = 1:length(fi);
301  l = length(data{fi(fnum)}.detailed_data.RB_info.min_test_estimator_sequence);
302  if size(estimators,2)> l
303  estimators = ...
304  [estimators;...
305  data{fi(fnum)}.detailed_data.RB_info.min_test_estimator_sequence(:)', ...
306  NaN * ones(1,size(estimators,2)-l)];
307  else
308  estimators = [estimators, ...
309  NaN * ones(size(estimators,1),...
310  l-size(estimators,2));...
311  data{fi(fnum)}.detailed_data.RB_info.min_test_estimator_sequence(:)'];
312  end;
313  end;
314  if ~isempty(fi)
315  figure;
316  if isempty(isnan(estimators))
317  p = plot(estimators');
318  else
319  p = plot(estimators','x');
320  end;
321  for i = 1:length(p)
322  if isfield(params,'plot_linecolors')
323  set(p(i),'color',params.plot_linecolors{fi(i)});
324  end;
325  if isfield(params,'plot_linewidths')
326  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
327  end;
328  if isfield(params,'plot_linestyles')
329  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
330  end;
331  end;
332  title('test estimator values decrease')
333  xlabel('num basis functions N');
334  ylabel('minimum test estimator values Delta_N')
335  set(gca,'Yscale','log');
336  legend(lfns(fi),'location',legends_location);
337  end;
338 end;
339 
340 
341 % plot of max/min test-estimator ratio
342 if params.plot_test_estimators
343  estimators = [];
344 
345  estimatorsX = [];
346  estimatorsY = [];
347 
348  for fnum = 1:length(fi);
349  max_seq = data{fi(fnum)}.detailed_data.RB_info.max_test_estimator_sequence;
350  min_seq = data{fi(fnum)}.detailed_data.RB_info.min_test_estimator_sequence;
351  seqX = find(~isnan(max_seq));
352  seqY = max_seq(seqX)./min_seq(seqX);
353  l = length(seqX);
354  if size(estimatorsX,2)> l
355  estimatorsX = ...
356  [estimatorsX;...
357  seqX(:)',...
358  NaN * ones(1,size(estimatorsX,2)-l)];
359  estimatorsY = ...
360  [estimatorsY;...
361  seqY(:)',...
362  NaN * ones(1,size(estimatorsY,2)-l)];
363  else
364  estimatorsX = [estimatorsX, ...
365  NaN * ones(size(estimatorsX,1),...
366  l-size(estimatorsX,2));...
367  seqX(:)'];
368  estimatorsY = [estimatorsY, ...
369  NaN * ones(size(estimatorsY,1),...
370  l-size(estimatorsY,2));...
371  seqY(:)'];
372  end;
373 
374  end;
375  if ~isempty(fi)
376  figure;
377  % if isempty(isnan(estimators))
378  % p = plot(estimators');
379  % else
380  % p = plot(estimators','x');
381  % end;
382 
383  p = plot(estimatorsX',estimatorsY','x');
384 
385  for i = 1:length(p)
386  if isfield(params,'plot_linecolors')
387  set(p(i),'color',params.plot_linecolors{fi(i)});
388  end;
389  if isfield(params,'plot_linewidths')
390  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
391  end;
392  if isfield(params,'plot_linestyles')
393  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
394  end;
395  end;
396  title('max/min test estimator ratio','Fontsize',params.fontsize)
397  xlabel('num basis functions N','Fontsize',params.fontsize);
398  ylabel('max/min test estimator ratio','Fontsize',params.fontsize)
399  set(gca,'Yscale','log');
400  legend(lfns(fi),'location',legends_location,'Fontsize',params.fontsize);
401  end;
402 end;
403 
404 
405 if isfield(params,'plot_max_test_vs_time')
406 
407  % plot of max test-estimator versus training time
408  estimators = [];
409  estimatorsX = [];
410  estimatorsY = [];
411 
412  for fnum = 1:length(fi);
413  max_seq = data{fi(fnum)}.detailed_data.RB_info.max_test_estimator_sequence;
414  seqN = find(~isnan(max_seq));
415  seqX = data{fi(fnum)}.detailed_data.RB_info.toc_value_sequence(seqN);
416  seqY = max_seq(seqN);
417  l = length(seqX);
418  if size(estimatorsX,2)> l
419  estimatorsX = ...
420  [estimatorsX;...
421  seqX(:)',...
422  NaN * ones(1,size(estimatorsX,2)-l)];
423  estimatorsY = ...
424  [estimatorsY;...
425  seqY(:)',...
426  NaN * ones(1,size(estimatorsY,2)-l)];
427  else
428  estimatorsX = [estimatorsX, ...
429  NaN * ones(size(estimatorsX,1),...
430  l-size(estimatorsX,2));...
431  seqX(:)'];
432  estimatorsY = [estimatorsY, ...
433  NaN * ones(size(estimatorsY,1),...
434  l-size(estimatorsY,2));...
435  seqY(:)'];
436  end;
437 
438  end;
439  if ~isempty(fi)
440  figure;
441  % if isempty(isnan(estimators))
442  % p = plot(estimators');
443  % else
444  % p = plot(estimators','x');
445  % end;
446 
447  p = plot(estimatorsX',estimatorsY','x');
448 
449  for i = 1:length(p)
450  if isfield(params,'plot_linecolors')
451  set(p(i),'color',params.plot_linecolors{fi(i)});
452  end;
453  if isfield(params,'plot_linewidths')
454  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
455  end;
456  if isfield(params,'plot_linestyles')
457  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
458  end;
459  end;
460  title('max test estimator over training time','Fontsize',params.fontsize)
461  xlabel('training time','Fontsize',params.fontsize);
462  ylabel('max test estimator value','Fontsize',params.fontsize)
463  set(gca,'Yscale','log');
464  legend(lfns(fi),'location',legends_location,'Fontsize',params.fontsize);
465  end;
466 end;
467 
468 % plot of max test-error decrease
469 if params.plot_test_errors
470  estimators = [];
471  fi = find(max_test_error_available);
472  for fnum = 1:length(fi);
473  l = length(data{fi(fnum)}.detailed_data.RB_info.max_test_error_sequence);
474  if size(estimators,2)> l
475  estimators = [estimators;...
476  data{fi(fnum)}.detailed_data.RB_info.max_test_error_sequence(:)',...
477  NaN * ones(1,size(estimators,2)-l)];
478  else
479  estimators = ...
480  [estimators, NaN * ones(size(estimators,1),l-size(estimators,2));...
481  data{fi(fnum)}.detailed_data.RB_info.max_test_error_sequence(:)'];
482  end;
483  end;
484  if ~isempty(fi)
485  figure;
486  if isempty(isnan(estimators))
487  p = plot(estimators');
488  else
489  p = plot(estimators','x');
490  end;
491  for i = 1:length(p)
492  if isfield(params,'plot_linecolors')
493  set(p(i),'color',params.plot_linecolors{fi(i)});
494  end;
495  if isfield(params,'plot_linewidths')
496  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
497  end;
498  if isfield(params,'plot_linestyles')
499  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
500  end;
501  end;
502  title('test error values decrease')
503  xlabel('num basis functions N');
504  ylabel('maximum test error values')
505  set(gca,'Yscale','log');
506  legend(lfns(fi),'location',legends_location);
507  end;
508 end;
509 
510 
511 
512 % plot of min test-error decrease
513 if params.plot_test_errors
514  estimators = [];
515  fi = find(min_test_error_available);
516  for fnum = 1:length(fi);
517  l = length(data{fi(fnum)}.detailed_data.RB_info.min_test_error_sequence);
518  if size(estimators,2)> l
519  estimators = [estimators;...
520  data{fi(fnum)}.detailed_data.RB_info.min_test_error_sequence(:)',...
521  NaN * ones(1,size(estimators,2)-l)];
522  else
523  estimators = ...
524  [estimators, NaN * ones(size(estimators,1),l-size(estimators,2));...
525  data{fi(fnum)}.detailed_data.RB_info.min_test_error_sequence(:)'];
526  end;
527  end;
528  if ~isempty(fi)
529  figure;
530  if isempty(isnan(estimators))
531  p = plot(estimators');
532  else
533  p = plot(estimators','x');
534  end;
535  for i = 1:length(p)
536  if isfield(params,'plot_linecolors')
537  set(p(i),'color',params.plot_linecolors{fi(i)});
538  end;
539  if isfield(params,'plot_linewidths')
540  set(p(i),'Linewidth',params.plot_linewidths(fi(i)));
541  end;
542  if isfield(params,'plot_linestyles')
543  set(p(i),'Linestyle',params.plot_linestyles{fi(i)});
544  end;
545  end;
546  title('test error values decrease')
547  xlabel('num basis functions N');
548  ylabel('minimum test error values')
549  set(gca,'Yscale','log');
550  legend(lfns(fi),'location',legends_location);
551  end;
552 end;
553 
554 
555 
556 
557 
558 
559 % TO BE ADJUSTED TO NEW SYNTAX
560 %| \docupdate