modelUsersGuide
Information
Users Guide of the Variates Library
Variates package contains a set of functions for generating random observations from the following probability distributions.
Discrete Probability Distributions:- Empirical Discrete
- Bernoulli
- Discrete Uniform
- Binomial
- Geometric
- Negative Binomial
- Poisson
- Empirical Continuous
- Uniform
- Exponential
- Erlang
- Gamma
- Weibull
- Normal
- LogNormal
- Beta
- Johnson (bounded and unbounded)
- Triangular
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.
Library Structure
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.
Random Variate Generation
In order to generate uniform random observations using Variates package the user has to:
- Declare a Generator that represents the source of uniform random numbers.
- Initialize it with the initGenerator function.
- Call the function of the desired probability distribution with the required parameters to generate a random variate. This function will return the generated random variate and the updated state of the Generator.
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.
Use Another Source of Uniform Random Numbers
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:
- The random number generator has to be described by a Modelica record datatype. For example, for a generator that reads numbers from a file, this record will store the filename and the last line read.
- The record that describe the random number generator has to be initialized using a function. This function can not have input parameters.
- A function to generate random numbers has to be declared following this prototype:
function name input generator g; output Real u; output generator gout; end name;Where generator is the record mentioned in the previous requirement.
Once the new random number generator meets these requirements, the Variates Generator, initGenerator and U01 values has to be set to the ones in the new random number generator.