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
MemoryTrajectoryData.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 
19  :public data.ATrajectoryData {
46  public:
47 
89  private:
90 
91  hm;
99  ctimes;
100 
101 
102  public:
103 
104 
106  if ~usejava(" jvm ")
107  error(" MemoryTrajectoryData cannot be used as java is not enabled. ");
108  end
109  this.hm= java.util.HashMap;
110  this.clearTrajectories;
111  }
112 
113 
114  function [colvec<double>x , doublectime ] = getTrajectory(colvec<double> mu,integer inputidx) {
115 
116  if nargin < 3
117  inputidx = [];
118  if nargin < 2
119  mu = [];
120  end
121  end
122 
123  x = []; ctime = Inf;
124  key = Utils.getHash([mu; inputidx]);
125  if this.hm.containsKey(key)
126  idx = this.hm.get(key);
127  x = this.TrajectoryData(:,:,idx);
128  ctime = this.ctimes(idx);
129  end
130  }
145  function n = getNumTrajectories() {
146  n = size(this.TrajectoryData,3);
147  }
148 
149 
150  function l = getTotalLength() {
151  l = size(this.TrajectoryData,2);
152  }
153 
154 
155  function [colvec<double>x , colvec<double>mu , integerinputidx , doublectime ] = getTrajectoryNr(nr) {
156  if nr > size(this.TrajectoryData,3) || nr < 1
157  error(" Invalid trajectory number: %d ",nr);
158  end
159  x = this.TrajectoryData(:,:,nr);
160  mu = [];
161  if ~isempty(this.Parameters)
162  mu = this.Parameters(:,nr);
163  end
164  inputidx = [];
165  if ~isempty(this.InputIndices)
166  inputidx = this.InputIndices(nr);
167  end
168  ctime = this.ctimes(nr);
169  }
178  function addTrajectory(colvec<double> x,colvec<double> mu,integer inputidx,double ctime) {
179 
180  if nargin < 4
181  inputidx = [];
182  if nargin < 3
183  mu = [];
184  end
185  end
186 
187  if isempty(inputidx) && ~isempty(this.InputIndices)
188  error(" MemoryTrajectoryData can only hold TrajectoryData of one type. Having InputIndices and not at the same time is not allowed. ");
189  end
190  if isempty(mu) && ~isempty(this.Parameters)
191  error(" MemoryTrajectoryData can only hold TrajectoryData of one type. Having parameters and not at the same time is not allowed. ");
192  end
193  if ~isempty(this.TrajectoryData) && (size(x,1) ~= size(this.TrajectoryData,1) || size(x,2) ~= size(this.TrajectoryData,2))
194  error(" New trajectory size mismatches the size of already stored TrajectoryData. ");
195  end
196 
197  key = Utils.getHash([mu; inputidx]);
198  if this.hm.containsKey(key)
199  warning(" KerMor:MemoryTrajectoryData "," Trajectory already present. Replacing ");
200  this.TrajectoryData(:,:,this.hm.get(key)) = x;
201  else
202  this.TrajectoryData(:,:,end+1) = x;
203  if ~isempty(mu)
204  this.Parameters(:,end+1) = mu;
205  end
206  if ~isempty(inputidx)
207  this.InputIndices(end+1) = inputidx;
208  end
209  idx = size(this.TrajectoryData,3);
210  this.hm.put(key,idx);
211  this.ctimes(idx) = ctime;
212  end
213  }
225  function clearTrajectories() {
226  this.TrajectoryData= double.empty(0,0,0);
227  this.Parameters= double.empty(0,0);
228  this.InputIndices= [];
229  this.hm.clear;
230  this.ctimes= [];
231  }
232 
233 
234  function [colvec<double>x , X ] = getBoundingBox() {
235  [x, X] = Utils.getBoundingBox(this.TrajectoryData(:,:));
236  }
237 
238 
239  function [d , mud ] = getTrajectoryDoFs() {
240  d = size(this.TrajectoryData,1);
241  mud = size(this.Parameters,1);
242  }
243 
244 
245  function [n , m ] = size(dim) {
246  td = this.TrajectoryData;
247  n = [size(td,1) size(td,2)*size(td,3)];
248  if nargin == 2
249  if dim > 0 && dim < 3
250  n = n(dim);
251  else
252  n = 0;
253  end
254  elseif nargout == 2
255  m = n(2);
256  n = n(1);
257  end
258  }
267  function n = getNumBlocks() {
268  n = 1;
269  }
270 
271 
272  function B = getBlock(unused1) {
273  B = reshape(this.TrajectoryData,this.getTrajectoryDoFs,[]);
274  }
275 
276 
277  public: /* ( Static ) */
278 
279  static function res = test_MemoryTrajectoryData() {
280 
281  m = data.MemoryTrajectoryData;
282 
283  T = 10;
284  res = true;
285  for i=1:T;
286  tr(:,:,i) = rand(30,50);/* #ok */
287 
288  p(:,i) = rand(4,1);/* #ok */
289 
290  in(i) = i;/* #ok */
291 
292  end
293 
294  /* Params only */
295  for i=1:T;
296  m.addTrajectory(tr(:,:,i),p(:,i),[],1);
297  end
298  res = res && m.getNumTrajectories == T;
299 
300  for i=1:T;
301  [x, pi] = m.getTrajectoryNr(i);
302  res = res && isequal(x,tr(:,:,i)) && isequal(p(:,i),pi);
303  x = m.getTrajectory(p(:,i),[]);
304  res = res && isequal(x,tr(:,:,i));
305  end
306  m.clearTrajectories;
307 
308  /* Inputs only */
309  for i=1:T;
310  m.addTrajectory(tr(:,:,i),[],in(i),1);
311  end
312  res = res && m.getNumTrajectories == T;
313 
314  for i=1:T;
315  [x, ~, ini] = m.getTrajectoryNr(i);
316  res = res && isequal(x,tr(:,:,i)) && isequal(ini,in(i));
317  x = m.getTrajectory([],in(i));
318  res = res && isequal(x,tr(:,:,i));
319  end
320  m.clearTrajectories;
321 
322  /* both */
323  for i=1:T;
324  m.addTrajectory(tr(:,:,i),p(:,i),in(i),1);
325  end
326  res = res && m.getNumTrajectories == T;
327 
328  [U,S] = m.getSVD;/* #ok */
329 
330 
331  for i=1:T;
332  [x, pi, ini] = m.getTrajectoryNr(i);
333  res = res && isequal(x,tr(:,:,i)) && isequal(ini,in(i)) && isequal(p(:,i),pi);
334  x = m.getTrajectory(p(:,i),in(i));
335  res = res && isequal(x,tr(:,:,i));
336  end
337  m.clearTrajectories;
338  }
339 
340 
341 };
342 }
343 
344 
345 
function l = getTotalLength()
Length of the stored trajectories.
Collection of generally useful functions.
Definition: Utils.m:17
function [ colvec< double > x , X ] = getBoundingBox()
Gets the bounding box of the state space of all trajectories.
function addTrajectory(colvec< double > x,colvec< double > mu,integer inputidx,double ctime)
Adds a trajectory to the ModelData instance.
function B = getBlock(unused1)
function [ colvec< double > x , colvec< double > mu , integer inputidx , double ctime ] = getTrajectoryNr(nr)
Gets the trajectory with the number nr.
function n = getNumTrajectories()
Gets the total number of trajectories.
reshape
hanges the dimensions of the handle object array to the specified dimensions. See the MATLAB reshape ...
An integer value.
TrajectoryData
The trajectories in a dim x timelength x trajectorynumber array.
Data class that contains a model's large data, purely in system memory.
function clearTrajectories()
Clears all stored trajectory data.
function [ colvec< double > x , double ctime ] = getTrajectory(colvec< double > mu,integer inputidx)
Gets a system's trajectory for the given and inputindex. Returns [] if no trajectory is found in the...
function [ d , mud ] = getTrajectoryDoFs()
Returns the degrees of freedom for the trajectories and parameter size.
static function h = getHash(vec)
Returns a hash code for the given vector.
Definition: Utils.m:493
#define X(i, j)
function n = getNumBlocks()
% data.ABlockedData implementations
function [ n , m ] = size(dim)
% data.ABlockedData implementations
Data class that contains a model's large data, including subspace matrices, trajectories and approxim...
static function res = test_MemoryTrajectoryData()
Parameters
The parameters associated with the trajectories. Each column index corresponds to the trajectory numb...
static function [ double bmin , double bmax ] = getBoundingBox(double vectors)
Gets the bounding box for a matrix containing column vectors.
Definition: Utils.m:96
InputIndices
The input indices associated with the trajectories. Each column index corresponds to the trajectory n...