rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Kernel.m
2 
3 
4  properties
5 
6  kernel = 'thin_plate';
7 
8  kernels = struct(...
9  'thin_plate', {@(x,y) -sqrt(norm(x-y)^2 +1)} );
10  end
11 
12 
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;
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 
51 
52  function fun = gen_reduced_data(this, model, detailed_data, reduced_data)
53  % Build all components for the assembly of the
54  data = detailed_data.gamma;
55  ntrain = length(data.values);
56 
57  K = eye(ntrain);
58  f = this.kernels.(this.kernel);
59  mus = data.mus;
60 
61  for i = 1:ntrain
62  for j = [1:i-1, i+1:ntrain]
63  K(i,j) = f(mus(i,:), mus(j,:));
64  end
65  end
66 
67  weights = K\data.values(1:ntrain);
68 
69  fun = @tmpFunction;
70  function g = tmpFunction(model, reduced_data, sim)
71  g = 0;
72  mu = model.get_mu();
73  for k = 1:ntrain
74  g = g + f(mu, mus(k,:))*weights(k);
75  end
76  end
77 
78  end
79 
80  function gamma = calculate(model, model_data, sim)
81  error('gamma calculation through kernel is not available!')
82  end
83 
84 
85  end
86 
87 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...