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
TimeSelector.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 {
58  public: /* ( setObservable ) */
59 
60  Size = 10000;
76  Seed = 1;
91  public: /* ( setObservable ) */
92 
94  this = this@data.selection.ASelector;
95  this.registerProps(" Size "," Seed ");
96  }
97 
98 
99  function copy = clone() {
100  copy = data.selection.TimeSelector;
101  /* copy = clone@data.selection.ASelector(this, copy); */
102  copy.Size= this.Size;
103  copy.Seed= this.Seed;
104  }
105 
106 
107  protected: /* ( Sealed ) */ /* ( setObservable ) */
108 
109  function [matrixxi , rowvecti , matrixmui , fxi ] = select(models.BaseFullModel model) {
110 
111  /* Build sn array similar to old one */
112  d = model.Data.TrajectoryData;
113  nt = d.getNumTrajectories;
114  times = model.Times;
115  tlen = length(times);
116 
117  if nt*tlen > this.Size
118  /* So many samples for each timestep (fill rest with random samples) */
119  num = floor(this.Size/tlen);
120  s = RandStream.create(" mt19937ar "," Seed ",this.Seed);
121  /* These are the time step indices that have to be selected overall */
122  selidx = repmat(s.randperm(tlen),1,num);
123  /* How many per trajectory?
124  * MUST be smaller than tlen, as otherwise selecting more timesteps per
125  * trajectory than available would have meant that nt*tlen < this.Size.
126  * This means also that repeating the random permutation of 1:tlen will not lead
127  * to double selection of a time within the same trajectory. */
128  protraj = floor(length(selidx)/nt);
129 
130  sel = logical.empty;
131  for tn = 1:nt
132  /* Select nothing by default */
133  hlp = false(1,tlen);
134  /* select "protraj" many sequentially */
135  step = (1:protraj)+(tn-1)*protraj;
136  /* set those to true */
137  hlp(selidx(step)) = true;
138  /* Store in selection array at range for current trajectory */
139  sel = [sel hlp]; /* #ok<*AGROW> */
140 
141  end
142 
143  /* Add up to full this.Size selection */
144  left = this.Size - protraj * nt;
145  notsel = find(~sel);
146  selsel = s.randperm(length(notsel),left);
147  sel(notsel(selsel)) = true;
148  else
149  sel = true(1,nt*tlen); /* Select everything! */
150 
151  end
152 
153  xi = []; ti = []; mui = [];
154  for tn = 1:nt
155  [x, mu] = d.getTrajectoryNr(tn);
156  idx = (1:tlen) + (tn-1)*tlen;
157  xi = [xi x(:,sel(idx))];
158  newt = times(sel(idx));
159  ti = [ti newt];
160  if ~isempty(mu)
161  mui = [mui mu(:,ones(1,length(newt)))];
162  end
163  end
164  fxi = [];
165  }
186  public: /* ( setObservable ) */
187 
188 
189 #if 0 //mtoc++: 'set.Size'
190 function Size(value) {
191  if ~isposintscalar(value)
192  error(" The value must be a finite positive integer. ");
193  end
194  this.Size= value;
195  }
196 
197 #endif
198 
199 
200 
201 #if 0 //mtoc++: 'set.Seed'
202 function Seed(value) {
203  if ~isreal(value)
204  error(" The value must be a real value. ");
205  end
206  this.Seed= value;
207  }
208 
209 #endif
210 
220 };
221 }
222 }
223 
TimeSelector: Approximation training data selection utilizing time information.
Definition: TimeSelector.m:19
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
An integer value.
A boolean value.
function copy = clone()
Definition: TimeSelector.m:99
virtual function n = getNumTrajectories()
Gets the total number of trajectories.
data.ModelData Data
The full model's data container. Defaults to an empty container.
Seed
The seed for the per-time-random selection (to enable reproduction of results)
Definition: TimeSelector.m:76
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
Size
The (maximum) size of training samples to take.
Definition: TimeSelector.m:60
function [ matrix xi , rowvec ti , matrix mui , fxi ] = select(models.BaseFullModel model)
Performs selection of samples adjusted to the apperances of different times.
Definition: TimeSelector.m:109
data.ATrajectoryData TrajectoryData
The trajectory training data for the full model (only complete trajectories!)
Definition: ModelData.m:63