Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

28
Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly

Transcript of Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

Page 1: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

Random Thoughts 2012(COMP 066)

Jan-Michael FrahmJared Heinly

Page 2: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

2

Final Project Presentation

• Dec 11th, 4pm

• presentations are 7-8 min

• slide deadline is Wednesday Dec. 5th

Page 3: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

3

Last class

• Hypothesis testing: test Null hypothesis H0

set decision threshold α (common α=0.05) reject Null hypothesis if sample result is unlikely accept alternative hypothesis if Null hypothesis is

rejected set up alternative hypothesis to proof what you

desire Process is similar to jury trial Sample normalization to Z-distribution (Normal

distribution with zero mean and variance 1)

Page 4: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

4

Last class

• Compute p-value from z-value if alternative hypothesis is: less than p=vp

not equal p=2 vp

larger than p = 1- vp

• Assumptions sufficient number of samples (>30) known standard deviation

Page 5: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

5

T-distribution for Hypothesis Testing

• t-distribution (Excel: T.DIST. ) if: unknown standard deviation if low number of samples

• t-distribution is approximating the z-distribution for higher number of samples (called degrees of freedom N-1, with N the number of samples)

Page 6: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

6

Hypothesis Test Example

• a huge amount of stories about hot and cold slot machines on the Internet

• government tests slot machines null hypothesis the machine is obeying the standards

must not produce detectable patterns of game elements

must not result in any recognizable dependency upon previous game outcome, the amount wagered, or upon the style or method of play

so slot machines really have to be random

I believe what my eyes want to see,And whate'er my fond hope wants to be,

When the experts proclaim otherwise,It's 'cause someone pays them to tell lies.

Page 7: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

7

Alternative Hypothesis

• We want to ensure a minimal pay-out to the player of at least 75% (NV)

• Alternative hypothesis would be the pay-out is less than the legal minimum α = 0.05

• A sample of 124 games costing $1 each provides a payout of $66 is the machine fulfilling the legal minimum payout?

• After 124 played samples the payout is $215 each game cost $1

Page 8: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

8

Comparing Two Groups

• Testing for the difference of two groups often used in drug testing used for differentiating the success of two methods

• Typically the members of the two groups are paired use characteristics of members like IQ, background, age,

• Look at the pair-wise differences with respect to your test characteristics

• Null hypothesis is set to both groups are equal

• Alternative hypothesis is set one group being better/worse

Page 9: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

9

Compare two groups

1. For each pair take the first value minus the second value to get the paired difference

2. Calculate the mean difference and the standard deviation σ of all samples

3. Calculate the standard error of the sample

4. z-value

5. Determine the p-value

Page 10: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

10

Random Numbers

• In this course we have been using random numbers for: simulations in Excel games computer security applications (truly random

numbers are very important there)

• We did discuss the use of math for describing random processes

• How do we get random numbers in a computer which is a deterministic machine?

Page 11: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

11

How to get Random Numbers

• Historically always been a challenge to obtain random numbers earliest source of random numbers have been the use

of dice shuffling cards flipping coins

• All the above methods are tedious

• Random number tables were created to use for large scale experiments first table 1927 L.H.C. Tippett 1946 Rand Corp random number table with 1000, 000

digits (electronic roulette simulations with checks)

Page 12: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

12

How to get Random Numbers

• Since computers are available Pseudo Random Number generator

• Physical methods to generate random numbers

Page 13: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

13

Hardware Random Generators

• random number from from thermal noise from photo-electric effect quantum phenomena (nuclear decay) human actions

• Strong for cryptographic use

• disadvantage: they are relatively slow

Page 14: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

14

Pseudo Random Number Generator (PRNG)

• produces a series of numbers approximating random number series

• not a truly random number series since a small set of numbers (seed) determines the whole sequence

• often not strong enough for security applications

• Typical PRNG: linear congruential generators, lagged Fibonacci generators linear feedback shift registers newer method: Mersenne twister

Page 15: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

15

Linear Congruential Generators

• oldest and best known PRNG

• m (modulus) > 0

• a (multiplier) , 0 < a < m

• c (increment), 0 < c < m

• X0 (seed), 0 < X0 < m

• c and m are relatively prime

• a-1 is divisible by all prime factors of m,

• a-1 is divisible by 4 if m is divisible by 4

Page 16: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

16

Linear Congruential Generators

• Numerical recipes m=232, a=1664525, c=1013904223

Page 17: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

17

Linear Congruential Generators

Page 18: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

18

Linear Congruential Generators

• Range [0, m-1]

• Uniform distribution

• Mapping to a desired range [m1,m2] by

• Mapping to normal distribution (Box-Mueller transformation)

• U1 and U2 are the uniformly distributed variables

Page 19: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

19

Transformed

Page 20: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

20

Homework Assignment

Build a Pseudo Random Number generator in Excel. You should generate 200 random numbers for the seed values of 0, 1001, 7711.

Your random number generator can use a,m,c as in the Numerical Recipes.

The output of your random number generator should be in the range [0,1]

Page 21: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

21

Applications of Random Numbers

• Pseudo random numbers are used in a variety of applications Excel Operating systems programing languages

• Modern slot machines are also using pseudo random numbers

Page 22: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

22

How does a slot machine work?

• Random number generator produces constantly random numbers

• once a player pulls the handle latest random number is used to determine the output combination

Page 23: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

23

Mapping the Random Numbers to values

• Assuming a wheel with 22 symbols

• uneven mapping of values to symbols

• notice many blanks are around the jackpot this

creates a psychological effect of almostwinning

Page 24: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

25

Payout Rates

Page 25: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

26

Expected Payout • sum of the payout*probability of sequence

Page 26: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

27

How to create a slot machine in Excel

• Create a random number generator as table

• Use a mapping table to obtain the values of each wheel

• test for the winnings and set their payouts

Page 27: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

28

Assignment (Monday)

• Simulate a slot machine using the tables in the slides.

• Perform a simulation to verify that your slot machine fulfills the 75% payout

Page 28: Random Thoughts 2012 (COMP 066) Jan-Michael Frahm Jared Heinly.

29

Hypothesis Testing

• A health-care actuary has been investigating the cost of maintaining the cancer patients within its plan. These people have typically been running up costs at the rate of $1,240 per month. A sample of 15 cases for November (the first 15 for which complete records were available) and an average cost of $1,080, with a standard deviation of $180. Is there any evidence of a significant change?