Quiz 2

Importance Sampling and Variance Reduction

105 words
1 min read
Python Week 1: the first filter for runtime behavior
Visual companion
Python
Type and operator map

Python Week 1: the first filter for runtime behavior

View
Revision summary

What this note is really saying

Short form

# Importance Sampling and Variance Reduction ## Importance Sampling Estimate $E_f[h(X)]$ by sampling from $g(x)$ instead of $f(x)$: $$ \hat{\theta} = \frac{1}{n} \sum_{i=1}^n h(X_i) \frac{f(X_i)}{g(X_i)} $$ ## Control Variates If $E[U] = \mu_U$ known, use $Y_{CV} = Y - \beta(U - \mu_U)$. Optimal $\beta = \text{Cov}(...

Importance Sampling and Variance Reduction

Importance Sampling

Estimate Ef[h(X)]E_f[h(X)] by sampling from g(x)g(x) instead of f(x)f(x):
θ^=1ni=1nh(Xi)f(Xi)g(Xi)\hat{\theta} = \frac{1}{n} \sum_{i=1}^n h(X_i) \frac{f(X_i)}{g(X_i)}

Control Variates

If E[U]=μUE[U] = \mu_U known, use YCV=Yβ(UμU)Y_{CV} = Y - \beta(U - \mu_U). Optimal β=Cov(Y,U)/Var(U)\beta = \text{Cov}(Y, U) / \text{Var}(U).
python
import 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}")
Document outline

Keep your place and jump directly to a heading.

Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.