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
ModelData.m
Go to the documentation of this file.
1 namespace data{
2 
3 
4 /* (Autoinserted by mtoc++)
5  * This source code has been filtered by the mtoc++ executable,
6  * which generates code that can be processed by the doxygen documentation tool.
7  *
8  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
9  * Except for the comments, the function bodies of your M-file functions are untouched.
10  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
11  * attached source files that are highly readable by humans.
12  *
13  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
14  * the correct locations in the source code browser.
15  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
16  */
17 
18 class ModelData
19  :public data.FileData {
40  private: /* ( Constant ) */
41 
42  static const FileTrajectoryDataFolder = "trajectories";
43 
44  static const FileTrajectoryIncompleteDataFolder = "trajectories_incomplete";
45 
46  static const FileTrajectoryFxiDataFolder = "trajectories_fx";
47 
48  static const SimCacheDataFolder = "simcache";
49 
50 
51  public:
52 
160  public:
161 
163 
164 
165  public: /* ( Dependent ) */
166 
178  public: /* ( Dependent ) */
179 
181  if isempty(varargin)
182  data_dir = fullfile(KerMor.App.TempDirectory,sprintf(" temp_md_%s ",...
184  elseif isa(varargin[1]," models.BaseFullModel ")
185  m = varargin[1];
186  basedir = KerMor.App.DataDirectory;
187  if length(varargin) > 1 && ischar(varargin[2])
188  basedir = varargin[2];
189  end
190  data_dir = fullfile(basedir,sprintf(" %s_id-%s ",m.SaveTag,m.ID));
191  elseif ischar(varargin[1])
192  data_dir = varargin[1];
193  else
194  error(" Invalid argument: %s ",class(varargin[1]));
195  end
196  this = this@data.FileData(data_dir);
197  /* Init with default memory data storages */
198  this.TrajectoryData= data.MemoryTrajectoryData;
199  this.TrajectoryIncompleteData= data.MemoryTrajectoryData;
200  this.TrajectoryFxiData= data.MemoryTrajectoryData;
201 
202  /* % Sim cache is FileTrajectoryData by default */
203  this.SimCache= data.FileTrajectoryData(fullfile(data_dir,this.SimCacheDataFolder));
204  /* Dont force uniform trajectory lengths for simulation cache */
205  this.SimCache.UniformTrajectories= false;
206  }
224  function addProjectionSpace(V,W,dims) {
225  if ~isa(V," data.FileMatrix ")
226  V = data.FileMatrix(V," Dir ",this.DataDirectory);
227  end
228  if ~isempty(W) && ~isa(W," data.FileMatrix ")
229  W = data.FileMatrix(W," Dir ",this.DataDirectory);
230  end
231  s = data.ProjectionSpace(V,W,dims);
232  if isempty(this.ProjectionSpaces)
233  this.ProjectionSpaces= s;
234  else
235  this.ProjectionSpaces(end+1) = s;
236  end
237  }
245  function matrix<double>mu = getParams(rowvec<int32> idx) {
246  mu = [];
247  if ~isempty(idx) && all(idx > 0) && all(idx < size(this.ParamSamples,2)+1)
248  mu = this.ParamSamples(:,idx);
249  else
250  /* warning('models:ModelData','No parameter found for idx %d',idx); */
251  end
252  }
264  function idx = getSampleIndex(colvec<double> mu) {
265  idx = [];
266  for n=1:this.SampleCount
267  if all(abs(this.ParamSamples(:,n) - mu) < sqrt(eps))
268  idx = n;
269  return;
270  end
271  end
272  }
286  function delete() {
287  this.ProjectionSpaces= [];
288  this.SimCache= [];
289  this.TrajectoryData= [];
290  this.TrajectoryIncompleteData= [];
291  this.TrajectoryFxiData= [];
292  this.ApproxTrainData= [];
293  this.JacobianTrainData= [];
294  if ~isempty(this.JacSimTransData)
295  this.JacSimTransData.VFull= [];
296  end
297  delete@data.FileData(this);
298  }
299 
300 
301  function relocate(char new_dir) {
302  if nargin < 2
303  new_dir = Utils.getDir(" Please specify the directory ",KerMor.App.DataDirectory);
304  if new_dir == 0
305  fprintf(2," No directory selected. Aborting.\n ");
306  return;
307  end
308  end
309 
310  if ~isempty(this.TrajectoryData) && isa(this.TrajectoryData," data.FileData ")
311  this.TrajectoryData.relocate(...
312  fullfile(new_dir,this.FileTrajectoryDataFolder));
313  end
314  if ~isempty(this.TrajectoryIncompleteData) && isa(this.TrajectoryIncompleteData," data.FileData ")
315  this.TrajectoryIncompleteData.relocate(...
316  fullfile(new_dir,this.FileTrajectoryIncompleteDataFolder));
317  end
318  if ~isempty(this.TrajectoryFxiData) && isa(this.TrajectoryFxiData," data.FileData ")
319  this.TrajectoryFxiData.relocate(...
320  fullfile(new_dir,this.FileTrajectoryFxiDataFolder));
321  end
322  if ~isempty(this.SimCache) && isa(this.SimCache," data.FileData ")
323  this.SimCache.relocate(...
324  fullfile(new_dir,this.SimCacheDataFolder));
325  end
326  if ~isempty(this.ApproxTrainData)
327  this.ApproxTrainData.relocate(new_dir);
328  end
329  if ~isempty(this.JacobianTrainData)
330  this.JacobianTrainData.relocate(new_dir);
331  end
332  if ~isempty(this.ProjectionSpaces)
333  for k=1:length(this.ProjectionSpaces)
334  this.ProjectionSpaces(k).relocate(new_dir);
335  end
336  end
337  relocate@data.FileData(this, new_dir);
338  }
349  function useFileTrajectoryData(logical overwrite) {
350  if nargin < 2
351  overwrite = false;
352  end
353 
354  /* complete trajectories */
355  if ~overwrite && isa(this.TrajectoryData," data.FileTrajectoryData ")
356  error(" TrajectoryData already is a data.FileTrajectoryData. Use 'true' parameter to overwrite. ");
357  end
358  old = this.TrajectoryData;
359  this.TrajectoryData= [];
360  this.TrajectoryData= data.FileTrajectoryData(...
361  fullfile(this.DataDirectory,this.FileTrajectoryDataFolder));
362  /* Copy existing data */
363  this.TrajectoryData.transferFrom(old);
364 
365  /* incomplete trajectories */
366  if ~overwrite && isa(this.TrajectoryIncompleteData," data.FileTrajectoryData ")
367  error(" TrajectoryIncompleteData already is a data.FileTrajectoryData. Use 'true' parameter to overwrite. ");
368  end
369  old = this.TrajectoryIncompleteData;
370  this.TrajectoryIncompleteData= [];
371  this.TrajectoryIncompleteData= data.FileTrajectoryData(...
372  fullfile(this.DataDirectory,this.FileTrajectoryIncompleteDataFolder));
373  /* Copy existing data */
375 
376  /* trajectory fxi data */
377  if ~overwrite && isa(this.TrajectoryFxiData," data.FileTrajectoryData ")
378  error(" TrajectoryFxiData already is a data.FileTrajectoryData. Use 'true' parameter to overwrite. ");
379  end
380  old = this.TrajectoryFxiData;
381  this.TrajectoryFxiData= [];
382  this.TrajectoryFxiData= data.FileTrajectoryData(...
383  fullfile(this.DataDirectory,this.FileTrajectoryFxiDataFolder));
384  /* Copy existing data */
385  this.TrajectoryFxiData.transferFrom(old);
386  }
400  function [doublet , matrix<double>y , colvec<double>mu , integerinputidx , ct ] = getCachedTrajectory(nr) {
401  [y, mu, inputidx, ct] = this.SimCache.getTrajectoryNr(nr);
402  t = 0:mu(2):mu(1);
403  mu = mu(3:end);
404  }
416  protected: /* ( Static ) */ /* ( Dependent ) */
417 
418  static function this = loadobj() {
419  if ~isa(this," data.ModelData ")
420  initfrom = this;
421  this = data.ModelData(initfrom.fDataDir);
422  this = loadobj@data.FileData(this,initfrom);
423  if isfield(initfrom," V ") && ~isempty(initfrom.V)
424  this.addProjectionSpace(initfrom.V,initfrom.W,size(initfrom.V,1));
425  end
426  else
427  this = loadobj@data.FileData(this);
428  end
429  if exist(this.DataDirectory," file ") == 0
430  fprintf(2," If you have moved the folder or attempt to load data on a different machine, use the ModelData.relocate method.\n ");
431  end
432  }
444  /* % Getter & Setter */
445  public: /* ( Dependent ) */
446 
447 
448 #if 0 //mtoc++: 'get.SampleCount'
449 function value = SampleCount() {
450  value = size(this.ParamSamples,2);
451  }
452 
453 #endif
454 
455 
456 
457 #if 0 //mtoc++: 'set.ApproxTrainData'
458 function ApproxTrainData(value) {
459  if ~isempty(value) && ~isa(value, " data.ApproxTrainData ")
460  error(" The ApproxTrainData must be a data.ApproxTrainData subclass. ");
461  end
462  if ~isequal(this.ApproxTrainData, value)
463  this.ApproxTrainData= [];
464  this.ApproxTrainData= value;
465  end
466  }
467 
468 #endif
469 
470 
471 
472 #if 0 //mtoc++: 'set.TrajectoryData'
473 function TrajectoryData(value) {
474  if ~isempty(value) && ~isa(value, " data.ATrajectoryData ")
475  error(" The TrajectoryData must be a data.ATrajectoryData subclass. ");
476  end
477  /* Precaution: Unset the old traj data as it may trigger deletion of the same folder
478  * that is used by the new one. */
479  if ~isequal(this.TrajectoryData,value)
480  this.TrajectoryData= [];
481  this.TrajectoryData= value;
482  end
483  }
484 
485 #endif
486 
487 
488 
489 #if 0 //mtoc++: 'set.JacobianTrainData'
490 function JacobianTrainData(value) {
491  if ~isempty(value) && ~isa(value, " data.ApproxTrainData ")
492  error(" The JacobianTrainData must be a data.ApproxTrainData subclass. ");
493  end
494  if ~isequal(this.JacobianTrainData, value)
495  this.JacobianTrainData= [];
496  this.JacobianTrainData= value;
497  end
498  }
499 
500 #endif
501 
502 
503 
504 #if 0 //mtoc++: 'set.ProjectionSpaces'
505 function ProjectionSpaces(value) {
506  if ~isempty(value) && ~isa(value," data.ProjectionSpace ")
507  error(" Value has to be a data.ProjectionSpace instance/array ");
508  end
509  this.ProjectionSpaces= value;
510  }
511 
512 #endif
513 
514 
537 };
538 }
539 
540 
541 
Collection of generally useful functions.
Definition: Utils.m:17
static function gen = generateID()
Generates a new unique ID.
Definition: IDGenerator.m:90
function useFileTrajectoryData(logical overwrite)
Sets the TrajectoryData and TrajectoryFxiData classes to filesystem based versions.
Definition: ModelData.m:349
matrix< double > InputSpaceSpan
The orthonormalized vectors spanning the space of the input components.
Definition: ModelData.m:97
A matlab matrix.
SampleCount
The number of samples contained in the model data.
Definition: ModelData.m:167
function relocate(char new_dir)
Convenience method. Relocates the xi and fxi FileMatrix instances if present.
colvec< data.ProjectionSpace > ProjectionSpaces
Array of ProjectionSpace instances that contains all the separate linear projection spaces computed d...
Definition: ModelData.m:133
matrix ParamSamples
A Model's parameter samples as column vector collection.
Definition: ModelData.m:53
function transferFrom(data.ATrajectoryData source)
Transfers the data from one ATrajectoryData instance to another.
data.FileDataCollection TrajectoryFxiData
Evaluations of the system's nonlinearity on the trajectoriy data.
Definition: ModelData.m:85
struct JacSimTransData
A struct containing precomputed values regarding the similarity transform of the jacobians in the con...
Definition: ModelData.m:148
static function this = loadobj()
Loads the ModelData with automatic relocation for different hosts.
Definition: ModelData.m:418
function relocate(char new_dir)
Relocates this ModelData instances filesystem-bound quantities to a new location. ...
Definition: ModelData.m:301
function relocate(char new_root)
Relocates this FileData instance to a different folder.
Definition: FileData.m:103
A boolean value.
A variable number of input arguments.
A matlab column vector.
function idx = getSampleIndex(colvec< double > mu)
Finds the column index of the given parameter vector within the Data's ParamSamples matrix...
Definition: ModelData.m:264
FileData: Base class for access of files stored in a specific folder in the local file system...
Definition: FileData.m:18
FileDataCollection: Basic class for storing data given a hashable key value.
function addProjectionSpace(V, W, dims)
Adds a new projection space to the model data instance.
Definition: ModelData.m:224
Speed test * all(1:3)
char DataDirectory
The root folder where the FileData's files are saved.
Definition: FileData.m:56
ModelData(varargin)
Creates a new container for large full model data.
Definition: ModelData.m:180
static function folder = getDir(caption, initial_path)
Prompts the user to select a directory.
Definition: Utils.m:669
data.ApproxTrainData JacobianTrainData
Training data for the jacobian approximation.
Definition: ModelData.m:120
Data class that contains a model's large data, including subspace matrices, trajectories and approxim...
Definition: ModelData.m:18
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
A matlab row vector.
Generates unique IDs.
Definition: IDGenerator.m:17
function matrix< double > mu = getParams(rowvec< int32 > idx)
Returns parameters for given indices.
Definition: ModelData.m:245
ApproxTrainData: Data class for approximation training data, containing several useful bounding box p...
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
A MatLab struct.
data.ApproxTrainData ApproxTrainData
Training data for the core function approximation.
Definition: ModelData.m:110
Data class that contains a model's large data, including subspace matrices, trajectories and approxim...
data.ATrajectoryData TrajectoryIncompleteData
The incomplete trajectory training data for the full model is saved separately.
Definition: ModelData.m:74
data.ATrajectoryData TrajectoryData
The trajectory training data for the full model (only complete trajectories!)
Definition: ModelData.m:63
function [ double t , matrix< double > y , colvec< double > mu , integer inputidx , ct ] = getCachedTrajectory(nr)
Shorthand for retrieval of cached trajectories that have been created during simulations of a models...
Definition: ModelData.m:400