代写代考 2022/10/20 11:53 (5) IEOR E4404 001 – Ed Lessons

2022/10/20 11:53 (5) IEOR E4404 001 – Ed Lessons
View options
Show slides Show questions Show responses
Submitted Saved

Copyright By PowCoder代写 加微信 powcoder

Discussion is set to require approval for new threads
[,:] be _ s(0., 0) print(np.mean(X, axis=0))
Download PDF
IEOR E4404 001 – Ed Lessons
What is the expected runtime of this algorithm? Well, it will be the number of 1s in the array, plus one, unless we have X_n =1, in which we case we will know that we don’t have to generate an additional geometric random variable.
So this has expectation: E[∑ Xi + 1∣Xn =
0]P(Xn =0)+E[∑Xi∣Xn =1]P(Xn =1)= p(n − 1) + 1 = pn + (1 − p). This suggests a small optimization: if p < 0.5, we proceed as before; if p > 0.5, use q = (1-p) as the parameter for the geometric random variable, and swap the 1s and 0s in the above algorithm.
Sampling a Binomial Random
In the last section, we showed a method for generating n independent Bernoulli(p) random variables. Clearly, we can use the method to generate a Binomial(n,p) by taking their sum.
However, we could also directly exploit the inverse cdf transformation to sample Binomials. There is, of course, no closed-form formula for the binomial cdf, so we will have to do something like this:
Step 1: U ∼ Unif(0, 1)
Step 2: i = 0, let pr = (ni )pi ∗ (1 − p)n−i , F =
Step 3: If U ≤ F return X = i
Step 4: i = i + 1, pr = pr + (ni )pi ∗ (1 − p)n−i, F = F + pr
Step 5: go to step 3
Using this method, we make X + 1 comparisons, giving us an expected number of iterations of np + 1.
https://edstem.org/us/courses/25500/lessons/42347/preview

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com