Variates package contains a set of functions for generating random observations from the following probability distributions.
Discrete Probability Distributions:Most of the algorithms used for generating the random variates
are detailed in "Simulation Modeling and Analysis" (Averill M. Law,
McGraw Hill, 2007), or the documentation of the Arena Simulation
environment.
The structure of the Variates package is divided in three
components: 1) general type and functions; 2) Discrete package; and
3) Continuous package.
The general type and functions mainly contain the
Generator record, which represent the source for uniform
random numbers that will be used by the U01 function,
which is the function that generates uniform random numbers.
Each Generator must be initialized using the function
initGenerator.
Var function is a prototype for the rest of variate
generation functions.
GenerateVariate is a function that accepts an integer
parameter that indicates the probability distribution for the
random variate.
The Constant function generates a constant number,
indicated as a parameter.
Package Discrete contains the functions for generating
random variates following discrete probability distributions.
Package Continuous, analogously to the previous, contains
the functions for generating random variates following continuous
probability distributions.
Each function of these packages contains a description of the
random variates that generates.
In order to generate uniform random observations using Variates package the user has to:
The following example represents the steps indicated above.
model usingVariates
// declaration of the generator
Variates.Generator g1;
Real u1[6];
algorithm
when initial() then
// generator initialization
g1 := Variates.initGenerator();
end when;
when time <= 0 then
for i in 1:6 loop
// generation of random variates from g1 with Exponential(8) distribution.
(u1[i],g1):= Variates.Continuous.Exponential(g1,8);
end for;
end when;
end usingVariates;
//results: u1 = {1.20419,12.282,0.713961,5.28482,7.26866,41.0291}
Several independent sources of random numbers can be created by
declaring several Generators (RngStreams). The initialization of
each declared Generator will give it a different initial
state.
The package seed is automatically managed, so it is not required to
set an initial seed.
CMRG is the default uniform random number generator for the
Variates package. However, Variates package can be used with any
other Modelica library for uniform random generation.
To use other uniform random number generator with the Variates
package the following requirements have to me meet:
function name
input generator g;
output Real u;
output generator gout;
end name;
Where generator is the record mentioned in the previous
requirement.