Computational Physics I: (Pseudo) Randomness

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Computational Physics I

(Pseudo) Randomness
Comp Phys 1 1

Random Numbers
Many uses in Computation Physics Simulating random processes Repetition of experiment for error analysis Study random effects on obser!ed data (resolution smearing" inefficiencies" acceptance" etc) X Calculating statistical expectations iS e Monte Carlo Integration paths #M (#$%) &' $eynman(s sum o!er paths < >= X ))) eiS

paths

Many of these processes are effecti!ely integrations)))


Comp Phys 1 2

Pseudo Randomness
Computers are deterministic machines" so generally spea*ing they don(t do anything randomly (except for hard&are failures+)

Comp Phys 1

Pseudo Randomness
Pseudo,random numbers are se-uences that appear random based on common statistical tests) %hey are fully deterministic" since the se-uence is &ell defined" e)g) ri.f(ri,/) 0y choosing different starting points in the series (seeds)" a good se-uence &ill generate (to a good approximation) uncorrelated se-uences of numbers)

Comp Phys 1

Randomness
1 typical test of randomness" for se-uence r/" r2" r3" ))) e)g) $or uniform random numbers in 45"/) r = 0:5 $or ri and r6 uncorrelated" i+.6
N X 1 lim ri N !1 N i=1

Numerous other statistical tests &ill be satisfied as &ell)))


http7''&&&)random)org'analysis'
Comp Phys 1 5

(any moment should con!erge to expectation from P8$)

Randomness
e)g) 2 test of randomness" for se-uence r/" r2" r3" ))) $or uniform random numbers in 45"/)" moments satisfy7

Z 1 N X 1 1 k k ri ' dx x P (x) ' N i=1 k+1 0


8e!iations about central !alue of the moment !aries proportionally &ith / ' s-rt(N) Normal distribution by C9% 1 !ariety of other useful tests along these lines are a!ailable" for some simple examples7 http7''en)&i*ipedia)org'&i*i'Statistical:randomness
Comp Phys 1 6

8istribution of /st moment


;niform distribution in 45"/)

/55 e!ents'trial

/555 e!ents'trial

/5"555 e!ents'trial

Comp Phys 1

Randomness and entropy


In information theory entropy can be thought of as a measure of information content" Shannon Entropy. <o& much information is carried by a &ord of information= If &ordi>/is fully determined by &ordi" then &ordi>/ gi!es no information) If &ordi>/is fully random" then &e gain exactly one &ord of information from adding &ordi>/) %he Shannon ?ntropy is typically defined as7
N X i=1

H (x)

p(xi )log2 p(xi )


$or completely non,random data .@ 5 $or completely random data .@ Abits of info'&ord
8

Comp Phys 1

Shannon entropy for binary data


/) histogram bytes of data" !alues . 45"2BBC 2) calculate Shannon entropy on D,bit &ords '' entropy calculation double entropy.5E for (int i . 5E i F 2BGE i>>) H if (byteIalues4iC +. 5) H ''histogram of Aoccurrences of each byte double p . (double) byteIalues4iC ' (double) totalE entropy >. ,p J log2(p)E N X K H (x) p(xi )log2 p(xi ) K
i=1

Relati!e fre-uency of !alue 4iC

3) di!ide by Abits'&ord.D entropy'.DE


Comp Phys 1

Shannon entropy for binary data


Note7 Maximal entropy is R?#;IR?8 for identification of randomness but it is not S;$$ICI?N%) Consider the effect of a good data compression algorithm) Information content per data &ord is maximiLed .@ appears as maximum entropy" but is by no means random) Similar to the case of pseudo random se-uences n)b) (Claude) Shannon(s source coding theorem In the large N limit" the a!erage length of the shortest possible encoding of a data set in a gi!en alphabet . the entropy of the data di!ided by the logarithm of the number of symbols in the alphabet)
Comp Phys 1 10

9inear Congruent Menerators


Idea7 Menerate se-uence of random integers in the range 45"M,/C by Cle!erly choose a" c" e)g) M a c G5NB /5G /2D3 D/555 O2/ /N//N 2P32 /GGOB2B /5/3Q5O223

ri (ari1 + c) mod M

Rhere M"c are chosen to be relatively primeJ" optimal choice of a to maximiLe period depends on M) %o get uniform numbers in 45"/)" di!ide result by M) %he seed is the first r !alue used to start the se-uence) Se-uence is deterministic" so same seed may be used to reproduce a particular run to debug code) %ypically use cloc*,time or seed list to ensure independent runs) JNo common di!isors" except /
Comp Phys 1 11

8angers of Pseudo Random A(s


/) 1re your numbers random enough= In a &orse case scenario your simulation may be ignoring important possible outcomes or pro!ide lopsided &eights based on non,uniformity or correlations) 2) %he period (M) may not be long enough for all the random A(s you need) 0illions or trillions of numbers are plausible for highly detailed &or*) 2P32 is only O"2QO"QGN"2QG + Fstdlib)h@ rand() has period of only 2P/B 1 reasonable choice7 drandOD() for uniform A(s in 45"/) Seed &ith srandOD(long seed) Period 2POD S 2D/ trillion 1 better (but slo&er) choice" eg %he Mersenne t&istor algorithm" period . 2/QQ3N,/
Comp Phys 1 12

%rue Random Menerators


%o get a se-uence of true random numbers" special hard&are is re-uired) %hese de!ices are based on physics principles" eg thermal noise" -uantum phenomena)
&&&)cryptography)com'intelRNM)pdf

Comp Phys 1

13

R1N8TM)TRM offers true random numbers to anyone on the Internet) %he randomness comes from atmospheric noise, &hich for many purposes is better than the pseudo,random number algorithms typically used in computer programs)

Comp Phys 1

14

Radioacti!e decay

Shot Noise
https7''my&ebspace)&isc)edu'lnmaurer'&eb'minirng'minirng)html

Comp Phys 1

15

Note7 it(s non,tri!ial tri!ial to implement true randomness" noise may &ell be pin* instead of &hite+ <ard&are de!ices ha!e speed limitations) <o& many random numbers do you need per second= Might be difficult to *eep up &' computations))) Mood pseudo random se-uences are sufficient for many problems)

Comp Phys 1

16

You might also like