random numbers and monte carlo
DESCRIPTION
Random numbers and Monte Carlo. Inmetro, 8/7/2003. João R. T. de Mello Neto IF - UFRJ. References. The Nature of Mathematical Modeling, N. Gershenfelder , Cambridge, 1999; Numerical Recipes in C, Second Edition, W.H Press et al. , Cambridge, 1992; - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/1.jpg)
Random numbers and Monte Carlo
Inmetro, 8/7/2003
João R. T. de Mello NetoIF - UFRJ
![Page 2: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/2.jpg)
References
• The Nature of Mathematical Modeling, N. Gershenfelder, Cambridge, 1999;
• Numerical Recipes in C, Second Edition, W.H Press et al., Cambridge, 1992;
• Statistical Data Analysis, G. Cowan, Oxford, 1998• Computational Physics, Dean Karlen (online), 1998
![Page 3: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/3.jpg)
Random
O acaso não existe. car sticker
![Page 4: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/4.jpg)
Random numbers
Important task: generate random variables from known probability distributions.
random numbers: produced by the computer in a strictly deterministic way – pseudorandom (→ Monte Carlo Method)
random number generators: ),...,,( 111 xxxfx jjj
linear congruential generators: mcaxx jj mod)( 1
ex: c=3, a=5, m=16 00 x 3163051 mod)(x2163351 mod)(x
0,2,3,13,4,7,6,1,8,11,10,5,12,15,14,9,0,2….
0110 xxxx m
![Page 5: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/5.jpg)
Generators
Arguments from number theory: good values for a, c and m.
Good generators: • longest possible period• individual elements within a period should follow each other “randomly”
Ex. 1 RANDU
a = 65539, m=231, c=0
311 265539 modnn xx
3112 296 mod)( ttt xxx
![Page 6: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/6.jpg)
Generators
![Page 7: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/7.jpg)
Generators
![Page 8: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/8.jpg)
Generators
![Page 9: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/9.jpg)
Generators
“Random numbers fall mainly in the planes” Marsaglia, Proc. Acad. Sci. 61, 25, 1968
What is seen in RANDU is present in any multiplicative congruential generator.
In 32 bit machines: maximum number of hyperplanes in the space of d-dimensions is:
d=3 2953d=4 566d=6 120d=10 41
RANDU has much less than the maximum!
![Page 10: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/10.jpg)
Generators
Ex. 2 Minimal standard generator (Num. Recp. ran0)
a = 75 =16807, m=231-1 RAN1 and RAN2, given in the first edition, are “at best mediocre”
![Page 11: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/11.jpg)
Generators
Ex. 3 RANLUXcernlib (mathlib V115, F.James )A portable high-quality random generator for lattice field theory simulation, M. Lüscher, Comp. Phys. Comm. 79, 100, 1994
period ≥ 10165
Recommendations:1. Do some simple tests.2. Check the results with other generator
Lots of literature about random generators testing. See a set of programs (Die Hard) http://stat.fsu.edu/~geo/diehard.html
Functional definition: an algorithm that generates uniform numbers in acceptable if it is not rejected by a set of tests.
![Page 12: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/12.jpg)
Inverse transform
p(x) uniform probability distribution
otherwise 0
10 xdxdxxp )(
x: uniform deviate Generate y according to g(y).
dxxpdyyg )()( dy
dxxpyg )()( )(yg
dy
dx
y
dyygx0
// )( )(yGx )(xGy 1
0
1
x
y
uniformdeviate in
out
analyticallyor numerically.
G(y)
g(y)
![Page 13: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/13.jpg)
Inverse transform
1
0.5
0 1 2 x
F(x)
3
Ex. 4 discrete case
f(x=0)=0.3f(x=1)=0.2f(x=2)=0.5 u
0.0 ≤ u ≤ 0.3 x=00.3 ≤ u ≤ 0.5 x=10.5 ≤ u ≤ 1.0 x=2
for 2000 deviates:x=0 0.2880X=1 0.2075X=2 0.5045
![Page 14: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/14.jpg)
Inverse transform
Exponential• amount of time until a specific event occurs;• time between independent events (time until a part fails);
0 0, x, xexf );( xexF 1)(
)(xFu
ue x 1
)log( ux 11
ux log1
![Page 15: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/15.jpg)
Acceptance-rejection method
ymax
0
f(x)
xmin xmax
minminmax )( xuxxx
uyy max
if (x,y) under the curve, accept the point, else, discard.
pN
n
A
dxxf
E acc
x
xf
max
min
)(maxminmax )( yxxA
AN
nI acc
N
ApNpI )( 1
p
p
NI
I 11
NI
I 1
![Page 16: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/16.jpg)
Acceptance-rejection method
![Page 17: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/17.jpg)
Importance sampling
g(x): random numbers are easy to generate
g(x)
f(x)
•generate random x according to g(x)• generate u uniformily between 0 and g(x);• if u < f(x), accept x, if not, reject.
![Page 18: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/18.jpg)
Multivariate Normal
Very useful
Starts with a d-dimensional vector of standard normal Random numbers;
Transformed to the desired distribution using:
zRx T
z
dX1 vector of standard normal random numbers
dX1 vector representing the mean
R dXd matrix such that RRT covariancematrix desired
(Cholesky factorization of the cov. matrix)
![Page 19: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/19.jpg)
Multivariate Normal
170
701
.
.
3 2
![Page 20: Random numbers and Monte Carlo](https://reader036.vdocuments.site/reader036/viewer/2022081504/5681401e550346895dab7492/html5/thumbnails/20.jpg)
Random walk
10 simulations1K points each