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
LinspaceSelector.m
Go to the documentation of this file.
1 namespace data{
2 namespace selection{
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 data.selection.ASelector {
50  public: /* ( setObservable ) */
51 
52  Size = Inf;
67  MaxMemPerc = .4;
68 
69 
70  public: /* ( setObservable ) */
71 
72 
74  this.registerProps(" Size ");
75  }
76 
77 
78  function copy = clone() {
79  copy = data.selection.LinspaceSelector;
80  /* copy = clone@data.selection.ASelector(this, copy); */
81  copy.Size= this.Size;
82  }
83 
84 
85 
86 #if 0 //mtoc++: 'set.Size'
87 function Size(value) {
88  if ~isposintscalar(value) && ~isinf(value)
89  error(" The value must be a positive integer. ");
90  end
91  this.Size= value;
92  }
93 
94 #endif
95 
96 
97  protected: /* ( Sealed ) */ /* ( setObservable ) */
98 
99  function [matrixxi , rowvecti , matrixmui , matrixfxi ] = select(models.BaseFullModel model) {
100 
101  md = model.Data;
102  td = md.TrajectoryData;
103  hasfxi = false;
104  if ~isempty(md.TrajectoryFxiData) && td.getNumTrajectories == md.TrajectoryFxiData.getNumTrajectories
105  hasfxi = true;
106  end
107  nt = td.getNumTrajectories;
108 
109  /* The trajectory length */
110  tl = length(model.Times);
111  /* The total size of all trajectories
112  * If nonuniform data is allowed, we need to iterate over all
113  * data in order to determine the different lengths */
114  if isa(td," data.FileTrajectoryData ") && ~td.UniformTrajectories
115  sizes = zeros(1,nt);
116  pi = ProcessIndicator(" Possibly non-uniform trajectories. Gathering %d trajectory sizes ",nt,false,nt);
117  for n = 1:nt
118  x = td.getTrajectoryNr(n);
119  sizes(n) = size(x,2);
120  pi.step;
121  end
122  pi.stop;
123  else
124  sizes = ones(1,nt) * tl;
125  end
126 
127  linpos = [1 cumsum(sizes)];
128  ts = linpos(end);
129 
130  /* Select maximal as many as are there! */
131  s = min(this.Size,ts);
132  idx = round(linspace(1,ts,s));
133 
134  [xd, mud] = td.getTrajectoryDoFs;
135  /* Use 512 MB chunks for approx train data */
136  xi = data.FileMatrix(xd,s," Dir ",md.DataDirectory);
137  ti = zeros(1,s);
138  mui = zeros(mud,s);
139  fxi = [];
140  if hasfxi
141  fxi = data.FileMatrix(xd,s," Dir ",md.DataDirectory);
142  end
143 
144  pi = ProcessIndicator(" Selecting %d approximation training data samples from %d trajectories ",nt,false,this.Size,nt);
145  atdpos = 0;
146  for k=1:nt
147  sel = idx(idx >= linpos(k) & idx < linpos(k+1));
148  if ~isempty(sel)
149  sel = sel - min(sel) + 1;
150  [x, mu] = td.getTrajectoryNr(k);
151  atdpos = atdpos(end) + (1:length(sel));
152  xi(:,atdpos) = x(:,sel);
153  ti(atdpos) = model.Times(sel);
154  mui(:,atdpos) = repmat(mu,1,length(atdpos));
155 
156  if hasfxi
157  [fx, fxmu] = md.TrajectoryFxiData.getTrajectoryNr(k);
158  if ~isequal(mu,fxmu)
159  hasfxi = false;
160  else
161  fxi(:,atdpos) = fx(:,sel);/* #ok */
162 
163  end
164  end
165  end
166  pi.step;
167  end
168  pi.stop;
169  }
195  public: /* ( Static ) */ /* ( setObservable ) */
196 
197  static function res = test_LinSpaceSelector() {
198  [res, m] = models.burgers.Tests.testBurgers_DEIM_versions(50,2);
199  m.Approx.TrainDataSelector= data.selection.LinspaceSelector;
200  m.Approx.TrainDataSelector.Size= 300;
201  m.off4_genApproximationTrainData;
202  m.ComputeTrajectoryFxiData= true;
203  m.off2_genTrainingData;
204  m.off4_genApproximationTrainData;
205  res = res & true;
206  }
207 
213 };
214 }
215 }
216 
217 
218 
Size
The (maximum) number of elements to take.
Base interface for any approximation training data selection algorithm.
Definition: ASelector.m:19
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
Times
Evaluation points of the model.
Definition: BaseModel.m:206
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
function [ matrix xi , rowvec ti , matrix mui , matrix fxi ] = select(models.BaseFullModel model)
Selects Size equally (index-)spaced samples from the training data.
An integer value.
virtual function n = getNumTrajectories()
Gets the total number of trajectories.
data.ModelData Data
The full model's data container. Defaults to an empty container.
static function res = test_LinSpaceSelector()
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
ProcessIndicator: A simple class that indicates process either via waitbar or text output...
data.ATrajectoryData TrajectoryData
The trajectory training data for the full model (only complete trajectories!)
Definition: ModelData.m:63
Selects Size equally spaced samples from the training data.