SlideShare a Scribd company logo
RANDOM NUMBER GENERATION
• Measured data often have random fluctuations .
• This may be due to inaccurate measurements .
• It may also be due to other external influences .
• Often we know or believe there is a deterministic model .
• (i.e., the process can be modeled by a deterministic equation .)
• However, deterministic equations can also have random behavior !
• The study of such equations is sometimes called chaos theory .
• We will look at a simple example, namely, the logistic equation .
The Logistic Equation
A simple deterministic model of population growth is
xk+1 = λ xk , k = 1, 2, · · · ,
for given λ , (λ ≥ 0) , and for given x0 , (x0 ≥ 0) .
The solution is
xk = λk
x0 , k = 1, 2, · · · .
Thus
If 0 ≤ λ < 1 then xk → 0 as k → ∞ (”extinction”) .
If λ > 1 then xk → ∞ as k → ∞ (”exponential growth”) .
A somewhat more realistic population growth model is
xk+1 = λ xk (1 − xk) , k = 1, 2, · · · ,
• This model is known as the logistic equation .
• The maximum sustainable population is 1 .
• λ is given, (0 ≤ λ ≤ 4) .
• x0 is given, (0 ≤ x0 ≤ 1) .
• Then 0 ≤ xk ≤ 1 for all k . (Prove this !)
QUESTION : How does the sequence {xk}∞
k=1 depend on λ ?
EXERCISE :
xk+1 = λ xk (1 − xk) , k = 1, 2, · · · ,
• Divide the interval [0, 1] into 200 subintervals .
• Compute xk for k = 1, 2, · · · 50 .
• Count the xk’s in each subinterval.
• Determine the percentage of xk’s in each subinterval.
• Present the result in a diagram .
• Do this for different choices of λ (0 ≤ λ ≤ 4) .
0.0 0.2 0.4 0.6 0.8
x
0.0
0.1
0.2
0.3
0.4
0.5
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 0.9 , x0 = 0.77 , 50 iterations , 200 subintervals .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 1.7 , x0 = 0.77 , 50 iterations , 200 subintervals .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.00
0.01
0.02
0.03
0.04
0.05
0.06
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.77 , x0 = 0.77 , 50 iterations , 200 subintervals .
EXERCISE :
xk+1 = λ xk (1 − xk) , k = 1, 2, · · · ,
Do the same as in the preceding example, but now
• Compute xk for k = 1, 2, · · · 1, 000, 000 !
• Do not record the first 200 iterations.
• ( This to eliminate transient effects .)
• You will see that there is a fixed point (a cycle of period 1 ) .
0.0 0.2 0.4 0.6 0.8 1.0
x
0.0
0.2
0.4
0.6
0.8
1.0
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 1.7 , 1, 000, 000 iterations , 200 subintervals .
There is a fixed point (a cycle of period 1 ) .
0.0 0.2 0.4 0.6 0.8 1.0
x
0.00
0.05
0.10
0.15
0.20
0.25
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.46 , 1, 000, 000 iterations , 200 subintervals .
There is a cycle of period 4 .
0.0 0.2 0.4 0.6 0.8 1.0
x
0.00
0.02
0.04
0.06
0.08
0.10
0.12
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.561 , 1, 000, 000 iterations , 200 subintervals .
There is a cycle of period 8 .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.00
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.6 , 1, 000, 000 iterations , 200 subintervals .
(The Figure on the right only shows 100 of these iterations.)
There is apparent chaotic behavior .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0.035
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.77 , 1, 000, 000 iterations , 200 subintervals .
(The Figure on the right only shows 100 of these iterations.)
There is apparent chaotic behavior .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0.035
0.040
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.89 , 1, 000, 000 iterations , 200 subintervals .
(The Figure on the right only shows 100 of these iterations.)
There is apparent chaotic behavior .
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.000
0.005
0.010
0.015
0.020
0.025
0.030
0.035
p(x)
0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
x
0.0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1.0
y
Percentage per interval Graphical interpretation.
λ = 3.99 , 1, 000, 000 iterations , 200 subintervals .
(The Figure on the right only shows 100 of these iterations.)
There is apparent chaotic behavior .
CONCLUSIONS :
• The behavior of the logistic equation depends on λ .
• For certain values of λ we see fixed points .
• For other values of λ there are cycles .
• For yet other values of λ there is seemingly random behavior .
• Many other deterministic equations have ”complex behavior ” !
• Nature is complex !
Generating Random Numbers
The logistic equation is a recurrence relation of the form
xk+1 = f(xk) , k = 1, 2, 3, · · · .
Most random number generators also have this form.
For the logistic equation we did not see sequences {xk}N
k=1 having
• a uniform distribution,
• a normal distribution,
• another known distribution.
QUESTION :
• How to generate uniform (and other) random numbers ?
• ( These are useful in computer simulations .)
Generating Uniformly Distributed Random Numbers
Uniformly distributed random numbers can also be generated by
a recurrence relation of the form
xk+1 = f(xk) , k = 1, 2, 3, · · · .
Unlike the logistic equation, the xk are most often integers .
The recurrence relation typically has the form
xk+1 = (n xk) mod p .
where p is a large prime number , and n a large integer , with
p 6 | n .
The following fact is useful :
THEOREM :
Let p be a prime number, and n an integer such that
p 6 | n .
Then the function
f : { 0, 1, 2, · · · , p − 1 } → { 0, 1, 2, · · ·, p − 1 } ,
given by
f(x) = (n x) mod p ,
is one-to-one (and hence onto, a bijection, and invertible).
p prime , p 6 | n ⇒ (n x) mod p is 1 − 1
EXAMPLE :
p = 7 and n = 12 .
x 12x 12x mod 7
0 0 0
1 12 5
2 24 3
3 36 1
4 48 6
5 60 4
6 72 2
Invertible !
NOTE : The values of 12x mod 7 look somewhat random !
p prime , p 6 | n ⇒ (n x) mod p is 1 − 1
EXAMPLE :
p = 6 and n = 2 .
x 2x 2x mod 6
0 0 0
1 2 2
2 4 4
3 6 0
4 8 2
5 10 4
Not Invertible .
p prime , p 6 | n ⇒ (n x) mod p is 1 − 1
EXAMPLE :
p = 6 and n = 13 .
x 13x 13x mod 6
0 0 0
1 13 1
2 26 2
3 39 3
4 52 4
5 65 5
Invertible . ( So ? )
NOTE : The numbers in the right hand column don’t look random !
p prime , p 6 | n ⇒ (n x) mod p is 1 − 1
PROOF : By contradiction : Suppose the function is not 1 − 1 .
Then there are distinct integers x1 , x2 ∈ { 0, 1, 2, · · ·, p − 1 } ,
such that
(nx1) mod p = k and (nx2) mod p = k ,
where also k ∈ { 0, 1, 2, · · ·, p − 1 } . It follows that
p | n(x1 − x2) , ( Why ? )
Since p is prime and p 6 | n it follows that
p | (x1 − x2) .
Thus x1 −x2 = 0 ( Why ? ) , i.e. , x1 = x2 . Contradiction !
For given x0 , an iteration of the form
xk = (n xk−1) mod p , k = 1, 2, · · · , p − 1 .
can be used to generate random numbers .
• Here p is a large prime number .
• The value of n is also large .
• The integer n must not be divisible by p .
• Do not start with x0 = 0 (because it is a fixed point !) .
• Be aware of cycles (of period less than p − 1) !
REMARK : Actually, more often used is an iteration of the form
xk = (n xk−1 + m) mod p , k = 1, 2, · · · , p − 1 .
EXAMPLE : As a simple example, take again p = 7 and n = 12 :
x 12x 12x mod 7
0 0 0
1 12 5
2 24 3
3 36 1
4 48 6
5 60 4
6 72 2
With x1 = 1 the recurrence relation
xk+1 = f(xk) , where f(x) = 12x mod 7 ,
generates the sequence
1 → 5 → 4 → 6 → 2 → 3 → 1 → 5 → · · ·
which is a cycle of maximal period p − 1 (here 6) .
f(x) sequence cycle period
5x mod 7 1 → 5 → 4 → 6 → 2 → 3 → 1 6
6x mod 7 1 → 6 → 1 → 6 → 1 → 6 → 1 2
8x mod 7 1 → 1 → 1 → 1 → 1 → 1 → 1 1
9x mod 7 1 → 2 → 4 → 1 → 2 → 4 → 1 3
10x mod 7 1 → 3 → 2 → 6 → 4 → 5 → 1 6
11x mod 7 1 → 4 → 2 → 1 → 4 → 2 → 1 3
12x mod 7 1 → 5 → 4 → 6 → 2 → 3 → 1 6
EXAMPLE : With x0 = 2 , compute
xk = (137951 xk−1) mod 101 , k = 1, 2, · · · , 100 .
Result :
71 46 17 48 88 94 4 41 92 34
96 75 87 8 82 83 68 91 49 73
16 63 65 35 81 98 45 32 25 29
70 61 95 90 64 50 58 39 21 89
79 27 100 15 78 42 77 57 54 99
30 55 84 53 13 7 97 60 9 67
5 26 14 93 19 18 33 10 52 28
85 38 36 66 20 3 56 69 76 72
31 40 6 11 37 51 43 62 80 12
22 74 1 86 23 59 24 44 47 2
QUESTION : Are there repetitions (i.e., cycles) ?
EXAMPLE : As in the preceding example, use x0 = 2 , and
compute
xk = (137951 xk−1) mod 101 , k = 1, 2, · · · , 100 ,
and set
x̂k =
xk
100
.
0.710 0.460 0.170 0.480 0.880 0.940 0.040 0.410 0.920 0.340
0.960 0.750 0.870 0.080 0.820 0.830 0.680 0.910 0.490 0.730
0.160 0.630 0.650 0.350 0.810 0.980 0.450 0.320 0.250 0.290
0.700 0.610 0.950 0.900 0.640 0.500 0.580 0.390 0.210 0.890
0.790 0.270 1.000 0.150 0.780 0.420 0.770 0.570 0.540 0.990
0.300 0.550 0.840 0.530 0.130 0.070 0.970 0.600 0.090 0.670
0.050 0.260 0.140 0.930 0.190 0.180 0.330 0.100 0.520 0.280
0.850 0.380 0.360 0.660 0.200 0.030 0.560 0.690 0.760 0.720
0.310 0.400 0.060 0.110 0.370 0.510 0.430 0.620 0.800 0.120
0.220 0.740 0.010 0.860 0.230 0.590 0.240 0.440 0.470 0.020
QUESTION : Do these numbers look uniformly distributed ?
EXAMPLE : With x0 = 2 , compute
xk = (137953 xk−1) mod 101 , k = 1, 2, · · · , 100 .
Result :
75 35 50 57 67 38 11 59 41 73
61 15 7 10 72 74 48 83 32 89
55 93 3 62 2 75 35 50 57 67
38 11 59 41 73 61 15 7 10 72
74 48 83 32 89 55 93 3 62 2
75 35 50 57 67 38 11 59 41 73
61 15 7 10 72 74 48 83 32 89
55 93 3 62 2 75 35 50 57 67
38 11 59 41 73 61 15 7 10 72
74 48 83 32 89 55 93 3 62 2
QUESTION : Are there cycles ?
EXAMPLE : With x0 = 4 , compute
xk = (137953 xk−1) mod 101 , k = 1, 2, · · · , 100 .
Result :
49 70 100 13 33 76 22 17 82 45
21 30 14 20 43 47 96 65 64 77
9 85 6 23 4 49 70 100 13 33
76 22 17 82 45 21 30 14 20 43
47 96 65 64 77 9 85 6 23 4
49 70 100 13 33 76 22 17 82 45
21 30 14 20 43 47 96 65 64 77
9 85 6 23 4 49 70 100 13 33
76 22 17 82 45 21 30 14 20 43
47 96 65 64 77 9 85 6 23 4
QUESTIONS :
• Are there cycles ?
• Is this the same cycle that we already found ?
Generating Random Numbers using the Inverse Method
• There are algorithms that generate uniform random numbers.
• These can be used to generate other random numbers.
• A simple method to do this is the Inverse Transform Method .
RECALL :
Let f(x) be a density function on an interval [a, b] .
The distribution function is
F(x) ≡
Z x
a
f(x) dx .
• Since f(x) ≥ 0 we know that F(x) is increasing .
• If F(x) is strictly increasing then F(x) is invertible .
X x1 x2
We want random numbers X with distribution F(x) (blue) .
Let the random variable Y be uniform on the interval [0, 1] .
Let X = F−1
(Y ) .
Then P(x1 ≤ X ≤ x2) = y2 − y1 = F(x2) − F(x1) .
Thus F(x) is indeed the distribution function of X !
• If Y is uniformly distributed on [0, 1] then
P( y1 ≤ Y ≤ y2 ) = y2 − y1 .
• Let
X = F−1
(Y ) ,
with
x1 = F−1
(y1) and x2 = F−1
(y2) .
• Then
P(x1 ≤ X ≤ x2) = y2−y1 = F(x2)−F(x1) . ( Why ? )
• Thus F(X) is also the distribution function of X ≡ F−1
(Y ) !
NOTE : In the illustration X is on [0, 1] , but this is not necessary.
EXAMPLE :
Recall that the exponential density function
f(x) =



λe−λx
, x > 0
0 , x ≤ 0
has distribution function
F(x) =



1 − e−λx
, x > 0
0 , x ≤ 0
The inverse distribution function is
F−1
(y) = −
1
λ
log(1 − y) , 0 ≤ y < 1 . ( Check ! )
0 1 2 3 4 5 6
x
0.0
0.2
0.4
0.6
0.8
F
(x)
The inverse method for generating 20 ”exponential random numbers ” ,
for the exponential distribution function with λ = 1 .
EXAMPLE : ( continued · · · )
(Using the inverse method to get exponential random numbers.)
• Divide [0, 12] into 100 subintervals of equal size ∆x = 0.12 .
• Let Ik denote the kth interval, with midpoint xk .
• Use the inverse method to get N exponential random numbers.
• Let mk be the frequency count (# of random values in Ik) .
• Let ˆ
f(xk) =
mk
N ∆x
.
• Then
Z ∞
0
ˆ
f(x) dx ∼
=
100
X
k=1
ˆ
f(xk) ∆x = 1 .
• Then ˆ
f(x) approximates the actual density function f(x) .
0 1 2 3 4 5 6 7
x
0.0
0.2
0.4
0.6
0.8
1.0
f
(x)
0 1 2 3 4 5 6 7
x
0.0
0.2
0.4
0.6
0.8
1.0
f
(x)
N = 500 . N = 50, 000 .
Simulating the exponential random variable with λ = 1 .
(The actual density function is shown in blue.)
EXERCISE : Consider the Tent density function
f(x) =



x + 1 , −1 < x ≤ 0
1 − x , 0 < x ≤ 1
0 , otherwise
• Verify that that the distribution function is given by
F(x) =



1
2
x2
+ x + 1
2
, −1 ≤ x ≤ 0
−1
2
x2
+ x + 1
2
, 0 < x ≤ 1
• Verify that that the inverse distribution function is
F−1
(y) =



−1 +
√
2y , 0 ≤ y ≤ 1
2
1 −
√
2 − 2y , 1
2
< y ≤ 1
• Use the inverse method to generate ”Tent random numbers ”.
−1.0 −0.5 0.0 0.5 1.0
x
0.0
0.2
0.4
0.6
0.8
1.0
f
(x)
−1.0 −0.5 0.0 0.5 1.0
x
0.0
0.2
0.4
0.6
0.8
F
(x)
The ”Tent ” density Function. The ”Tent ” distribution function.
The inverse method for generating 20 ”Tent random numbers ” .
−1.00 −0.75 −0.50 −0.25 0.00 0.25 0.50 0.75 1.00
x
0.00
0.25
0.50
0.75
1.00
1.25
1.50
f
(x)
−1.00 −0.75 −0.50 −0.25 0.00 0.25 0.50 0.75 1.00
x
0.00
0.25
0.50
0.75
1.00
1.25
f
(x)
N = 500 . N = 50, 000 .
Simulating the ”Tent random variable ” .
(The actual density function is shown in blue.)

More Related Content

PDF
Intro probability 4
Phong Vo
 
PPT
Clase3 Notacion
luzenith_g
 
PDF
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
widespreadpromotion
 
PDF
Mathematics Ist year pdf.pdf
proacademyhub
 
PDF
Maths 11
Mehtab Rai
 
PPT
2010 3-24 cryptography stamatiou
vafopoulos
 
PDF
Rosen, K. - Elementary Number Theory and Its Application (Instructor's Soluti...
Sahat Hutajulu
 
PDF
Maths sa 1 synopsis
Abdallahawesome
 
Intro probability 4
Phong Vo
 
Clase3 Notacion
luzenith_g
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
widespreadpromotion
 
Mathematics Ist year pdf.pdf
proacademyhub
 
Maths 11
Mehtab Rai
 
2010 3-24 cryptography stamatiou
vafopoulos
 
Rosen, K. - Elementary Number Theory and Its Application (Instructor's Soluti...
Sahat Hutajulu
 
Maths sa 1 synopsis
Abdallahawesome
 

Similar to RANDOM NUMBER GENERATION, The Logistic Equation (20)

DOCX
DIGITAL TEXT BOOK
bintu55
 
PDF
Appendex
swavicky
 
DOCX
Rajnifile
rajni
 
PDF
Power Full Exposition
Heesu Hwang
 
PPT
Design and analysis of algorithm ppt ppt
srushtiivp
 
ODP
When Computers Don't Compute and Other Fun with Numbers
PDE1D
 
PPT
ch08 modified.pptmodified.pptmodified.ppt
tahirnaquash2
 
PPT
lecture07 dicrete mathematics relation .ppt
ssuser7b9bda1
 
DOCX
Theoryofcomp science
Raghu nath
 
PDF
Computer science-formulas
RAJIV GANDHI INSTITUTE OF TECHNOLOGY
 
PDF
Roots equations
oscar
 
PDF
Roots equations
oscar
 
PDF
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
leoyang0406
 
PPTX
Number System2.pptx
AnshRattan
 
PPTX
The Most Beautiful formula
PriyatoshDutta
 
PDF
Advanced Calculus and Analysis MA1002 - CiteSeer ( PDFDrive ).pdf
SREEPATHI SHETTY
 
PDF
Analysis of Algorithms - 2
AtakanAral
 
PDF
Study on a class of recursive functions
Luca Polidori
 
PPT
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
ssuser702532
 
PDF
RSA Cryptosystem
aniruddh Tyagi
 
DIGITAL TEXT BOOK
bintu55
 
Appendex
swavicky
 
Rajnifile
rajni
 
Power Full Exposition
Heesu Hwang
 
Design and analysis of algorithm ppt ppt
srushtiivp
 
When Computers Don't Compute and Other Fun with Numbers
PDE1D
 
ch08 modified.pptmodified.pptmodified.ppt
tahirnaquash2
 
lecture07 dicrete mathematics relation .ppt
ssuser7b9bda1
 
Theoryofcomp science
Raghu nath
 
Computer science-formulas
RAJIV GANDHI INSTITUTE OF TECHNOLOGY
 
Roots equations
oscar
 
Roots equations
oscar
 
Dynamic Programming From CS 6515(Fibonacci, LIS, LCS))
leoyang0406
 
Number System2.pptx
AnshRattan
 
The Most Beautiful formula
PriyatoshDutta
 
Advanced Calculus and Analysis MA1002 - CiteSeer ( PDFDrive ).pdf
SREEPATHI SHETTY
 
Analysis of Algorithms - 2
AtakanAral
 
Study on a class of recursive functions
Luca Polidori
 
ADVANCED ALGORITHMS-UNIT-3-Final.ppt
ssuser702532
 
RSA Cryptosystem
aniruddh Tyagi
 
Ad

Recently uploaded (20)

PDF
D9110.pdfdsfvsdfvsdfvsdfvfvfsvfsvffsdfvsdfvsd
minhn6673
 
PPTX
International-health-agency and it's work.pptx
shreehareeshgs
 
PPTX
Introduction-to-Python-Programming-Language (1).pptx
dhyeysapariya
 
PPTX
Probability systematic sampling methods.pptx
PrakashRajput19
 
PPTX
1intro to AI.pptx AI components & composition
ssuserb993e5
 
PDF
717629748-Databricks-Certified-Data-Engineer-Professional-Dumps-by-Ball-21-03...
pedelli41
 
PDF
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
PDF
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
PPTX
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
PDF
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
PPTX
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
PPTX
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PPTX
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
PPT
Grade 5 PPT_Science_Q2_W6_Methods of reproduction.ppt
AaronBaluyut
 
PPT
2009worlddatasheet_presentation.ppt peoole
umutunsalnsl4402
 
PDF
Chad Readey - An Independent Thinker
Chad Readey
 
PDF
blockchain123456789012345678901234567890
tanvikhunt1003
 
PDF
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
PDF
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
D9110.pdfdsfvsdfvsdfvsdfvfvfsvfsvffsdfvsdfvsd
minhn6673
 
International-health-agency and it's work.pptx
shreehareeshgs
 
Introduction-to-Python-Programming-Language (1).pptx
dhyeysapariya
 
Probability systematic sampling methods.pptx
PrakashRajput19
 
1intro to AI.pptx AI components & composition
ssuserb993e5
 
717629748-Databricks-Certified-Data-Engineer-Professional-Dumps-by-Ball-21-03...
pedelli41
 
Technical Writing Module-I Complete Notes.pdf
VedprakashArya13
 
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
202501214233242351219 QASS Session 2.pdf
lauramejiamillan
 
INFO8116 - Week 10 - Slides.pptx big data architecture
guddipatel10
 
World-population.pptx fire bunberbpeople
umutunsalnsl4402
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
IP_Journal_Articles_2025IP_Journal_Articles_2025
mishell212144
 
Grade 5 PPT_Science_Q2_W6_Methods of reproduction.ppt
AaronBaluyut
 
2009worlddatasheet_presentation.ppt peoole
umutunsalnsl4402
 
Chad Readey - An Independent Thinker
Chad Readey
 
blockchain123456789012345678901234567890
tanvikhunt1003
 
Mastering Financial Analysis Materials.pdf
SalamiAbdullahi
 
WISE main accomplishments for ISQOLS award July 2025.pdf
StatsCommunications
 
Ad

RANDOM NUMBER GENERATION, The Logistic Equation

  • 1. RANDOM NUMBER GENERATION • Measured data often have random fluctuations . • This may be due to inaccurate measurements . • It may also be due to other external influences . • Often we know or believe there is a deterministic model . • (i.e., the process can be modeled by a deterministic equation .) • However, deterministic equations can also have random behavior ! • The study of such equations is sometimes called chaos theory . • We will look at a simple example, namely, the logistic equation .
  • 2. The Logistic Equation A simple deterministic model of population growth is xk+1 = λ xk , k = 1, 2, · · · , for given λ , (λ ≥ 0) , and for given x0 , (x0 ≥ 0) . The solution is xk = λk x0 , k = 1, 2, · · · . Thus If 0 ≤ λ < 1 then xk → 0 as k → ∞ (”extinction”) . If λ > 1 then xk → ∞ as k → ∞ (”exponential growth”) .
  • 3. A somewhat more realistic population growth model is xk+1 = λ xk (1 − xk) , k = 1, 2, · · · , • This model is known as the logistic equation . • The maximum sustainable population is 1 . • λ is given, (0 ≤ λ ≤ 4) . • x0 is given, (0 ≤ x0 ≤ 1) . • Then 0 ≤ xk ≤ 1 for all k . (Prove this !) QUESTION : How does the sequence {xk}∞ k=1 depend on λ ?
  • 4. EXERCISE : xk+1 = λ xk (1 − xk) , k = 1, 2, · · · , • Divide the interval [0, 1] into 200 subintervals . • Compute xk for k = 1, 2, · · · 50 . • Count the xk’s in each subinterval. • Determine the percentage of xk’s in each subinterval. • Present the result in a diagram . • Do this for different choices of λ (0 ≤ λ ≤ 4) .
  • 5. 0.0 0.2 0.4 0.6 0.8 x 0.0 0.1 0.2 0.3 0.4 0.5 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 0.9 , x0 = 0.77 , 50 iterations , 200 subintervals .
  • 6. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 1.7 , x0 = 0.77 , 50 iterations , 200 subintervals .
  • 7. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.00 0.01 0.02 0.03 0.04 0.05 0.06 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.77 , x0 = 0.77 , 50 iterations , 200 subintervals .
  • 8. EXERCISE : xk+1 = λ xk (1 − xk) , k = 1, 2, · · · , Do the same as in the preceding example, but now • Compute xk for k = 1, 2, · · · 1, 000, 000 ! • Do not record the first 200 iterations. • ( This to eliminate transient effects .) • You will see that there is a fixed point (a cycle of period 1 ) .
  • 9. 0.0 0.2 0.4 0.6 0.8 1.0 x 0.0 0.2 0.4 0.6 0.8 1.0 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 1.7 , 1, 000, 000 iterations , 200 subintervals . There is a fixed point (a cycle of period 1 ) .
  • 10. 0.0 0.2 0.4 0.6 0.8 1.0 x 0.00 0.05 0.10 0.15 0.20 0.25 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.46 , 1, 000, 000 iterations , 200 subintervals . There is a cycle of period 4 .
  • 11. 0.0 0.2 0.4 0.6 0.8 1.0 x 0.00 0.02 0.04 0.06 0.08 0.10 0.12 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.561 , 1, 000, 000 iterations , 200 subintervals . There is a cycle of period 8 .
  • 12. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.00 0.01 0.02 0.03 0.04 0.05 0.06 0.07 0.08 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.6 , 1, 000, 000 iterations , 200 subintervals . (The Figure on the right only shows 100 of these iterations.) There is apparent chaotic behavior .
  • 13. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.77 , 1, 000, 000 iterations , 200 subintervals . (The Figure on the right only shows 100 of these iterations.) There is apparent chaotic behavior .
  • 14. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 0.040 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.89 , 1, 000, 000 iterations , 200 subintervals . (The Figure on the right only shows 100 of these iterations.) There is apparent chaotic behavior .
  • 15. 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.000 0.005 0.010 0.015 0.020 0.025 0.030 0.035 p(x) 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 x 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 y Percentage per interval Graphical interpretation. λ = 3.99 , 1, 000, 000 iterations , 200 subintervals . (The Figure on the right only shows 100 of these iterations.) There is apparent chaotic behavior .
  • 16. CONCLUSIONS : • The behavior of the logistic equation depends on λ . • For certain values of λ we see fixed points . • For other values of λ there are cycles . • For yet other values of λ there is seemingly random behavior . • Many other deterministic equations have ”complex behavior ” ! • Nature is complex !
  • 17. Generating Random Numbers The logistic equation is a recurrence relation of the form xk+1 = f(xk) , k = 1, 2, 3, · · · . Most random number generators also have this form. For the logistic equation we did not see sequences {xk}N k=1 having • a uniform distribution, • a normal distribution, • another known distribution. QUESTION : • How to generate uniform (and other) random numbers ? • ( These are useful in computer simulations .)
  • 18. Generating Uniformly Distributed Random Numbers Uniformly distributed random numbers can also be generated by a recurrence relation of the form xk+1 = f(xk) , k = 1, 2, 3, · · · . Unlike the logistic equation, the xk are most often integers . The recurrence relation typically has the form xk+1 = (n xk) mod p . where p is a large prime number , and n a large integer , with p 6 | n .
  • 19. The following fact is useful : THEOREM : Let p be a prime number, and n an integer such that p 6 | n . Then the function f : { 0, 1, 2, · · · , p − 1 } → { 0, 1, 2, · · ·, p − 1 } , given by f(x) = (n x) mod p , is one-to-one (and hence onto, a bijection, and invertible).
  • 20. p prime , p 6 | n ⇒ (n x) mod p is 1 − 1 EXAMPLE : p = 7 and n = 12 . x 12x 12x mod 7 0 0 0 1 12 5 2 24 3 3 36 1 4 48 6 5 60 4 6 72 2 Invertible ! NOTE : The values of 12x mod 7 look somewhat random !
  • 21. p prime , p 6 | n ⇒ (n x) mod p is 1 − 1 EXAMPLE : p = 6 and n = 2 . x 2x 2x mod 6 0 0 0 1 2 2 2 4 4 3 6 0 4 8 2 5 10 4 Not Invertible .
  • 22. p prime , p 6 | n ⇒ (n x) mod p is 1 − 1 EXAMPLE : p = 6 and n = 13 . x 13x 13x mod 6 0 0 0 1 13 1 2 26 2 3 39 3 4 52 4 5 65 5 Invertible . ( So ? ) NOTE : The numbers in the right hand column don’t look random !
  • 23. p prime , p 6 | n ⇒ (n x) mod p is 1 − 1 PROOF : By contradiction : Suppose the function is not 1 − 1 . Then there are distinct integers x1 , x2 ∈ { 0, 1, 2, · · ·, p − 1 } , such that (nx1) mod p = k and (nx2) mod p = k , where also k ∈ { 0, 1, 2, · · ·, p − 1 } . It follows that p | n(x1 − x2) , ( Why ? ) Since p is prime and p 6 | n it follows that p | (x1 − x2) . Thus x1 −x2 = 0 ( Why ? ) , i.e. , x1 = x2 . Contradiction !
  • 24. For given x0 , an iteration of the form xk = (n xk−1) mod p , k = 1, 2, · · · , p − 1 . can be used to generate random numbers . • Here p is a large prime number . • The value of n is also large . • The integer n must not be divisible by p . • Do not start with x0 = 0 (because it is a fixed point !) . • Be aware of cycles (of period less than p − 1) ! REMARK : Actually, more often used is an iteration of the form xk = (n xk−1 + m) mod p , k = 1, 2, · · · , p − 1 .
  • 25. EXAMPLE : As a simple example, take again p = 7 and n = 12 : x 12x 12x mod 7 0 0 0 1 12 5 2 24 3 3 36 1 4 48 6 5 60 4 6 72 2 With x1 = 1 the recurrence relation xk+1 = f(xk) , where f(x) = 12x mod 7 , generates the sequence 1 → 5 → 4 → 6 → 2 → 3 → 1 → 5 → · · · which is a cycle of maximal period p − 1 (here 6) .
  • 26. f(x) sequence cycle period 5x mod 7 1 → 5 → 4 → 6 → 2 → 3 → 1 6 6x mod 7 1 → 6 → 1 → 6 → 1 → 6 → 1 2 8x mod 7 1 → 1 → 1 → 1 → 1 → 1 → 1 1 9x mod 7 1 → 2 → 4 → 1 → 2 → 4 → 1 3 10x mod 7 1 → 3 → 2 → 6 → 4 → 5 → 1 6 11x mod 7 1 → 4 → 2 → 1 → 4 → 2 → 1 3 12x mod 7 1 → 5 → 4 → 6 → 2 → 3 → 1 6
  • 27. EXAMPLE : With x0 = 2 , compute xk = (137951 xk−1) mod 101 , k = 1, 2, · · · , 100 . Result : 71 46 17 48 88 94 4 41 92 34 96 75 87 8 82 83 68 91 49 73 16 63 65 35 81 98 45 32 25 29 70 61 95 90 64 50 58 39 21 89 79 27 100 15 78 42 77 57 54 99 30 55 84 53 13 7 97 60 9 67 5 26 14 93 19 18 33 10 52 28 85 38 36 66 20 3 56 69 76 72 31 40 6 11 37 51 43 62 80 12 22 74 1 86 23 59 24 44 47 2 QUESTION : Are there repetitions (i.e., cycles) ?
  • 28. EXAMPLE : As in the preceding example, use x0 = 2 , and compute xk = (137951 xk−1) mod 101 , k = 1, 2, · · · , 100 , and set x̂k = xk 100 . 0.710 0.460 0.170 0.480 0.880 0.940 0.040 0.410 0.920 0.340 0.960 0.750 0.870 0.080 0.820 0.830 0.680 0.910 0.490 0.730 0.160 0.630 0.650 0.350 0.810 0.980 0.450 0.320 0.250 0.290 0.700 0.610 0.950 0.900 0.640 0.500 0.580 0.390 0.210 0.890 0.790 0.270 1.000 0.150 0.780 0.420 0.770 0.570 0.540 0.990 0.300 0.550 0.840 0.530 0.130 0.070 0.970 0.600 0.090 0.670 0.050 0.260 0.140 0.930 0.190 0.180 0.330 0.100 0.520 0.280 0.850 0.380 0.360 0.660 0.200 0.030 0.560 0.690 0.760 0.720 0.310 0.400 0.060 0.110 0.370 0.510 0.430 0.620 0.800 0.120 0.220 0.740 0.010 0.860 0.230 0.590 0.240 0.440 0.470 0.020 QUESTION : Do these numbers look uniformly distributed ?
  • 29. EXAMPLE : With x0 = 2 , compute xk = (137953 xk−1) mod 101 , k = 1, 2, · · · , 100 . Result : 75 35 50 57 67 38 11 59 41 73 61 15 7 10 72 74 48 83 32 89 55 93 3 62 2 75 35 50 57 67 38 11 59 41 73 61 15 7 10 72 74 48 83 32 89 55 93 3 62 2 75 35 50 57 67 38 11 59 41 73 61 15 7 10 72 74 48 83 32 89 55 93 3 62 2 75 35 50 57 67 38 11 59 41 73 61 15 7 10 72 74 48 83 32 89 55 93 3 62 2 QUESTION : Are there cycles ?
  • 30. EXAMPLE : With x0 = 4 , compute xk = (137953 xk−1) mod 101 , k = 1, 2, · · · , 100 . Result : 49 70 100 13 33 76 22 17 82 45 21 30 14 20 43 47 96 65 64 77 9 85 6 23 4 49 70 100 13 33 76 22 17 82 45 21 30 14 20 43 47 96 65 64 77 9 85 6 23 4 49 70 100 13 33 76 22 17 82 45 21 30 14 20 43 47 96 65 64 77 9 85 6 23 4 49 70 100 13 33 76 22 17 82 45 21 30 14 20 43 47 96 65 64 77 9 85 6 23 4 QUESTIONS : • Are there cycles ? • Is this the same cycle that we already found ?
  • 31. Generating Random Numbers using the Inverse Method • There are algorithms that generate uniform random numbers. • These can be used to generate other random numbers. • A simple method to do this is the Inverse Transform Method .
  • 32. RECALL : Let f(x) be a density function on an interval [a, b] . The distribution function is F(x) ≡ Z x a f(x) dx . • Since f(x) ≥ 0 we know that F(x) is increasing . • If F(x) is strictly increasing then F(x) is invertible .
  • 33. X x1 x2 We want random numbers X with distribution F(x) (blue) . Let the random variable Y be uniform on the interval [0, 1] . Let X = F−1 (Y ) . Then P(x1 ≤ X ≤ x2) = y2 − y1 = F(x2) − F(x1) . Thus F(x) is indeed the distribution function of X !
  • 34. • If Y is uniformly distributed on [0, 1] then P( y1 ≤ Y ≤ y2 ) = y2 − y1 . • Let X = F−1 (Y ) , with x1 = F−1 (y1) and x2 = F−1 (y2) . • Then P(x1 ≤ X ≤ x2) = y2−y1 = F(x2)−F(x1) . ( Why ? ) • Thus F(X) is also the distribution function of X ≡ F−1 (Y ) ! NOTE : In the illustration X is on [0, 1] , but this is not necessary.
  • 35. EXAMPLE : Recall that the exponential density function f(x) =    λe−λx , x > 0 0 , x ≤ 0 has distribution function F(x) =    1 − e−λx , x > 0 0 , x ≤ 0 The inverse distribution function is F−1 (y) = − 1 λ log(1 − y) , 0 ≤ y < 1 . ( Check ! )
  • 36. 0 1 2 3 4 5 6 x 0.0 0.2 0.4 0.6 0.8 F (x) The inverse method for generating 20 ”exponential random numbers ” , for the exponential distribution function with λ = 1 .
  • 37. EXAMPLE : ( continued · · · ) (Using the inverse method to get exponential random numbers.) • Divide [0, 12] into 100 subintervals of equal size ∆x = 0.12 . • Let Ik denote the kth interval, with midpoint xk . • Use the inverse method to get N exponential random numbers. • Let mk be the frequency count (# of random values in Ik) . • Let ˆ f(xk) = mk N ∆x . • Then Z ∞ 0 ˆ f(x) dx ∼ = 100 X k=1 ˆ f(xk) ∆x = 1 . • Then ˆ f(x) approximates the actual density function f(x) .
  • 38. 0 1 2 3 4 5 6 7 x 0.0 0.2 0.4 0.6 0.8 1.0 f (x) 0 1 2 3 4 5 6 7 x 0.0 0.2 0.4 0.6 0.8 1.0 f (x) N = 500 . N = 50, 000 . Simulating the exponential random variable with λ = 1 . (The actual density function is shown in blue.)
  • 39. EXERCISE : Consider the Tent density function f(x) =    x + 1 , −1 < x ≤ 0 1 − x , 0 < x ≤ 1 0 , otherwise • Verify that that the distribution function is given by F(x) =    1 2 x2 + x + 1 2 , −1 ≤ x ≤ 0 −1 2 x2 + x + 1 2 , 0 < x ≤ 1 • Verify that that the inverse distribution function is F−1 (y) =    −1 + √ 2y , 0 ≤ y ≤ 1 2 1 − √ 2 − 2y , 1 2 < y ≤ 1 • Use the inverse method to generate ”Tent random numbers ”.
  • 40. −1.0 −0.5 0.0 0.5 1.0 x 0.0 0.2 0.4 0.6 0.8 1.0 f (x) −1.0 −0.5 0.0 0.5 1.0 x 0.0 0.2 0.4 0.6 0.8 F (x) The ”Tent ” density Function. The ”Tent ” distribution function. The inverse method for generating 20 ”Tent random numbers ” .
  • 41. −1.00 −0.75 −0.50 −0.25 0.00 0.25 0.50 0.75 1.00 x 0.00 0.25 0.50 0.75 1.00 1.25 1.50 f (x) −1.00 −0.75 −0.50 −0.25 0.00 0.25 0.50 0.75 1.00 x 0.00 0.25 0.50 0.75 1.00 1.25 f (x) N = 500 . N = 50, 000 . Simulating the ”Tent random variable ” . (The actual density function is shown in blue.)