Smallest Box That Still Works
You want samples from the density on , which is the Beta(4,2) density. The method: draw a point uniformly from the rectangle and keep its coordinate whenever the point falls under the graph of .
import random
def sample(h):
draws = 0
while True:
x, y = random.random(), h * random.random()
draws += 1
if y <= 20 * x**3 * (1 - x):
return x, draws
Which value of makes the expected value of draws as small as possible while keeping the sampler correct?
Answer format: round to 3 decimal places.
Sign in to answer questions and track your progress
Sign In