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
BaseSampler.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 KerMorObject {
26  public:
27 
42  public:
43 
44  function samples = generateSamples(models.BaseFullModel model) {
45  sys = model.System;
46  if sys.ParamCount == 0
47  samples = [];
48  else
49  params = 1:sys.ParamCount;
50  if ~isempty(model.TrainingParams)
51  params = params(model.TrainingParams);
52  end
53  samples = this.performSampling(sys.Params(params));
54  if ~isempty(model.TrainingParams)
55  full = repmat(model.DefaultMu,1,size(samples,2));
56  full(model.TrainingParams,:) = samples;
57  samples = full;
58  end
59  end
60  }
61 
62 
63 
64 #if 0 //mtoc++: 'set.Domain'
65 function Domain(value) {
66  if ~isempty(value) && ~isa(value," sampling.Domain ")
67  error(" The Domain property must be a sampling.Domain instance. ");
68  end
69  this.Domain= value;
70  }
71 
72 #endif
73 
74 
75  public: /* ( Abstract ) */
76 
77  virtual function samples = performSampling() = 0;
85  protected: /* ( Static ) */
86 
87  static function obj = loadobj(obj,from) {
88  if ~isa(obj," sampling.BaseSampler ")
89  if nargin < 2
90  error(" Invalid call to loadobject method. Must pass the struct to instantiate the class from. ");
91  end
92  if isfield(from," Domain ")
93  obj.Domain= from.Domain;
94  else
95  obj.Domain= [];
96  end
97  obj = loadobj@KerMorObject(obj, from);
98  else
99  obj = loadobj@KerMorObject(obj);
100  end
101  }
102 
103 
104  public: /* ( Static ) */
105 
106  static function res = test_SubsetSampling() {
107  m = models.BaseFullModel;
108  s = models.BaseFirstOrderSystem(m);
109  m.System=s;
110  s.addParam(" param_a ",.5);
111  s.addParam(" param_b ",1);
112  s.addParam(" param_c ",0," Range ",[0,1]);
113  s.addParam(" param_d ",2);
114 
115  m.TrainingParams= [1 3];
116  m.DefaultMu= rand(4,1);
117 
118  m.Sampler= sampling.RandomSampler;
119  m.Sampler.Samples= 500;
120  samples = m.Sampler.generateSamples(m);
121 
122  res = size(samples,1) == 4;
123  res = res & all(samples(2,:) == m.DefaultMu(2));
124  res = res & all(samples(4,:) == m.DefaultMu(4));
125 
126  m.Sampler= sampling.GridSampler;
127  samples = m.Sampler.generateSamples(m);
128  res = res & size(samples,1) == 4;
129  res = res & all(samples(2,:) == m.DefaultMu(2));
130  res = res & all(samples(4,:) == m.DefaultMu(4));
131  }
144 };
145 }
146 
147 
148 
static function res = test_SubsetSampling()
setup parameter domain etc domain are all points in unit square with norm > 0.7
Definition: BaseSampler.m:106
The base class for any KerMor detailed model.
Definition: BaseFullModel.m:18
models.BaseFirstOrderSystem System
The actual dynamical system used in the model.
Definition: BaseModel.m:102
Base class for any KerMor class.
Definition: KerMorObject.m:17
sampling.Domain Domain
A domain from which the produced/generated samples may come from. Use in subclasses at the sampling...
Definition: BaseSampler.m:28
BaseSampler Basis class for parameter sampling classes.
Definition: BaseSampler.m:18
KerMorObject()
Constructs a new KerMor object.
Definition: KerMorObject.m:55
virtual function samples = performSampling()
Template method for actual sampling.
static function obj = loadobj(obj, from)
Definition: BaseSampler.m:87
rowvec< integer > TrainingParams
The indices of the model parameters to use for training data generation.
Speed test * all(1:3)
colvec< double > DefaultMu
The default parameter value if none is given.
Definition: BaseModel.m:355
function samples = generateSamples(models.BaseFullModel model)
Definition: BaseSampler.m:44
ParamCount
The number of the system's parameters.
Domain:
Definition: Domain.m:18