random number generators cisc/qcse 810. what is random? flip 10 coins: how many do you expect will...

20
Random Number Generators CISC/QCSE 810

Upload: charlotte-baker

Post on 26-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Random Number Generators

CISC/QCSE 810

Page 2: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

What is random?

Flip 10 coins: how many do you expect will be heads?

Measure 100 people: how are their heights distributed?

How would you recognize an outlying data point?

Page 3: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

True randomness

Surprisingly hard to defineBest identified by its absence simulate a sequence of events many

times (millions) and see if data distribution matches theoretical one

bad sequences hard to identify with few (thousands) of samples

Page 4: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Computer Example

Sample 100 normally distributed random variables based on population height characteristics

Page 5: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

How did it do that??

The computer includes a pseudo-random number generator function

Page 6: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Randomness and Number Theory

Surprisingly, most pseudo-random number generators are developed through applications of number theory number theory usually considered the

most 'pure' of mathematics also considered the least random!

Connection is that integers are well-understood, not rounded off, can generate long, non-repetitive cycles

Page 7: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Congruential Generator

Function is linear (so random?)'randomness' comes from modulus, or 'clock arithmetic' improves (generally) with larger m,

and prime m can still be ruined by bad a, b values

1( )modn nx ax b m

Page 8: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Simple Examples

a = 10, b = 2, m = 13

a = 769, b = 3, m = 1001

a = 16807, b = 0, m = 2147483647

Page 9: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Lagged Fibonacci

Examples: r = 17, s = 5, N = 2^32 r= 68, s = 33, N = 2^32

Can initialize first part of series with any valuesThrow away first collection (see graph)

mod( )n n r n sx xx N

Page 10: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Common features

All generate a sequence of pseudo-random numbers

must set a 'seed' for the sequence

All sequences generate uniformly distributed numbers on [0, N)

some real-valued algorithms exist, but generally integer are preferred because of lack of round-off error

All will eventually reach back to start of a cycle 2^32 = 4 x 10^9 best case for those shown

Converting to [0, 1) range: divide by N

Page 11: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Applications

Multivariate numerical integration large number of dimensions

Simulating inter-related probabilities Gibbs sampling

Direct simulation models with error, randomness molecular simulations

Graph simulations binary values represent connections

Page 12: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Integration

Simpson's rule, etc. are sufficiently efficient on one, two, three variable problemsProblems in 6,7, or higher dimensions, much less so! grid size is to (num intervals)^D

Alternative approach: generate random samples from space, take average of function at those points

Page 13: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

3D Example: sphere

Estimate the volume of the 3D and 10D (hyper)-sphereTake uniform samples on hypercube [-1 1]^3 or [-1 1]^10

Percentage that fall inside sphere (easy to check) represent percent volume of cube inside (hyper)-sphere

Page 14: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Convergence

Page 15: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Quasi-random numbers

Pseudo random are best for real randomness last value doesn’t predict value of next

For integration in particular, want guarantees of fast coverage of hyper-volumes last value should depend on previous ones

Sampling almost on a grid, but able to stop at any point in the samplingSearch for Sobol sequences, or low discrepancy sequences (LDS)

Page 16: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

2D Example – Halton Sequence

Page 17: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Volume of 6D Sphere

0 500 1000 1500 2000 2500 3000 3500 4000 4500 50000

5

10

15

Halton

Pseudo

Page 18: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Testing Random Numbers

Tests for randomness are usually statistical, and require long sequences (millions of values)Some subtle correlations can occur that can affect simulations some more than others; depends on

interpretation of the values (binary, floating point, dimensionality, etc.)

See Marsaglia for references and test suites (Diehard suite)

Page 19: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

"Physical" randomness

Machines exist measure time between radioactive

decay events

Surprisingly, values from these are often 'less' random than computer-generated ones! Don't take randomness on faith (or

advertising)

Page 20: Random Number Generators CISC/QCSE 810. What is random? Flip 10 coins: how many do you expect will be heads? Measure 100 people: how are their heights

Summary

Randomness is difficult to defineGenerating sequences of random numbers is not a trivial exercise use references!

If possible, develop or borrow tests before you start using a generator