rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Kernel.m
2 
3  properties
4 
5  kernel = 'gaussian';
6  kernel_parameters = [1];
7 
8  kernels = struct(...
9  'gaussian', {@(x,y,p) exp(-norm(x-y)^2/p(1)^2), [1]} ...
10  );
11 
12  end
13 
14  methods
15  function data = gen_detailed_data(this, model, model_data, detailed_data)
16  % Store some additional data for the online calculation
17  reduced_data = eval([model.problem_type(), '.ReducedData(model, detailed_data);']);
18 
19  % TODO: Think about the training set strategy
20  mus = detailed_data.info.M_train.sample(detailed_data.info.chosen_mu, :);
21 
22  nmus = size(mus, 1);
23  times = zeros(nmus, 1);
24  values = zeros(nmus, 1);
25 
26  % Perform all the expensive calculations of gamma in the
27  % offline step and store the results in the detailed_data.gamma
28  % structure.
29  display(['Calculating ', num2str(nmus), ' gamma values'])
30  parfor_progress(nmus);
31  tmpModel = copy(model);
32  tmpModel.enable_error_estimator = false;
33  tmpModel.calc_residual = false;
34 
35  for j = 1:nmus
37  tmpModel.set_mu(mus(j, :));
38  timer = tic();
39  rbsim = rb_simulation(tmpModel, reduced_data);
40  rbrec = rb_reconstruction(tmpModel, detailed_data, rbsim);
41  values(j) = tmpModel.gamma(model_data, rbrec);
42  times(j) = toc(timer);
43  end
44 
45  data.mus = mus;
46  data.values = values;
47  data.times = times;
48  end
49 
50  function fun = gen_reduced_data(this, model, detailed_data, reduced_data)
51  % Build all components for the assembly of the
52  data = detailed_data.gamma;
53  ntrain = length(data.values);
54 
55  K = zeros(ntrain);
56  f = this.kernels.(this.kernel);
57  p = this.kernel_parameters;
58  mus = data.mus;
59 
60  for i = 1:ntrain
61  for j = 1:ntrain
62  K(i,j) = f(mus(i,:), mus(j,:), p);
63  end
64  end
65 
66  weights = K\data.values(1:ntrain);
67 
68  fun = @tmpFunction;
69  function g = tmpFunction(model, reduced_data, sim)
70  g = 0;
71  mu = model.get_mu();
72  for k = 1:ntrain
73  g = g + f(mu, mus(k,:), p)*weights(k);
74  end
75  end
76  end
77 
78  function gamma = calculate(model, model_data, sim)
79  error('gamma calculation through kernel is not available!')
80  end
81 
82  end
83 
84 end
BASE Basis class for the preparation and calculation of gamma Any subclass should also overwrite the...
Implementation of the parametric algebraic Riccati equation.
function percent = parfor_progress(N)
PARFOR_PROGRESS Progress monitor (progress bar) that works with parfor. PARFOR_PROGRESS works by crea...