KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tests.m
Go to the documentation of this file.
1 namespace models{
2 namespace pcd{
3 
4 
5 /* (Autoinserted by mtoc++)
6  * This source code has been filtered by the mtoc++ executable,
7  * which generates code that can be processed by the doxygen documentation tool.
8  *
9  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
10  * Except for the comments, the function bodies of your M-file functions are untouched.
11  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
12  * attached source files that are highly readable by humans.
13  *
14  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
15  * the correct locations in the source code browser.
16  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
17  */
18 
19 class Tests {
38  public: /* ( Static ) */
39 
40 
41  static function reductionErrorAnalysis_2D(d,r,pm) {
42 
43  m = r.FullModel;
44  ma = ModelAnalyzer(r);
45  /* orders = [3 15 35 55 100]; % orders for old large 3000s model */
46  orders = [1 5 20 97 102 107 145;...
47  149 145 130 53 48 43 5];
48  errors = zeros(8,m.Data.SampleCount,length(orders));
49  ns = 100;
50  rand_errors = zeros(8,ns,length(orders));
51  details = cell(1,length(orders));
52  rand_details = details;
53  for j=1:size(orders,2)
54  fprintf(" Setting DEIM order = %d\n ",orders(1,j));
55  r.System.f.Order= orders(:,j)^t;
56  [e, details[j]] = ma.getRedErrForParamSamples;
57  errors(:,:,j) = e;
58  [params, re, rand_details[j]] = ma.getRedErrForRandomParamSamples(ns,1); /* 100 params, seed 1 */
59 
60  rand_errors(:,:,j) = re;
61  end
62  save(fullfile(d," reduction_errors.mat ")," errors "," orders "," details ");
63  save(fullfile(d," reduction_errors_randparams.mat ")," rand_errors "," orders "," params "," rand_details ");
64 
65 /* s=load(fullfile(d,'reduction_errors.mat'));
66  * sr=load(fullfile(d,'reduction_errors_randparams.mat'));
67  * sr.rand_errors = sr.errors; % fix for re-runs
68  * orders = s.orders;
69  *
70  * str = sprintf(' on %d training parameters, m=%d',size(s.errors,2),sr.orders(end));
71  * strr = sprintf(' on %d random parameters, m=%d',size(sr.rand_errors,2),sr.orders(end));
72  * directplot(s.errors,'train',str);
73  * directplot(sr.rand_errors,'random',strr);
74  * paramplot(s.errors,'train',str,m.Data.ParamSamples,7);
75  * paramplot(sr.rand_errors,'random',strr,sr.params,7);
76  * pm.done; */
77 
78 /* function directplot(errors, tag, str)
79  * h = pm.nextPlot([tag '_abs'],['Absolute Linf-L2 reduction errors' str],...
80  * 'DEIM order m','param sample nr');
81  * LogPlot.logsurf(h, orders, 1:size(errors,2), squeeze(errors(1,:,:)));
82  * h = pm.nextPlot([tag '_rel'],['Relative Linf-L2 reduction errors' str],...
83  * 'DEIM order m','param sample nr');
84  * LogPlot.logsurf(h, orders, 1:size(errors,2), squeeze(errors(2,:,:)));
85  * end
86  *
87  * function paramplot(errors, tag, str, params, orderidx)
88  * innerPlot(1,'abs');
89  * innerPlot(2,'rel');
90  * function innerPlot(pos,tag2)
91  * h = pm.nextPlot(['paramdomain_' tag '_' tag2],...
92  * ['Locations of 10% of worst ' tag2 ' errors' str],...
93  * ['param "' m.System.Params(1).Name '"'],...
94  * ['param "' m.System.Params(2).Name '"']);
95  *
96  * [v, idx] = sort(errors(pos,:,orderidx));
97  * v = log10(v);
98  * merr = min(v);
99  * range = (max(v)-merr);
100  * hold(h,'on');
101  * for k=1:length(v)
102  * if k > length(v)*.85
103  * c2 = 'blue';
104  * else
105  * c2 = 'none';
106  * end
107  * c = [(v(k)-merr)/range 1-(v(k)-merr)/range 0];
108  * plot3(h,params(1,idx(k)),params(2,idx(k)),v(k),...
109  * 'MarkerFaceColor',c,...%'Color',c,...
110  * 'MarkerEdgeColor',c2,...
111  * 'Marker','o',...
112  * 'MarkerSize',10);
113  * end
114  * view(h,21,24);
115  * hold(h,'off');
116  * end
117  * end */
118  }
130  static function m = tests_PCD_DEIM_2D(dim) {
131  m = models.pcd.PCDModel(2);
132 
133  m.T= 3000; /* [s] */
134 
135  m.dt= 5; /* [s] */
136 
137  if nargin < 1
138  dim = 150;
139  end
140  m.System.h= (m.System.Omega(1,2)-m.System.Omega(1,1))/(dim-1);
141 
142  if all([m.System.f.fDim m.System.f.xDim] < 1000)
143  m.Data.TrajectoryData= data.MemoryTrajectoryData;
144  end
145 
146  /* area */
147  m.System.Params(1).Desired = 10;
148  /* rate */
149  m.System.Params(2).Desired = 20;
150  s = sampling.GridSampler;
151  s.Spacing= " lin ";
152  m.Sampler= s;
153 
154  s = spacereduction.PODGreedy;
155  s.Eps= 1e-7;
156  m.SpaceReducer= s;
157 
158  m.Approx= approx.DEIM;
159  m.Approx.MaxOrder= 120;
160 
161  s = data.selection.LinspaceSelector;
162  s.Size= 20000;
163  m.Approx.TrainDataSelector= s;
164 
165  m.System.MaxTimestep= m.dt;
166  m.ODESolver= solvers.SemiImplicitEuler(m);
167 
168  e = error.DEIMEstimator;
169  e.JacMatDEIMMaxOrder= 80;
170  ts = data.selection.LinspaceSelector;
171  ts.Size= round(.2 * m.T * m.System.Params(1).Desired / m.dt);
172  e.TrainDataSelector= ts;
173  m.ErrorEstimator= e;
174 
175  gitbranch = KerMor.getGitBranch;
176  d = fullfile(KerMor.App.DataDirectory,sprintf(" tests_PCD_DEIM_2D_%d_%d ",m.System.Dims));
177  [~,~] = mkdir(d);
178  oldd = pwd;
179  cd(d);
180  save tests_PCD_DEIM_2D;
181  cd(oldd);
182 
183 /* t(1) = m.off1_createParamSamples;
184  * t(2) = m.off2_genTrainingData;
185  * t(3) = m.off3_computeReducedSpace;
186  * t(4) = m.off4_genApproximationTrainData;
187  * t(5) = m.off5_computeApproximation;
188  * t(6) = m.off6_prepareErrorEstimator;
189  * offline_times = t; */
190 
191  offline_times = m.offlineGenerations;
192 
193  clear s t;
194  oldd = pwd;
195  cd(d);
196  save tests_PCD_DEIM_2D;
197  cd(oldd);
198  }
214  static function m = tests_PCD_DEIM_2D_500s(dim) {
215  m = models.pcd.PCDModel(2);
216 
217  m.T= 500; /* [s] */
218 
219  m.dt= 5; /* [s] */
220 
221  if nargin < 1
222  dim = 150;
223  end
224  m.System.h= (m.System.Omega(1,2)-m.System.Omega(1,1))/(dim-1);
225 
226 /* if all([m.System.f.fDim m.System.f.xDim] < 1000)
227  * m.Data.TrajectoryData = data.MemoryTrajectoryData;
228  * end */
229 
230  s = sampling.RandomSampler;
231  s.Seed= 35178;
232  s.Samples= 200;
233  m.Sampler= s;
234 
235  m.ComputeTrajectoryFxiData= true;
236  s = spacereduction.PODGreedy;
237  s.Eps= 1e-7;
238  s.MaxSubspaceSize= 200;
239  s.MinRelImprovement= 1e-8;
240  s.IncludeTrajectoryFxiData= true; /* enable inclusion of f evaluations! */
241 
242  m.SpaceReducer= s;
243 
244  m.Approx= approx.DEIM;
245  m.Approx.MaxOrder= 250;
246 
247  s = data.selection.LinspaceSelector;
248  s.Size= 30000;
249  m.Approx.TrainDataSelector= s;
250 
251  m.System.MaxTimestep= m.dt;
252  m.ODESolver= solvers.SemiImplicitEuler(m);
253 
254  e = error.DEIMEstimator;
255  e.JacMatDEIMMaxOrder= 200;
256  e.JacSimTransMaxSize= 200;
257  ts = data.selection.LinspaceSelector;
258  ts.Size= 30000;
259  e.TrainDataSelector= ts;
260  m.ErrorEstimator= e;
261 
262  gitbranch = KerMor.getGitBranch;
263  d = fullfile(KerMor.App.DataDirectory,sprintf(" tests_PCD_DEIM_2D_%d_%d_500s ",m.System.Dims));
264  [~,~] = mkdir(d);
265  oldd = pwd;
266  cd(d);
268  cd(oldd);
269 
270 /* t(1) = m.off1_createParamSamples;
271  * t(2) = m.off2_genTrainingData;
272  * t(3) = m.off3_computeReducedSpace;
273  * t(4) = m.off4_genApproximationTrainData;
274  * t(5) = m.off5_computeApproximation;
275  * t(6) = m.off6_prepareErrorEstimator;
276  * offline_times = t; */
277 
278  offline_times = m.offlineGenerations;
279 
280  clear s t;
281  oldd = pwd;
282  cd(d);
284  cd(oldd);
285  }
297  static function m = tests_PCD_DEIM_1D(dim) {
298  m = models.pcd.PCDModel(1);
299 
300  m.T= 3000; /* [s] */
301 
302  m.dt= 5; /* [s] */
303 
304  if nargin < 1
305  dim = 25;
306  end
307  m.System.h= (m.System.Omega(2)-m.System.Omega(1))/(dim-1);
308 
309  m.Data.TrajectoryData= data.MemoryTrajectoryData;
310 
311  m.System.Params(1).Desired = 20;
312  s = sampling.GridSampler;
313  s.Spacing= " lin ";
314  m.Sampler= s;
315 
316  m.Approx= approx.DEIM;
317  m.Approx.MaxOrder= 60;
318 
319  s = data.selection.DefaultSelector;
320  /* s.Size = 15000; */
321  m.Approx.TrainDataSelector= s;
322 
323  m.System.MaxTimestep= m.dt;
324  m.ODESolver= solvers.SemiImplicitEuler(m);
325 
326  e = error.DEIMEstimator;
327  e.JacMatDEIMMaxOrder= 60;
328  ts = data.selection.LinspaceSelector;
329  ts.Size= round(.2 * m.T * m.System.Params(1).Desired / m.dt);
330  e.TrainDataSelector= ts;
331  m.ErrorEstimator= e;
332 
333  offline_times = m.offlineGenerations;
334  gitbranch = KerMor.getGitBranch;
335 
336  clear s;
337  d = fullfile(KerMor.App.DataDirectory," tests_PCD_DEIM_1D ");
338  [~,~] = mkdir(d);
339  oldd = pwd;
340  cd(d);
341  /* eval(sprintf('save tests_PCD_DEIM_1D',dim,version)); */
342  save tests_PCD_DEIM_1D;
343  cd(oldd);
344  }
345 
346 
347 
348  static function res = test_PCDModels() {
349  m = models.pcd.PCDModel(1);
350  mu = m.getRandomParam;
351  [t,y] = m.simulate(mu);
352  m.plot(t,y);
353  m = models.pcd.PCDModel(2);
354  mu = m.getRandomParam;
355  [t,y] = m.simulate(mu);
356  m.plot(t,y);
357 /* m = models.pcd.PCDModel(3);
358  * mu = m.getRandomParam;
359  * [t,y] = m.simulate(mu);
360  * m.plot(t,y); */
361  res = true;
362  }
363 
364 
365 };
366 }
367 }
368 
ModelAnalyzer: Analysis tools for reduced models and approximations.
Definition: ModelAnalyzer.m:17
static function m = tests_PCD_DEIM_1D(dim)
Definition: Tests.m:297
A MatLab cell array or matrix.
static function reductionErrorAnalysis_2D(d, r, pm)
% -------------— 2D tests -----------------— Reduction error analysis - computes the reduction erro...
Definition: Tests.m:41
static function m = tests_PCD_DEIM_2D_500s(dim)
New configuration with shorter runtime Samples are randomly distributed!
Definition: Tests.m:214
static function b = getGitBranch(dir)
Returns the current git commit in a descriptive string.
Definition: KerMor.m:1039
Speed test * all(1:3)
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
static function res = test_PCDModels()
Definition: Tests.m:348
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
static function m = tests_PCD_DEIM_2D(dim)
% Model creation functions Original setting for the large-scale reduction up to T=3000 with 200 lin-s...
Definition: Tests.m:130
Tests: Some test settings regarding the PCD model simulations.
Definition: Tests.m:19