All problems
Exponential Mixture Composition (Seeded)
Problem
Sample from a two-component exponential mixture using the composition method: with probability p1 draw from Exponential(lam1), otherwise from Exponential(lam2). Return the seeded sample mean over n draws. Return 0.0 for invalid inputs.
Hint
Choose the component first, then sample from it with a second uniform.
Test cases
case 1
in: [1,2,0.5,20000,42]
expected: 0.7507352428918592
case 2
in: [1,2,0.5,20000,7]
expected: 0.7461103728816006
case 3
in: [3,0.5,0.7,10000,1]
expected: 0.8352886808240652
case 4
in: [1,2,0.5,0,0]
expected: 0
Starter codePython
import math
import random
def composition_sample_mean(lam1, lam2, p1, n, seed):
# Your code here
pass4 test cases · run your code against them in the editor