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
WH10Experiment.m
Go to the documentation of this file.
1 namespace models{
2 namespace wh10{
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 
20  :public models.BaseFullModel {
29  public: /* ( setObservable ) */
30 
31  dim;
44  public: /* ( setObservable ) */
45 
46 
48  this.registerProps(" dim ");
49 
50  this.dim= dims;
51 
52  this.Sampler= [];/* sampling.GridSampler; */
53 
54 
55  /* This class implements a fake Approx subclass to allow access
56  * to the this.Ma property for the error estimator. */
57  this.Approx= [];
58 
59  /* s = solvers.MLWrapper(@ode45); */
60  s = solvers.ExplEuler;
61  s.MaxStep= [];
62  /* s = solvers.Heun; */
63  this.ODESolver= s;
64 
65  /* % System settings */
66  this.System= models.wh10.WH10System(this);
67  this.System.MaxTimestep= this.dt;
68  }
69 
70 
71  public: /* ( Static ) */ /* ( setObservable ) */
72 
73 
74  static function res = test_WH10_RunExperiments() {
75  models.wh10.WH10Experiment.Experiment1(100);
76  /* These are not updated to new - might do some time or not
77  *models.wh10.WH10Experiment.Experiment2(d);
78  *models.wh10.WH10Experiment.Experiment3(d);
79  *models.wh10.WH10Experiment.Experiment4(d); */
80  res = true;
81  }
82 
83 
84  static function [d , rmodels ] = Experiment1(dim,dir) {
85  if nargin < 2
86  dir = KerMor.App.TempDirectory;
87  if nargin < 1
88  dim = 240000;
89  end
90  end
91  m = models.wh10.WH10Experiment(dim);
92 
93  m.T= 20;
94  m.dt= 0.05;
95  s = m.System;
96  f = s.f.Expansion;
97  f.Ma= repmat(-exp(-f.Centers.xi(1,:)/15),dim,1);
98 
99  s.x0= dscomponents.ConstInitialValue(ones(dim,1));
100 
101  /* Commented out some inputs to speed up simulations when in
102  * test_ mode.
103  *s.Inputs{1} = @(t).4*exp(-t/4); % alter input */
104  s.Inputs[1] = @(t).04*sin(t/3);
105  s.Inputs[2] = @(t)exp(-abs(10-t/2)); /* Gutes Beispiel!
106  * s.Inputs{3} = @(t).5*exp(-(12-t).^2); % Sehr interessante dynamik
107  * s.Inputs{4} = @(t)(t>10)*.1; % okay, aber nicht so spannend */
108 
109  s.B= dscomponents.LinearInputConv(ones(m.dim,1));
110  m.DefaultInput= 1;
111 
112  /* % No training necessary! */
113  m.TrainingInputs= [];
114 
115  s.C= dscomponents.LinearOutputConv(ones(1,m.dim)/m.dim);
116 
117  V = ones(dim,1)/sqrt(dim);
118  sr = spacereduction.ManualReduction(V,V);
119  sr = spacereduction.RotationDecorator(sr);
120  sr.Dims= 100;
121  m.SpaceReducer= sr;
122 
123  d = EstimatorAnalyzer;
124  d.EstimatorIterations= [1 2 5];
125  d.EstimatorVersions= [1 1 0 0 1 0 0 1 1];
126 
127  /* degs = [.0005 .005 .05 .5]; */
128  degs = .0005;
129  rmodels = [];
130 
131  pm = PlotManager;
132  pm.AutoTickMarks= false;
133  pm.UseFileTypeFolders= false;
134  pm.NoTitlesOnSave= true;
135 
136  /* % Create estimation plots */
137  for didx = 1:length(degs)
138  sr.Degree= degs(didx);
139  d.setModel(m);
140 
141  rmodels[didx] = d.ReducedModel;/* #ok<*AGROW> */
142 
143 
144  for idx=1:s.InputCount
145  m.Name= sprintf(" \\theta=%.4f ",sr.Degree);
146  [errs, relerrs, ctimes] = d.compute([],idx);
147  d.createPlots(errs, relerrs, ctimes, pm);
148 
149  md = d.ModelData(end);
150  /* 1 = full, 7 = LSLE TD */
151  absmax = 30*abs(md.ErrT(7)-md.ErrT(1));
152  relmax = 30*abs(md.RelErrT(7)-md.RelErrT(1));
153 
154  axis(gca(1),[0 m.T md.MinErr*.9 min(1e4,absmax)]);
155  axis(gca(2),[0 m.T md.MinRelErr*.9 min(1,relmax)]);
156  set(gca(3)," XScale "," log ");
157 
158  pm.FilePrefix= sprintf(" WH10_in%d_deg%f ",idx,sr.Degree);
159  /* pm.savePlots(dir,'Format','eps','Close',true); */
160  end
161  end
162 
163  /* % Create output error plot for u3 and theta=0.05 */
164  ma = ModelAnalyzer(rmodels[3]);
165  ma.SingleFigures= true;
166  d.ReducedModel.ErrorEstimator= d.Est(7).Estimator;
167  ma.analyzeError([],3,pm);
168  pm.FilePrefix= " WH10_in3_deg05 ";
169  /* pm.savePlots(dir,'Format','eps','Close',true,'Selection',3); */
170 
171  /* % Table stuff */
172  range = 1:4:13;
173  sort = [range (range)+1 (range)+2 (range)+3];
174  d.createStatsTables(sort);
175  }
189  static function d = Experiment4(dim) {
190 
191  if nargin < 1
192  dim = 240000;
193  end
194  m = WH10Experiment(dim);
195 
196  m.T= 20;
197  m.dt= 0.05;
198 
199  s = spacereduction.PODReducer;
200  s.Mode= " abs ";
201  s.Value= 4;
202  s.UseSVDS= dim > 10000;
203  s = spacereduction.RotationDecorator(s);
204  s.Degree= .01;
205  s.Dims= 5;
206  m.SpaceReducer= s;
207 
208  s = m.System;
209  f = s.f.Expansion;
210  s.x0= dscomponents.ConstInitialValue(ones(dim,1));
211  f.Ma= repmat(-exp(-f.Centers.xi(1,:)/15),dim,1);
212 
213  m.System.Inputs[1] = @(t).2*sin(t);
214  /* B = rnd.rand(m.dim,1); */
215  B = linspace(0,1,m.dim)^t;
216  m.System.B= dscomponents.LinearInputConv(B);
217  m.DefaultInput= 1;
218  m.TrainingInputs= 1;
219 
220  m.Name= " Sinus input, mean output mapping, larger error ";
221  m.System.C= dscomponents.LinearOutputConv(ones(1,m.dim)/m.dim);
222 
223  d = EstimatorAnalyzer;
224  d.EstimatorIterations= [1 2 5];
225  d.EstimatorVersions= [1 0 0 1 0 0 1 1];
226  d.SingleFigures= true;
227  d.setModel(m);
228  d.start([],1);
229 
230  f = d.Figures[1];
231  a = gca(f);
232  axis(a,[0 m.T 0 10]);
233  set(legend(a)," Location "," NorthEast ");
234  Utils.saveFigure(f," WH10_e1_errors "," fig ");
235  title(a,);
236  Utils.saveFigure(f," WH10_e1_errors ");
237  close(f);
238 
239  f = d.Figures[2]; a = gca(f);
240  axis(a,[0 m.T 5e-5 1]);
241  set(legend(a)," Location "," NorthEast ");
242  Utils.saveFigure(f," WH10_e1_relerrors "," fig ");
243  title(a,);
244  Utils.saveFigure(f," WH10_e1_relerrors ");
245  close(f);
246 
247  f = d.Figures[3]; a = gca(f);
248  Utils.saveFigure(f," WH10_e1_ctimes "," fig ");
249  title(a,);
250  Utils.saveFigure(f," WH10_e1_ctimes ");
251  close(f);
252  }
253 
254 
255  static function d = Experiment2(dim) {
256  if nargin < 1
257  dim = 240000;
258  end
259  m = WH10Experiment(dim);
260 
261  m.T= 20;
262  m.dt= 0.05;
263 
264  f = m.System.f;
265  f.x0= @(mu)ones(dim,1);
266  f.Ma= repmat(-exp(-f.Centers.xi(1,:)/15),dim,1);
267 
268  /* m.System.Inputs{1} = @(t).4*exp(-t/4); % alter input */
269  m.System.Inputs[1] = @(t).04*sin(t/3);
270  m.System.Inputs[2] = @(t)exp(-abs(10-t/2)); /* Gutes Beispiel! */
271 
272  m.System.Inputs[3] = @(t)exp(-(10-t).^2); /* Sehr interessante dynamik */
273 
274  m.System.Inputs[4] = @(t)(t>10)*.1; /* okay, aber nicht so spannend */
275 
276  m.System.B= dscomponents.LinearInputConv(ones(m.dim,1));
277 
278  m.TrainingInputs= 1:4;
279 
280  m.System.C= dscomponents.LinearOutputConv(ones(1,m.dim)/m.dim);
281 
282  s = spacereduction.PODReducer;
283  s.Value= 4;
284  s.Mode= " abs ";
285  s.UseSVDS= dim > 10000;
286  m.SpaceReducer= s;
287 
288  d = EstimatorAnalyzer;
289  d.EstimatorIterations= [1 2 5];
290  d.EstimatorVersions= [1 1 0 0 1 0 0 1 1];
291  d.SingleFigures= true;
292  d.setModel(m);
293 
294  for idx=1:m.System.InputCount
295  m.Name= " POD4in ";
296  d.start([],idx);
297 
298  md = d.ModelData(end);
299  /* 1 = full, 7 = LSLE TD */
300  absmax = 30*abs(md.ErrT(7)-md.ErrT(1));
301  relmax = 30*abs(md.RelErrT(7)-md.RelErrT(1));
302 
303  f = d.Figures[1];
304  a = gca(f);
305  axis(a,[0 m.T md.ErrT(1)*.9 min(1e4,absmax)]);
306  set(legend(a)," Location "," NorthEast ");
307  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_errors ",idx)," fig ");
308  title(a,);
309  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_errors ",idx));
310 
311  f = d.Figures[2]; a = gca(f);
312  axis(a,[0 m.T md.RelErrT(1)*.9 min(1,relmax)]);
313  set(legend(a)," Location "," NorthEast ");
314  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_relerr ",idx)," fig ");
315  title(a,);
316  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_relerr ",idx));
317 
318  f = d.Figures[3]; a = gca(f);
319  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_ctimes ",idx)," fig ");
320  title(a,);
321  Utils.saveFigure(f,sprintf(" WH10_POD4_in%d_ctimes ",idx));
322 
323  close([d.Figures[:]]);
324  end
325 
326  d.createStatsTables;
327  }
338  static function d = Experiment3(dim) {
339  rnd = RandStream(" mt19937ar "," Seed ",2564); /* 2564 */
340 
341  if nargin < 1
342  dim = 240000;
343  end
344  m = WH10Experiment(dim);
345 
346  m.T= 20;
347  m.dt= 0.05;
348 
349  s = spacereduction.PODReducer;
350  s.Mode= " abs ";
351  s.Value= 4;
352  s.UseSVDS= dim > 10000;
353  s = spacereduction.RotationDecorator(s);
354  s.Degree= .01;
355  s.Dims= 5;
356  m.SpaceReducer= s;
357 
358  f = m.System.f;
359  f.x0= @(mu)ones(dim,1);
360  n = size(f.Centers.xi,2);
361  f.Ma= -exp(-rand(dim,n));
362 
363  m.System.Inputs[1] = @(t).1*sin(t);
364  m.System.B= dscomponents.LinearInputConv(rnd.rand(m.dim,1));
365 
366  this.TrainingInputs= 1;
367 
368  m.Name= " Sinus input, mean output mapping, larger error ";
369  m.System.C= dscomponents.LinearOutputConv(ones(1,m.dim)/m.dim);
370 
371  d = EstimatorAnalyzer;
372  d.EstimatorIterations= [1 2 5];
373  d.EstimatorVersions= [1 0 0 1 0 0 1 1];
374  d.SingleFigures= true;
375  d.setModel(m);
376  d.start([],1);
377 
378 /* f = d.Figures{1};
379  * a = gca(f);
380  * axis(a,[0 m.T 1e-5 1e4]);
381  * set(legend(a),'Location','NorthEast');
382  * Utils.saveFigure(f,'WH10_e3_errors','fig');
383  * title(a,'');
384  * Utils.saveFigure(f,'WH10_e3_errors');
385  * close(f);
386  *
387  * f = d.Figures{2}; a = gca(f);
388  * axis(a,[0 m.T 1e-5 1]);
389  * set(legend(a),'Location','SouthWest');
390  * Utils.saveFigure(f,'WH10_e3_relerrors','fig');
391  * title(a,'');
392  * Utils.saveFigure(f,'WH10_e3_relerrors');
393  * close(f);
394  *
395  * f = d.Figures{3}; a = gca(f);
396  * Utils.saveFigure(f,'WH10_e3_ctimes','fig');
397  * title(a,'');
398  * Utils.saveFigure(f,'WH10_e3_ctimes');
399  * close(f); */
400  }
412 };
413 }
414 }
415 
416 
417 
ModelAnalyzer: Analysis tools for reduced models and approximations.
Definition: ModelAnalyzer.m:17
Collection of generally useful functions.
Definition: Utils.m:17
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
double dt
The desired time-stepsize for simulations.
Definition: BaseModel.m:291
integer TrainingInputs
The indices of inputs to use for training data generation. Uses the DefaultInput if not set (and Defa...
sampling.BaseSampler Sampler
The sampling strategy the Model uses.
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
Definition: BaseModel.m:102
static function d = Experiment2(dim)
Experiment with POD reduction and training with all 4 inputs!
static function d = Experiment4(dim)
sort
ort the handle objects in any array in ascending or descending order.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
PlotManager: Small class that allows the same plots generated by some script to be either organized a...
Definition: PlotManager.m:17
rowvec EstimatorIterations
How many estimator iterations should be performed?
static function d = Experiment3(dim)
Experiment with truly random component-wise functions.
solvers.BaseSolver ODESolver
The solver to use for the ODE. Must be an instance of any solvers.BaseSolver subclass.
Definition: BaseModel.m:315
static function [ d , rmodels ] = Experiment1(dim, dir)
Experiment with manual reduction and rotation as error source.
static function saveFigure(fig, filename, ext)
Opens a matlab save dialog and saves the given figure to the file selected.
Definition: Utils.m:324
approx.BaseApprox Approx
The approximation method for the CoreFunction.
Analysis class for the error estimators.
rowvec< integer > AutoTickMarks
An integer number to enforce a minimum number of tickmarks on the respective axes.
Definition: PlotManager.m:236
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
Numerical experiments class for Paper WH10.
dim
The system's dimension.
double MaxTimestep
The maximum timestep allowed for any ODE solvers.
static function res = test_WH10_RunExperiments()