Neural Sync Active
Importance Sampling and Variance Reduction
Registry Synced
Importance Sampling and Variance Reduction
105 words
1 min read
Reading compass
Now · Importance Sampling
Importance Sampling and Variance Reduction
Importance Sampling
Estimate Ef[h(X)] by sampling from g(x) instead of f(x):
Control Variates
If E[U]=μU known, use YCV=Y−β(U−μU).
Optimal β=Cov(Y,U)/Var(U).
pythonimport numpy as np # Control variate: use known mean of U u = np.random.uniform(0, 1, 1000) y = np.exp(u) # want to estimate integral of e^x u_mean = 0.5 beta = np.cov(y, u)[0,1] / np.var(u) y_cv = y - beta * (u - u_mean) print(f"Var(Y): {np.var(y):.4f}, Var(Y_CV): {np.var(y_cv):.4f}")