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
AAdaptiveBase.m
Go to the documentation of this file.
1 namespace approx{
2 namespace algorithms{
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 approx.algorithms.ABase {
48  public: /* ( setObservable ) */
49 
70  double MaxRelErr = 1e-5;
85  char InitialCenter = "maxfx";
112  public:
113 
125  Used = "[]";
137  protected:
138 
140 
141 
142  public:
143 
145  this = this@approx.algorithms.ABase;
146 
147  /* Register default property changed listeners */
148  this.registerProps(" MaxExpansionSize "," MaxRelErr "," InitialCenter ");
149  }
150 
151 
152  function copy = clone(copy) {
153  copy = clone@approx.algorithms.ABase(this, copy);
154 
155  /* copy local props */
156  copy.MaxExpansionSize= this.MaxExpansionSize;
157  copy.MaxRelErr= this.MaxRelErr;
158  copy.initialidx= this.initialidx;
159  copy.InitialCenter= this.InitialCenter;
160  copy.Used= this.Used;
161  }
173  protected: /* ( Sealed ) */
174 
175  function kernels.KernelExpansionkexp = templateComputeApproximation(data.ApproxTrainData atd,data.ApproxTrainData avd) {
176 
177  /* % Checks */
178  if size(atd.xi,2) < this.MaxExpansionSize
179  warning(" AAdaptiveBase:expansionsize ",...
180  " Only %d training samples but having MaxExpansionSize=%d, changing to %d. ",...
181  size(atd.xi,2),this.MaxExpansionSize,size(atd.xi,2));
182  this.MaxExpansionSize= size(atd.xi,2);
183  end
184 
185  /* Init debug fields */
187  this.MaxErrors= zeros(nc,this.MaxExpansionSize);
188  this.MaxRelErrors= this.MaxErrors;
189  this.ValidationErrors= zeros(nc,2);
190  this.ValidationRelErrors= zeros(nc,2);
191  this.ExpansionSizes= zeros(nc,1);
192 
193  /* Compute initial center */
194  [~, this.initialidx] = this.getInitialCenter(atd);
195 
196  /* Start adaptive extension part of subclass */
197  kexp = this.startAdaptiveExtension(atd, avd);
198  }
217  /* % Convenience methods for use/override in concrete algorithms */
218  protected:
219 
220 
222  kexp.clear;
223  this.extendExpansion(kexp, atd, this.initialidx);
224  this.Used= this.initialidx;
225  }
238  kexp.Centers.xi(:,end+1) = atd.xi(:,idx);
239  if atd.hasTime
240  kexp.Centers.ti(end+1) = atd.ti(idx);
241  end
242  if atd.hasParams
243  kexp.Centers.mui(:,end+1) = atd.mui(:,idx);
244  end
245  this.Used(end+1) = idx;
246  }
262  function bool = checkStop(cnt,rel) {
263  vb = KerMor.App.Verbose;
264  bool = false;
265  if cnt == this.MaxExpansionSize
266  if vb > 1
267  fprintf(" AAdaptiveBase stopping criteria holds: Max expansion size %d reached.\n ",this.MaxExpansionSize);
268  end
269  bool = true;
270  elseif rel < this.MaxRelErr
271  if vb > 1
272  fprintf(" AAdaptiveBase stopping criteria holds: Relative error %.7e < %.7e\n ",rel,this.MaxRelErr);
273  end
274  bool = true;
275  end
276  }
290  protected: /* ( Abstract ) */
291 
302  private:
303 
304  function [colvecc , integeridx ] = getInitialCenter(data.ApproxTrainData atd) {
305 
306 
307  if strcmp(this.InitialCenter," maxfx ")
308  [~, idx] = max(this.ErrorFun(atd.fxi));
309  c = atd.xi(:,idx);
310  if atd.hasTime
311  c = [c; atd.ti(idx)];
312  end
313  if atd.hasParams
314  c = [c; atd.mui(:,idx)];
315  end
316  elseif strcmp(this.InitialCenter," center ")
317  [c, idx] = atd.getClosestToCenter;
318  elseif strcmp(this.InitialCenter," t0 ")
319  if atd.hasTime
320  idx = find(atd.ti == 0);
321  if ~isempty(idx)
322  c = [atd.xi(:,idx); zeros(1,numel(idx))];
323  if atd.hasParams
324  c = [c; atd.mui(:,idx)];
325  end
326  if numel(idx) > 1
327  [~,i] = min(sum((c-repmat(atd.Center,1,numel(idx))).^2,1));
328  c = c(:,i);
329  idx = idx(i);
330  end
331  end
332  end
333  else
334  error(" Unknown strategy: %s ",this.InitialCenter);
335  end
336  }
363  /* % Getter & Setter */
364  public:
365 
366 
367 #if 0 //mtoc++: 'set.MaxExpansionSize'
368 function MaxExpansionSize(value) {
369  if ~isposintscalar(value)
370  error(" Value must be a positive integer. ");
371  end
372  this.MaxExpansionSize= value;
373  }
374 
375 #endif
376 
377 
378 
379 #if 0 //mtoc++: 'set.MaxRelErr'
380 function MaxRelErr(value) {
381  if ~isempty(value) && ~isposrealscalar(value)
382  error(" The value must be a positive scalar ");
383  end
384  this.MaxRelErr= value;
385  }
386 
387 #endif
388 
389 
390  protected: /* ( Static ) */
391 
392  static function this = loadobj(this,initfrom) {
393  if nargin > 1
394  this.MaxExpansionSize= initfrom.MaxExpansionSize;
395  this.InitialCenter= initfrom.InitialCenter;
396  if isfield(initfrom," initialidx ")
397  this.initialidx= initfrom.initialidx;
398  end
399  if isfield(initfrom," Used ")
400  this.Used= initfrom.Used;
401  end
402  this.ExpansionSizes= initfrom.ExpansionSizes;
403  this.InitialCenter= initfrom.InitialCenter;
404  this.MaxRelErr= initfrom.MaxRelErr;
405  this = loadobj@approx.algorithms.ABase(this, initfrom);
406  end
407  }
408 
418 };
419 }
420 }
421 
422 
423 
424 
matrix< double > ValidationErrors
For each configuration, contains a row with the maximum errors on the validation data. The number of columns depends on the type of algorithm implemented by the subclasses.
Definition: ABase.m:154
logical hasParams
Flag that indicates if param samples are present.
matrix< double > MaxRelErrors
For each configuration, contains a row with the maximum relative errors on the training data...
Definition: ABase.m:139
data.FileMatrix xi
The state space samples , stored row-wise in a data.FileMatrix instance.
data.FileMatrix fxi
The evaluations of , stored row-wise in a data.FileMatrix.
char InitialCenter
Determines how the initial center(s) are chosen.
Definition: AAdaptiveBase.m:85
function [ colvec< double > c , integer idx ] = getClosestToCenter()
The sample triple closest to the Center.
A double value.
function registerProps(varargin)
Call this method at any class that defines DPCM observed properties.
Definition: DPCMObject.m:125
An integer value.
matrix< double > ValidationRelErrors
For each configuration, contains a row with the maximum relative errors on the validation data...
Definition: ABase.m:169
kernels.config.ExpansionConfig ExpConfig
The different kernel expansion configurations to try.
Definition: ABase.m:55
rowvec ti
The time samples .
function bool = checkStop(cnt, rel)
Checks the stopping conditions for the adaptive approximation algorithm.
Used
The indices of the effectively used centers during the.
function_handle ErrorFun
The error function to apply on each data vector.
Definition: ABase.m:87
function kernels.KernelExpansion kexp = templateComputeApproximation(data.ApproxTrainData atd,data.ApproxTrainData avd)
Performs adaptive approximation generation.
function copy = clone(copy)
Clones the instance.
function clear()
Removes all centers and coefficients from the expansion and leaves the associated kernels untouched...
function n = getNumConfigurations()
Returns the number of configurations that can be applied.
logical hasTime
Flag that indicates if time samples are present.
matrix mui
The parameter samples used computing the parent trajectories of .
matrix< double > MaxErrors
For each configuration, contains a row with the maximum errors on the training data. The number of columns depends on the type of algorithm implemented by the subclasses.
Definition: ABase.m:124
ABase: Base class for any approximation generation algorithms for kernel expansions,.
Definition: ABase.m:19
Base class for adaptive component-wise kernel approximation algorithms.
Definition: AAdaptiveBase.m:19
function res = isposintscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
function extendExpansion(kernels.KernelExpansion kexp,data.ApproxTrainData atd,integer idx)
Extends the kernel expansion kexp by the training data sample in atd given by index idx...
Global configuration class for all KerMor run-time settings.
Definition: KerMor.m:17
ApproxTrainData: Data class for approximation training data, containing several useful bounding box p...
struct Centers
The kernel centers used in the approximation.
static function KerMor theinstance = App()
The singleton KerMor instance.
Definition: KerMor.m:910
A MatLab character array.
double MaxRelErr
Stopping condition property. Maximum relative error that may occur.
Definition: AAdaptiveBase.m:70
function res = isposrealscalar(value)
isposintscalar: Backwards-compatibility function for matlab versions greater than 2012a ...
static function this = loadobj(this, initfrom)
function initExpansion(kernels.KernelExpansion kexp,data.ApproxTrainData atd)
Initializes the Find and set first expansion center.
virtual function startAdaptiveExtension(kernels.KernelExpansion kexp,data.ApproxTrainData atd)
Runs the actual detailed algorithm.
KernelExpansion: Base class for state-space kernel expansions.
integer MaxExpansionSize
The maximum size of the expansion to produce.
Definition: AAdaptiveBase.m:50