rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
Random.m
1 classdef Random < ParameterSampling.Interface
2  % Parameter sampling class producing randomly distributed parameter samples
3  % in sparameter space `{\cal M}`.
4  %
5  properties(SetAccess=private, Dependent)
7  sample;
8  end
9 
10  properties (Constant)
11  % string specifying the random generator to be used
12  method = 'twister';
13  end
14 
15  properties
16  % cell vector with min and max values for each parameter component
17  ranges;
18 
19  % a random seed for initialization of the random generator (Default =
20  % random value initialized with clock)
21  seed;
22 
23  % number of parameters in the sample
24  nparameters = 100;
25 
26  % boolean value determining whether a logarithmic function shall be
27  % applied on the uniform distribution of the parameter samples.
28  log_distribution = false;
29 
30  end
31 
32  methods
33  function rps = Random(nparameters, seed, log_distribution)
34  % function rps = Random(nparameters, seed, log_distribution)
35  % constructor
36  %
37  % Parameters:
38  % nparameters: @copydoc Random.nparameters
39  % seed: @copydoc Random.seed
40  % log_distribution: @copydoc Random.log_distribution
41  if nargin >= 3
42  rps.log_distribution = log_distribution;
43  end
44  if nargin >= 2
45  rps.seed = seed;
46  else
47  rps.seed = sum(100*clock);
48  end
49  if nargin >= 1
50  rps.nparameters = nparameters;
51  end
52  end
53 
54  function this = init_sample(this, dmodel)
55  % function init_sample(this, dmodel)
57  %
59  %
60  % This method initializes the random number generator with the given #seed.
61  this.ranges = dmodel.mu_ranges;
62  rand(this.method, this.seed);
63  this.init_done = true;
64  end
65 
66  function size = size(this)
67  % function size = size(this)
69  %
71  size = this.nparameters;
72  end
73 
74  function M = get.sample(this)
75  %
76  %
77  % copied from rand_uniform() written by
78  % \author Bernard Haasdonk 29.3.2007
79  % adapted by Martin Drohmann 31.3.2011
80 
81  assert(~isempty(this.ranges));
82  rand(this.method, this.seed);
83 
84  mu_dim = length(this.ranges);
85  M = rand(this.nparameters, mu_dim);
86  for i=1:mu_dim
87  mu_range = this.ranges{i};
88  if this.log_distribution
89  M(:,i) = exp(M(:,i)*(log(mu_range(2)-mu_range(1)))) + mu_range(1);
90  else
91  M(:,i) = M(:,i)*(mu_range(2)-mu_range(1)) + mu_range(1);
92  end
93  end
94 
95  end
96 
97  end
98 
99 
100 end
log_distribution
boolean value determining whether a logarithmic function shall be applied on the uniform distribution...
Definition: Random.m:79
Parameter sampling sets.
Definition: Interface.m:1
virtual function init_sample(IDetailedModel dmodel)
initializes the parameter sampling object
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
virtual function size = size()
returns the number of parameter vectors in this sampling
Parameter sampling class producing randomly distributed parameter samples in sparameter space ...
Definition: Random.m:18