About
User Reference
C++ API
luafaudes
Developer
Links
libFAUDES online
libFAUDES
C++ API
Sections
Sets
Generators
Functions
PlugIns
Tutorials
Index
Classes
Files
sp_random.h
Go to the documentation of this file.
1
/** @file sp_random.h Evaluating random variables */
2
3
/*
4
FAU Discrete Event System Simulator
5
6
Copyright (C) 2007 Christoph Doerr
7
Exclusive copyright is granted to Thomas Moor
8
9
*/
10
11
#ifndef FAUDES_SP_RANDOM_H
12
#define FAUDES_SP_RANDOM_H
13
14
#include "
tp_timeinterval.h
"
15
#include "
sp_executor.h
"
16
17
18
namespace
faudes {
19
20
/**
21
22
@defgroup SimRandomVariables Random Variables
23
24
@ingroup SimulatorPlugin
25
26
Sampling or evaluating random variables for simulation
27
28
This module implements the evaluation (also known as sampling) of random
29
variables with various distributions. It specialises on restricted support
30
PDFs, since this is required for the ProposingExecutor.
31
32
Random variables and their simulation is a highly involved topic and we give credit
33
to the sources from which this module stems:
34
35
1)
36
Implementation of a random number generator from Stave Park and Dave Geyer, which
37
we use in original form up to minor cosmetic changes.
38
39
2)
40
Inverse gaussian CDF by rational approxomation coefficients, presumably by Peter J, Acjlam,
41
which we use in its original form up to minor cosmetic changes.
42
43
44
3)
45
Gaussian CDF by an aproximation that we found in "Handbook of Mathematical Functions" by
46
Abromowitz and Stegun.
47
48
All sources were available freely and we did not find any restricting licensing terms.
49
Thanks!
50
51
52
---------------------------------------------------------------------
53
54
Regarding 1), from the header of rngs.c
55
56
This is an ANSI C library for multi-stream random number generation.
57
The use of this library is recommended as a replacement for the ANSI C
58
rand() and srand() functions, particularly in simulation applications
59
where the statistical 'goodness' of the random number generator is
60
important. The library supplies 256 streams of random numbers; use
61
SelectStream(s) to switch between streams indexed s = 0,1,...,255.
62
63
The streams must be initialized. The recommended way to do this is by
64
using the function PlantSeeds(x) with the value of x used to initialize
65
the default stream and all other streams initialized automatically with
66
values dependent on the value of x. The following convention is used
67
to initialize the default stream: \n
68
if x > 0 then x is the state \n
69
if x < 0 then the state is obtained from the system clock \n
70
if x = 0 then the state is to be supplied interactively. \n
71
72
The generator used in this library is a so-called 'Lehmer random number
73
generator' which returns a pseudo-random number uniformly distributed
74
0.0 and 1.0. The period is (m - 1) where m = 2,147,483,647 and the
75
smallest and largest possible values are (1 / m) and 1 - (1 / m)
76
respectively. For more details see:
77
78
"Random Number Generators: Good Ones Are Hard To Find" \n
79
Steve Park and Keith Miller \n
80
Communications of the ACM, October 1988 \n
81
82
Name : rngs.c (Random Number Generation - Multiple Streams) \n
83
Authors : Steve Park & Dave Geyer \n
84
Language : ANSI C \n
85
Latest Revision : 09-22-98
86
87
---------------------------------------------------------------------
88
89
Regarding 2), from the header of rngs.c
90
91
This function returns an approximation of the inverse cumulative
92
standard normal distribution function. I.e., given P, it returns
93
an approximation to the X satisfying P = Pr{Z <= X} where Z is a
94
random variable from the standard normal distribution.
95
96
The algorithm uses a minimax approximation by rational functions
97
and the result has a relative error whose absolute value is less
98
than 1.15e-9.
99
100
Author: Peter J. Acklam \n
101
Time-stamp: 2002-06-09 18:45:44 +0200 \n
102
E-mail: jacklam at math dot uio dor no \n
103
WWW URL: http www dot math dot uio dot no /~jacklam \n
104
105
C implementation adapted from Peter's Perl version \n
106
107
---------------------------------------------------------------------
108
109
Regarding 3), found as code example in Wikipedia
110
111
---------------------------------------------------------------------
112
113
114
@{
115
116
*/
117
118
119
120
121
/**
122
* Use this function to set the state of all the random number generator
123
* streams by "planting" a sequence of states (seeds), one per stream,
124
* with all states dictated by the state of the default stream.
125
* The sequence of planted states is separated one from the next by
126
* 8,367,782 calls to ran().
127
*/
128
void
ran_plant_seeds
(
long
x);
129
130
/**
131
* Use this function to set the current random number generator
132
* stream -- that stream from which the next random number will come.
133
*/
134
void
ran_select_stream
(
int
index);
135
136
/**
137
* Put a seed
138
* @param seed
139
* Random generator seed
140
*/
141
void
ran_put_seed
(
long
seed);
142
143
/**
144
* Initialize random generator
145
* @param seed
146
* Random generator seed
147
*/
148
void
ran_init
(
long
seed);
149
150
/**
151
* Run random generator
152
* Random Number Generator
153
* (for more details see "Random Number Generators: Good Ones Are Hard To Find"
154
* Steve Park and Keith Miller
155
* Communications of the ACM, October 1988)
156
* @return
157
* Random value in [0,1) ( excluding 1 (?))
158
*/
159
double
ran
(
void
);
160
161
162
/**
163
* Sample a random variable uniformly on interval [a;b)
164
* Distribution: f(t) dt= {1/(b-a)} dt for t, a <=t< b, else 0
165
* @param a
166
* Lower bound
167
* @param b
168
* Upper bound
169
* @return
170
* Random value
171
*/
172
double
ran_uniform
(
double
a,
double
b);
173
174
/**
175
* Sample a discrete random variable uniformly on interval [a;b)
176
* Distribution: p(n) = 1/(b-a-1)
177
* @param a
178
* Lower bound
179
* @param b
180
* Upper bound
181
* @return
182
* Random value
183
*/
184
long
ran_uniform_int
(
long
a,
long
b);
185
186
/**
187
* Sample a random variable exponentially
188
* Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0
189
* @param mu
190
* mu
191
* @return
192
* Random variabe
193
*/
194
double
ran_exponential
(
double
mu);
195
196
/**
197
* Sample a random variable exponentially on a restricted interval
198
* Distribution: f(t) dt = 1/mu exp(-t/mu) dt for t>=0
199
* @param mu
200
* mu
201
* @param tossLB
202
* Lower interval bound
203
* @param tossUB
204
* Upper interval bound
205
*/
206
double
ran_exponential
(
double
mu,
tpTime::Type
tossLB,
tpTime::Type
tossUB);
207
208
/**
209
* Sample a random variable gaussian distributed on a restricted interval
210
* Distribution: f(t) = 1 / sqrt(2 pi sigma^2) * exp( -1/2 ((t-mu)/sigma)^2) for t>=0
211
* @param mu
212
* mu
213
* @param sigma
214
* sigma
215
* @param tossLB
216
* Lower interval bound
217
* @param tossUB
218
* Upper interval bound
219
*/
220
double
ran_gauss
(
double
mu,
double
sigma,
tpTime::Type
tossLB,
tpTime::Type
tossUB);
221
222
/**
223
* Help function: calculate gaussian CDF
224
* using an approximation from
225
* Abromowitz and Stegun: Handbook of Mathematical Functions
226
* @param x
227
* @return CDF(x)
228
*/
229
double
ran_gaussian_cdf_P
(
double
x);
230
231
/** @} doxygen group */
232
233
234
}
// namespace
235
236
237
#define FAUDES_STOCHRAN_H
238
#endif
libFAUDES 2.24g
--- 2014.09.15 --- c++ api documentaion by
doxygen
>>
C++ API
Introduction
Sets
Generators
Functions
PlugIns
Tutorials
Classes
Files
Top of Page