ETM 607 – Random Number and Random Variates
• Define random numbers and .pseudo-random numbers• Generation of random numbers• Test for random numbers
- Frequency tests- Autocorrelation
• Random-Variate generation- Inverse-transform technique
Definitions:Random number (Ri) – a value between 0 and 1.0, ~ U[0,1).
Random Variable – a variable with an associated probability distribution.Random Variable – a function that assigns a real number to each outcome in the sample space (Feldman and Valdez-Flores).
ex. X ~ U[0,1) Y ~ Exp(5.75)
Z ~ Normal(8.0,1.0)
ETM 607 – Random Number and Random Variates
Random Number (Ri):
12
1
12
)(][
2
1
2][
,0
10,1)(
2
abXV
baXE
otherwise
xxf
ETM 607 – Random Number and Random Variates
Random Number (Ri) – statistical properties:
Uniformity – if divided into n intervals of equal length, then the expected number of observations in each interval is n/N, where N is the total number of observations.
Independence – the probability of a value in a particular interval is independent of the previously generated value.
ETM 607 – Random Number and Random Variates
Generation of Pseudo-Random Number:
Pseudo – false, or “not quite”.
Random numbers generated in a computer. Not exactly random, but generated from an algorithm and are in fact repeatable given same starting position (good for debugging).
ETM 607 – Random Number and Random Variates
Generation of Pseudo-Random Number:
Goal – develop generation method such that output most closely imitates ideal properties of uniformity and independence.
Considerations1.fast and efficient (in code)2.portable to different computers3.should have long cycles (before number pattern repeats)4.Should be repeatable (for debugging)5.Closely approximate true ~U[0,1)
ETM 607 – Random Number and Random Variates
Linear Congruential Method:
Sequence of intergers: X1, X2, X3,…. Xn between 0 and m-1.
Xi+1 = (a Xi+ c) mod mWhere, X0 - initial seeda - multiplierc – incrementm – modulus
Then,
ETM 607 – Random Number and Random Variates
m
XR i
i
Linear Congruential Method:
In class exercise:
Xi+1 = (a Xi+ c) mod mGiven, X0 - 5376a - 13c – 0m – 10000
Find,
ETM 607 – Random Number and Random Variates
4321 ,, RandRRR
Linear Congruential Method:
Why was m = 10000 effective (from a computational perspective) in the example.
In computer algorithm, m is usually a function of 2b , producing same effect in binary terms.
Much research done to determine effective values of a and c to produce long cycles, uniformity and independence.
ETM 607 – Random Number and Random Variates
Combined Linear Congruential:
See book for combining linear congruential methods to produce random number streams with large cycles / periods.
ETM 607 – Random Number and Random Variates
Uniformity Tests :
Null hypothesis, H0: Ri ~ U[0,1) and H1: Ri ~ U[0,1)
Level of significance, = P(reject H0 | H0 true) probability of rejecting the null hypothesis when in null hypothesis is true.
Usually set = .05 or .01, or probability is 5% or 1% of rejecting null hypothesis when performing the test.
ETM 607 – Random Number and Random Variates
/
Uniformity Tests – Kolmogorov-Smirnov:Step 1 – rank data from smallest to largest Ri :
Step 2 - compute
Step 3 – compute D
Step 4 – Use Kolmogorov-Smirnov table A.8, selecting column associated with significance level, and row where N is the number of observations.
Step 5 – If sample statistic D from step 3 is greater than Dthe null hypothesis is rejected. If D <= Dcannot detect difference between random numbers and the uniform distribution.
ETM 607 – Random Number and Random Variates
][]3[]2[]1[ ..... NRRRR
N
iRD
RN
iD
iNi
iNi
1max
max
)(1
)(1
},max{ DD
Uniformity Tests – Kolmogorov-Smirnov:Excellent example in book, Ex. 7.6
insert Ex 7.6
ETM 607 – Random Number and Random Variates
Uniformity Tests – Kolmogorov-Smirnov:Excellent example in book, Ex. 7.6
insert Fig 7.2
ETM 607 – Random Number and Random Variates
Uniformity Tests – Chi-Square Test:
Where Oi is the number of observations within a segment/range/cell, Ei is the expected number of observation in the segment/range, and n is the number of segments/ranges/cells.
For a uniform distribution that has n segments or ranges,
ETM 607 – Random Number and Random Variates
n
NEi
n
ii
ii
E
EO
0
220
)(
Uniformity Tests – Chi-Square Test:
Insert ex 7.7
ETM 607 – Random Number and Random Variates
Independence Tests – Autocorrelation:
Recall correlation (r)
r = .334437
r = -1.0
r = 1.0
ETM 607 – Random Number and Random Variates
Independence Tests – Autocorrelation:Autocorrelation is correlation of a series of data to help identify repeated patterns. Objective is to have autocorrelation values near 0 for all lags.
ETM 607 – Random Number and Random Variates
Lag = 1, r = .171282
Lag = 2, r = -.16459
Lag = 3, r = -.51783
Lag = 5, r = .337725
Time series plot of 7.4.2 data
Lag is the interval betweenplotted vales.
Independence Tests – Autocorrelation:See book for statistical method of applying hypothesis testing for the objective of 0 correlation at various time lags.
ETM 607 – Random Number and Random Variates
Random-Variate Generation – Chapter 8:
Random-Variate generation is converting from a random number (Ri) to a Random Variable, Xi ~ some distribution.
Inverse transform method:Step 1 – compute cdf of the desired random variable XStep 2 – Set F(X) = R where R is a random number ~U[0,1)Step 3 – Solve F(X) = R for X in terms of R. X = F-1(R).Step 4 – Generate random numbers Ri and compute desired random variates:
Xi = F-1(Ri)
ETM 607 – Random Number and Random Variates
Inverse transform method – Uniform Distibution Example:Step 1 – compute cdf of the desired random variable X
Step 2 – Set F(X) = R where R is a random number ~U[0,1)
Step 3 – Solve F(X) = R for X in terms of R. X = F-1(R).
Step 4 – Generate random numbers Ri and compute desired random variates:
Xi = Ri(b-a) + a
ETM 607 – Random Number and Random Variates
bx
bxaab
axax
xF
,1
,
,0
)(
ab
axRxF
)(
aabRXaXabR )(,)(
Inverse transform method – Uniform Distibution Example:
Xi = F-1 (R) = Ri(b-a) + a
If Xi ~ U[5,10)a = 5b =10
Ri Xi
.5 .5(10 - 5)+5 = 7.5
.7 .7(10 – 5) + 5 = 8.5
.1 .1(10 – 5) + 5 = 5.5
ETM 607 – Random Number and Random Variates
Inverse transform method – General Idea:
Mapping (or transforming) from cdf to Random Variable
Insert fig 8.2
ETM 607 – Random Number and Random Variates
In class exercise:
Determine the inverse function F-1 for the triangular distribution.
If, a = 5b = 7c = 10
Find X when R = .75.
ETM 607 – Random Number and Random Variates
cx
cxbacbc
xc
bxaacab
axax
xF
otherwise
cxbacbc
xc
bxaacab
ax
xf
,1
,))((
)(1
,))((
)(,0
)(
,0
,))((
)(2
,))((
)(2
)(
2
2