Skip to main content

5.7b Variance-reduction labs

Source: Lab ideas from Computational Physics (Landau, Páez, Bordeianu), §5.7. Rewritten as original drills. Continues 5.7 Monte Carlo variance reduction.

Control variate on [0,1][0,1] for f(x)=e−xf(x)=e^{-x}, g(x)=1−xg(x)=1-x, J=1/2J=1/2. Exact value I=1−e−1I=1-e^{-1}. Use the chapter LCG only.

Fixed LCG

r ← (1103515245 * r + 12345) % 2**31, then uniform r / 2**31. Default seed 1. Advance the state before each draw.

Formula refresh​

Warm up: pick the matching equation among lookalikes (same walk as the theory lesson).

Labs​

Activity: Plain mean-value MC

Estimate I=∫01e−x dxI=\int_0^1 e^{-x}\,dx by I≃1N∑i=1Ne−xiI\simeq\frac{1}{N}\sum_{i=1}^{N} e^{-x_i} with xi∼U[0,1)x_i\sim U[0,1), with the chapter LCG, seed 11, N=1000N=1000. Print with 10 decimals.

No input.

Write-ups​

0/4 solved
5.7b.W1

Using “peak”, “zero”, and “waste”, explain:

Why does a peaked integrand waste uniform Monte Carlo samples?

Minimum 3 words. Your answer must include: “peak”, “zero”, “waste”.

0 words/ 3 min

Meet the writing requirements, then you can open the model answer.

Explorers​

# control_variate.py — original sketch (not a textbook listing)
M = 2**31

def plain_and_cv(N, seed=1):
r, s_f, s_res = seed, 0.0, 0.0
for _ in range(N):
r = (1103515245 * r + 12345) % M
x = r / M
fx = __import__('math').exp(-x)
s_f += fx
s_res += fx - (1.0 - x)
return s_f / N, s_res / N + 0.5

Next: 5.8 Importance sampling.