Skip to content
DeepForgeby svx
All problems
HardProbabilitypr-225

Antithetic Variates Estimate (Seeded)

Problem

Estimate E[exp(U)] for U uniform on (0, 1), whose exact value is e - 1, using n antithetic pairs. For each pair draw u with random.Random(seed), average exp(u) and exp(1 - u), and return the overall mean.

Return 0.0 for n <= 0.

Hint

The two values of each pair are negatively correlated because exp is monotone.

Test cases

case 1
in: [20000,42]
expected: 1.718325754686535
case 2
in: [20000,7]
expected: 1.7184331002239301
case 3
in: [100,0]
expected: 1.7132295901718049
case 4
in: [0,5]
expected: 0
Starter codePython
import math
import random


def antithetic_variate_estimate(n, seed):
    # Your code here
    pass

4 test cases · run your code against them in the editor