Skip to content

Instantly share code, notes, and snippets.

@adpoe

adpoe/std_normal.py

Created Mar 25, 2016
Embed
What would you like to do?
standard normal random variates
# PROCEDURE, From ROSS: Simulation (5th Edition) Page 78
# Step 1: Generate Y1, an exponential random variable with rate 1
Y1 = gen_exponential_distro_rand_variable()
# Step 2: Generate Y2, an exponential random variable with rate 2
Y2 = gen_exponential_distro_rand_variable()
# Step 3: If Y2 - (Y1 - 1)^2/2 > 0, set Y = Y2 - (Y1 - 1)^2/2, and go to Step 4 (accept)
#         Otherwise, go to Step 1 (reject)
subtraction_value = ( math.pow( ( Y1 - 1 ), 2 ) ) / 2
critical_value = Y2 - subtraction_value
if critical_value > 0:
   accept = True
else:
   reject = True
# Step 4: Generate a random number on the Uniform Distribution, U, and set:
#         Z = Y1 if U <= 1/2
#         Z = Y2 if U >- 1/2if accept == True:
   U = random.random()
   if (U > 0.5):
       Z = Y1
   if (U <= 0.5):
       Z = -1.0 * Y1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.