cs 450 – modeling and simulation dr. x. topics what does randomness mean? randomness in games...

21
CS 450 – Modeling and Simulation Dr. X

Upload: holly-banks

Post on 01-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

CS 450 – Modeling and Simulation

Dr. X

Page 2: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Topics

• What Does Randomness Mean?• Randomness in games• Generating Random Values• Random events in real life: measuring

randomness

Page 3: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

What is Randomness?

• Unpredictability?• Does it characterize a single event or a

sequence of events?• From Wikipedia:

Randomness means lack of pattern or predictability in events. Randomness suggests a non-order or non-coherence in a sequence of symbols or steps, such that there is no intelligible pattern or combination.

Page 4: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Randomness in games

Page 5: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Probability 101

If you roll the dice twice, what is the probability of rolling two sixes?

Page 6: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Probability vs odds

• Odds = Favorable Outcomes / Unfavorable Outcomes

• Probability = Favorable Outcomes / All Outcomes

Page 7: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Probability 101

If you toss two coins what is the probability of HH?

Page 8: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Probability 101

• Independent events• Logical relations:– AND– OR

Page 9: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Defining Randomness

• How can a computer generate random numbers?

• Can we measure randomness?

Page 10: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Measuring Randomness

• Runs Test• Frequency test• Autocorrelation test• Chi-square goodness of fit

Page 11: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Statistical Hypothesis test

• H0: Null Hypothesis, ex., a sequence of numbers is random

• Hα: Alternative Hypothesis, ex., a sequence of numbers is NOT random

Real SituationDecision

H0 is not rejected H0 is rejected

H0 is true Valid Type I Error

H0 is not true Type II Error Valid

Page 12: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Runs test

• Sequence of numbers X1, …, XN

• Subtract Xi+1 – Xi

• Collect only the signs of the subtraction results

• Do the signs alternate ~50% of the time?

Page 13: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Frequency Test (Monobit test)

• Create a string Sn = X1 + X2 + … + Xn

• Calculate Sobs = Sn/n• Calculate P-Value:

P-value = erfc(Sobs/2)where erfc: complementary error function

• If P-value > 0.01 accept the null hypothesis else reject

Page 14: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Autocorrelation Test

Intuition: if the sequence of bits in e is random, then it will be different from another bit string obtained by shifting the bits of e by d positions.

Page 15: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Chi-Square Goodness of Fit Test

• Intuition: test checks whether a sequence of pseudo-random numbers in [0,1] are uniformly distributed

• If you have n numbers and split them in k groups, then if in the groups you have n/k numbers the distribution is normal

• Compare all observed values fi inside your kth group with the mean n/k

• If chi-square > theoretical x2 obtained from table with k degrees of freedom, then null hypothesis rejected

Page 16: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Generating Random Numbers

• Congruential method• Tausworthe generators• Lagged Fibonacci generators• The Mercenne Twister

Page 17: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Congruential Method

xi+1 = axi + c (mod m)• a, c, m: non-negative• If m is large, period of number repetition is

large• Conditions for full period:– m and c have no common divisor– a = 1 (mod r) if r is a prime factor of m – a = 1 (mod 4) if m is a multiple of 4

Page 18: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Tausworthe generators

• Additive congruential generators • Modulus m is equal to 2• xi = (a1xi-1 + a2xi-2 + ...+ anxi-n) (mod 2)

where xi: 0 or 1• Mod 2 is equivalent to XOR

Page 19: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Lagged Fibonacci Generators

• Based on Fibonacci series: xn = xn-1 + xn-2

• LFG: xn = xn-j O xn-k (mod m)where O: addition, or subtraction, or multiplication, or XOR

Page 20: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

Mersenne Twister

xk+n = xk+m (⊕ xku | xk+1

k )A, k≥0

Where x is the block of numbers of w bits

Page 21: CS 450 – Modeling and Simulation Dr. X. Topics What Does Randomness Mean? Randomness in games Generating Random Values Random events in real life: measuring

CS 450 21

References

• The Guide to Computer Simulations and Games, By Katrin Becker and J.R.Parker, Wiley (Chapter 6)

• Computer Simulation Techniques: The Definitive Introduction, by Harry Perros, http://www4.ncsu.edu/~hp/simulation.pdf (Chapter 2)