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
GridSampler.m
Go to the documentation of this file.
1 namespace sampling{
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 sampling.BaseSampler {
44  public:
45 
46 
47  function samples = performSampling(params) {
48 
49  nparams = length(params);
50  ranges = cell(nparams,1);
51 
52  /* Create linearly spaced parameter value ranges */
53  for pidx=1:nparams
54  /* Cater for single parameters */
55  if (params(pidx).MinVal == params(pidx).MaxVal)
56  ranges[pidx] = params(pidx).MinVal;
57  else
58  if strcmp(params(pidx).Spacing," lin ")
59  ranges[pidx] = linspace(params(pidx).MinVal,...
60  params(pidx).MaxVal,...
61  params(pidx).Desired);
62  elseif strcmp(params(pidx).Spacing," log ")
63  /* TODO? modify if statements
64  * TODO? uneven params(pidx).Desired) */
65  if params(pidx).MinVal == 0
66  /* then, NaNs due to log10(0) have to be avoided, further MaxVal \neq 0 */
67  m = -16; /* take double precision zero */
68 
69  M = log10(params(pidx).MaxVal);
70  ranges[pidx] = logspace(m, M, params(pidx).Desired);
71  elseif params(pidx).MaxVal == 0
72  /* then, NaNs due to log10(0) have to be avoided, further MinVal \neq 0 */
73  m = log10(params(pidx).MinVal);
74  M = -16; /* take double precision zero */
75 
76  ranges[pidx] = logspace(m, M, params(pidx).Desired);
77  elseif params(pidx).MinVal < 0
78  /* need to split the interval into -[10^ml,10^Ml] [10^mr,10^Mr],
79  * as no logarithm of negative number exists */
80  ml = log10(abs(params(pidx).MinVal));
81  Mr = log10(params(pidx).MaxVal);
82  if ml == Mr
83  divl = params(pidx).Desired/2;
84  divr = params(pidx).Desired/2;
85  Ml = ml - divl + 1;
86  mr = Mr - divr + 1;
87  elseif ml < Mr
88  diff = Mr - ml;
89  divl = (params(pidx).Desired - diff)/2;
90  divr = divl + diff;
91  Ml = ml - divl + 1;
92  mr = Mr - divr +1;
93  elseif ml > Mr
94  diff = ml - Mr;
95  divr = (params(pidx).Desired - diff)/2;
96  divl = divr + diff;
97  Ml = ml - divl + 1;
98  mr = Mr - divr +1;
99  end
100  ranges[pidx] = [-logspace(ml, Ml, divl) logspace(mr, Mr, divr)];
101  else
102  m = log10(params(pidx).MinVal);
103  M = log10(params(pidx).MaxVal);
104  ranges[pidx] = logspace(m, M, params(pidx).Desired);
105  end
106  end
107  end
108  end
109 
110  /* Return first range if only one available. */
111  if nparams == 1
112  samples = ranges[1];
113  else
114  samples = Utils.createCombinations(ranges);
115  end
116 
117  /* Restrict samples to given domain if set */
118  if ~isempty(this.Domain)
119  samples = this.Domain.filter(samples);
120  end
121  }
131  protected: /* ( Static ) */
132 
133  static function obj = loadobj(obj) {
134  if ~isa(obj," sampling.GridSampler ")
135  obj = sampling.GridSampler;
136  end
137  obj = loadobj@sampling.BaseSampler(obj);
138  }
149 };
150 }
151 
152 
153 
Collection of generally useful functions.
Definition: Utils.m:17
function samples = performSampling(params)
Uses the given model and generates a training set by creating a regular grid in joint time/parameter ...
Definition: GridSampler.m:47
function [ matrix< double > params , rowvec< integer > idx ] = filter(matrix< double > params)
Filters from the given parameters only those that belong to this domain.
Definition: Domain.m:81
static function comb = createCombinations(ranges, varargin)
Creates the cartesian product of the vectors passed as a matrix containing elements of each vector pe...
Definition: Utils.m:114
static function obj = loadobj(obj)
Introduced as the "Spacing" property has moved to data.ModelParam.
Definition: GridSampler.m:133
A MatLab cell array or matrix.
BaseSampler Basis class for parameter sampling classes.
Definition: BaseSampler.m:18
GridSampler: Samples the models params on a grid, using the ModelParam.Desired field.
Definition: GridSampler.m:18
Domain:
Definition: Domain.m:18