rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
riccati_gen_reduced_data.m
Go to the documentation of this file.
1 function reduced_data = riccati_gen_reduced_data(model, detailed_data)
2 %reduced_data = riccati_gen_reduced(model, detailed_data)
3 %
4 % Build the reduced data, i.e. all matrices and components that are
5 % required for the calculation of the reduced solution and the residual
6 % norm in an online efficient manner.
7 %
8 % Andreas Schmidt, 2015
9 W = detailed_data.RB;
10 if ~isfield(detailed_data, 'RB_V');
11  V = W;
12 else
13  V = detailed_data.RB_V;
14 end
15 % 1. Project all the matrices:
16 model_data = gen_model_data(model);
17 
18 % For copying all the coefficient functions:
19 reduced_data = model_data;
20 reduced_data.RB = V;
21 
22 reduced_data.VtV = V'*V;
23 Ak = {};
24 for k = 1:length(model_data.A_components)
25  Ak{k} = W'*model_data.A_components{k}*V;
26 end
27 reduced_data.A_components = Ak;
28 reduced_data.B_components = {};
29 for k = 1:length(model_data.B_components)
30  reduced_data.B_components{k} = W'*model_data.B_components{k};
31 end
32 reduced_data.C_comp = {};
33 for k = 1:length(model_data.C_components)
34  reduced_data.C_components{k} = model_data.C_components{k}*V;
35 end
36 reduced_data.E_comp = {};
37 for k = 1:length(model_data.E_components)
38  reduced_data.E_components{k} = W'*model_data.E_components{k}*V;
39 end
40 reduced_data.x0_components = {};
41 for k = 1:length(model_data.x0_components)
42  reduced_data.x0_components{k} = W'*model_data.x0_components{k};
43 end
44 
45 % For the error estimator:
46 estim.M1 = {};
47 for i=1:length(model_data.B_components)
48  for j=1:length(model_data.B_components)
49  estim.M2{i,j} = (W'*model_data.B_components{i})*(model_data.B_components{j}'*W);
50  end
51 end
52 estim.M3 = {};
53 for i=1:length(model_data.C_components)
54  for j=1:length(model_data.C_components)
55  for k=1:length(model_data.E_components)
56  for l=1:length(model_data.E_components)
57  estim.M4{i,j,k,l} = (W'*model_data.E_components{k}*model_data.C_components{i}')*(model_data.C_components{j}*model_data.E_components{l}'*W);
58  end
59  end
60  end
61 end
62 
63 estim.M5 = {};
64 estim.M6 = {};
65 for i = 1:length(model_data.A_components)
66  for j = 1:length(model_data.C_components)
67  for k = 1:length(model_data.C_components)
68  for l = 1:length(model_data.E_components)
69  estim.M1{i,j,k,l} = W'*model_data.E_components{l}*model_data.C_components{j}'*model_data.C_components{k}*(model_data.A_components{i})'*W;
70  end
71  end
72  end
73  for j = 1:length(model_data.E_components)
74  estim.M3{i,j} = W'*model_data.E_components{j}*(model_data.A_components{i})'*W;
75  estim.M6{i,j} = estim.M3{i,j}';
76  end
77  for j = 1:length(model_data.A_components)
78  estim.M5{i,j} = W'*model_data.A_components{i}*(model_data.A_components{j}')*W;
79  end
80 
81 end
82 for i = 1:length(model_data.C_components)
83  for j = 1:length(model_data.C_components)
84  for k = 1:length(model_data.C_components)
85  for l = 1:length(model_data.C_components)
86  estim.M7{i,j,k,l} = trace(model_data.C_components{i}*model_data.C_components{j}'*model_data.C_components{k}*model_data.C_components{l}');
87  end
88  end
89  end
90 end
91 for i = 1:length(model_data.E_components)
92  for j = 1:length(model_data.E_components)
93 estim.M8{i,j} = W'*model_data.E_components{i}*(model_data.E_components{j}')*W;
94  end
95 end
96 
97 
98 % Finally the last components for the error estimator:
99 estim.normE = normest(model_data.E_components{1});
100 
101 
102 % Prepare the value for ||BB^T||
103 estim.normBBT = {};
104 estim.normBBT_use2norm = false;
105 if length(model_data.B_components) == 1
106  estim.normBBT = normest(model_data.B_components{1});
107  estim.normBBT_use2norm = true;
108 else
109  for i = 1:length(model_data.B_components)
110  for j = 1:length(model_data.B_components)
111  for k = 1:length(model_data.B_components)
112  for l = 1:length(model_data.B_components)
113  estim.normBBT{i,j,k,l} = trace(model_data.B_components{k}'*model_data.B_components{l});
114  end
115  end
116  end
117  end
118 end
119 
120 % Gamma:
121 if isfield(detailed_data,'gamma')
122  estim.gamma = detailed_data.gamma;
123 
124  if strcmp(estim.gamma.mode, 'kernel_interpolation')
125  % Build the kernel weights
126  mus = estim.gamma.interpol_mus;
127  gammas = estim.gamma.interpol_gammas;
128  k = riccati_kernel_functions(model, estim.gamma.kernel);
129  % Calculate the alphas:
130  K = zeros(length(gammas));
131  for i = 1:length(gammas)
132  for j = 1:length(gammas)
133  K(i,j) = k(mus(i,:),mus(j,:));
134  end
135  end
136 
137  estim.gamma.alpha = K\gammas;
138  elseif strcmp(estim.gamma.mode, 'exponential_bound')
139  if length(model_data.E_components) > 1
140  error('Only one component in E is currently supported!');
141  end
142 
143  % NOTE: This is a workaround for a real strange and nasty "bug" in
144  % Matlabs svds function:
145  converged = false;
146  while ~converged
147  estim.normEInv = 1/svds(model_data.E_components{1},1,0);
148 
149  if ~isempty(estim.normEInv)
150  converged = true;
151  end
152  end
153  end
154 end
155 
156 reduced_data.estim = estim;
function reduced_data = riccati_gen_reduced_data(model, detailed_data)
reduced_data = riccati_gen_reduced(model, detailed_data)