rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Uniform.m
1 classdef Uniform < ParameterSampling.IRefineable
2  % Parameter sampling class with uniformly distributed parameters in the
3  % parameter space.
4 
5  properties (SetAccess = private, Dependent)
7  sample;
8  end
9 
10  properties
11  % boolean value determining whether a logarithmic function shall be
12  % applied on the uniform distribution of the parameter samples.
13  log_distribution = false;
14 
15  % vector or scalar determining how many equally distant vectors shall be
16  % added to the parameter sample in each direction.
17  %
18  % If it is a vector, for each direction of the parameter space a different
19  % number can be given.
20  init_numintervals = 2;
21  end
22 
23  properties (Access = public)
24  % underlying grid of type cubegrid
25  pgrid;
26  end
27 
28  methods
29  function ups = Uniform(init_numintervals, log_distribution)
30  % function ups = Uniform(init_numintervals, log_distribution)
31  % constructor
32  %
33  % Parameters:
34  % init_numintervals: vector or scalar determining how many equally
35  % distant vectors shall be added to the parameter
36  % sample in each direction.
37  % log_distribution: boolean indicator determining whether a
38  % logarithmic function shall be applied on the
39  % uniform distribution of the parameter samples.
40  if nargin >= 1
41  ups.init_numintervals = init_numintervals;
42  end
43  if nargin >= 2
44  ups.log_distribution = log_distribution;
45  end
46  end
47 
48  function init_sample(this, dmodel)
49  % function init_sample(this, dmodel)
51  %
53 
54  if ~this.init_done
55  if this.log_distribution
56  params.range = cellfun(@log, dmodel.mu_ranges, 'UniformOutput', false);
57  else
58  params.range = dmodel.mu_ranges;
59  end
60  if isscalar(this.init_numintervals)
61  params.numintervals = ones(1,length(params.range)) * this.init_numintervals;
62  else
63  params.numintervals = this.init_numintervals;
64  end
65  this.pgrid = cubegrid(params);
66  end
67 
68  this.init_done = true;
69  end
70 
71  function M = get.sample(this)
72  if this.init_done
73  M = get(this.pgrid, 'vertex');
74  if this.log_distribution
75  M = exp(M);
76  end
77  else
78  M = [];
79  end
80  end
81 
82  function levels = get_refinement_levels(this)
83  % function levels = get_refinement_levels(this)
84  % @copybrief ParameterSamplingIRefineableget_refinement_levels()
85  %
86  % @copydetails ParameterSamplingIRefineableget_refinement_levels()
87  levels = get(this.pgrid, 'level');
88  end
89 
90  function size = size(this)
91  % function size = size(this)
92  % @copybrief ParameterSamplingInterfacesize()
93  %
94  % @copydetails ParameterSamplingInterfacesize()
95  size = get(this.pgrid, 'nleafelements');
96  end
97 
98  function this = refine(this, elems)
99  % function this = refine(this, elems)
100  % @copybrief ParameterSamplingIRefineablerefine()
101  %
102  % @copydetails ParameterSamplingIRefineablerefine()
103  if nargin == 1
104  elems = 1:length(this.pgrid.get_leafgids);
105  end
106  this.refined_elements = [this.refined_elements, {elems}];
107  this.sample_history = [this.sample_history, this.sample];
108  refine(this.pgrid, elems);
109  end
110 
111  function cogs = cogs(this)
112  % function cogs = cogs(this)
114  %
115  % @copydetails ParameterSampling.IRefineable.cogs()
116  cogs = get(this.pgrid, 'leafcogs');
117  end
118 
119  function skips = skipped_refinements(this)
120  % function skips = skipped_refinements(this)
121  % @copybrief ParameterSamplingIRefineableskipped_refinements()
122  %
123  % @copydetails ParameterSamplingIRefineableskipped_refinements()
124  li = get_leafgids(this.pgrid);
125  skips = this.pgrid.refine_steps - this.pgrid.creation_step(li);
126  end
127 
128  function max_vertex = elementwise_maximum_of_vertex_values(this, values)
129  % function max_vertex = elementwise_maximum_of_vertex_values(this, values)
130  % @copybrief ParameterSamplingIRefineableelementwise_maximum_of_vertex_values()
131  %
132  % @copydetails ParameterSamplingIRefineableelementwise_maximum_of_vertex_values()
133  li = get_leafgids(this.pgrid);
134  lv = this.pgrid.vertexindex(li,:);
135 
136  value_vertex = reshape(values(lv(:)), size(lv));
137  max_vertex = max(value_vertex, [], 2);
138  end
139  end
140 end
141 
A hierarchical cubegrid of arbitrary dimension.
Definition: cubegrid.m:17
virtual function cogs = cogs()
returns the center of gravity of sample cells (in case the sample can be viewed as a grid) ...
Parameter sampling sets.
Definition: Interface.m:1
virtual function init_sample(IDetailedModel dmodel)
initializes the parameter sampling object
Parameter sampling class with uniformly distributed parameters in the parameter space.
Definition: Uniform.m:18
Interface class for parameter sample classes that allow the adaptive refinement of the sampling...
Definition: IRefineable.m:18
init_numintervals
vector or scalar determining how many equally distant vectors shall be added to the parameter sample ...
Definition: Uniform.m:53
Interface for parameter sampling classes producing discrete parameter sample in the parameter space ...
Definition: Interface.m:18
sample
matrix storing the parameter vectors in the parameter samples as row vectors.
Definition: Interface.m:33