Monte Carlo Methods
306 words
2 min read
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
# Monte Carlo Methods ## 🎯 Learning Objectives - Understand the law of large numbers and its role in Monte Carlo - Estimate integrals using Monte Carlo simulation - Compute confidence intervals for Monte Carlo estimates - Implement variance reduction techniques * * * ## 1.1 Intuition: Estimating by Random Sampling...

Monte Carlo Methods
🎯 Learning Objectives
- Understand the law of large numbers and its role in Monte Carlo
- Estimate integrals using Monte Carlo simulation
- Compute confidence intervals for Monte Carlo estimates
- Implement variance reduction techniques
1.1 Intuition: Estimating by Random Sampling
Monte Carlo methods use random sampling to estimate quantities that are difficult to compute analytically. The idea: generate many random samples, compute the statistic, and average.
🔑 Key Insight: The law of large numbers guarantees that Monte Carlo estimates converge to the true value as sample size increases.
1.2 Monte Carlo Integration
Estimate θ=∫abf(x)dx:
Where Ui∼Uniform(a,b).
pythonimport numpy as np # estimate integral of sin(x) from 0 to pi n = 10000 x = np.random.uniform(0, np.pi, n) estimate = np.pi * np.mean(np.sin(x)) print(f"MC estimate: {estimate:.4f}, true: 2.0")
1.3 Variance Reduction
Antithetic Variates
Use negatively correlated pairs: U and 1−U.
pythonu = np.random.uniform(0, 1, n//2) estimates = (f(u) + f(1-u)) / 2
Control Variates
Leverage known expectation of a correlated variable.
1.4 Confidence Intervals
θ^±zα/2nsWhere s is the sample standard deviation of the Monte Carlo estimates.
✅ Practice Questions
Q1: Estimate ∫01exdx using MC with 10000 samples.
Solutionpythonimport numpy as np x = np.random.uniform(0, 1, 10000) estimate = np.mean(np.exp(x)) # since (b-a) = 1 print(estimate) # approx 1.718 (true: e-1 = 1.71828)
Q2: How does the MC error decrease with n?
SolutionMC error ∝σ/n. To halve the error, quadruple n (this is the curse of MC — slow convergence). Join Discord NextImportance Sampling