Created
March 25, 2016 14:50
-
-
Save adpoe/dc231fa2b7c9d3fd914f to your computer and use it in GitHub Desktop.
standard normal random variates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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