Monte Carlo Simulation Cheat Sheet
Covers the core idea of Monte Carlo estimation, random sampling, and variance reduction, with Python examples for integration and probability estimation.
2 PagesIntermediateMar 15, 2026
Core Concepts
The building blocks of Monte Carlo methods.
- Law of large numbers- The sample average converges to the expected value as the number of samples grows
- Monte Carlo estimator- Approximates an expectation or integral by averaging over random samples
- Variance reduction- Techniques (antithetic variates, control variates, importance sampling, stratified sampling) that reduce estimator variance for a given sample size
- Convergence rate- Standard Monte Carlo error shrinks as O(1/sqrt(n)) regardless of dimensionality
- Random seed- Fixing the seed makes simulations reproducible
Estimating Pi
Classic example: estimate pi by sampling points in a unit square.
python
import numpy as npnp.random.seed(42)n = 1_000_000x, y = np.random.uniform(-1, 1, n), np.random.uniform(-1, 1, n)inside_circle = (x**2 + y**2) <= 1pi_estimate = 4 * inside_circle.sum() / nprint(f"Estimated pi: {pi_estimate:.5f}")
Monte Carlo Integration
Approximate a definite integral by averaging function values at random points.
python
import numpy as npdef f(x): return np.sin(x) * np.exp(-x / 5)a, b, n = 0, 10, 100_000samples = np.random.uniform(a, b, n)integral_estimate = (b - a) * np.mean(f(samples))std_error = (b - a) * np.std(f(samples)) / np.sqrt(n)print(f"Integral estimate: {integral_estimate:.4f} +/- {1.96*std_error:.4f}")
Variance Reduction Techniques
Get a tighter estimate without more samples.
- Antithetic variates- Pair each random sample u with 1-u to cancel out some sampling error
- Control variates- Adjust the estimate using a correlated variable whose expectation is known exactly
- Importance sampling- Sample more often from regions that contribute most to the estimate, then reweight
- Stratified sampling- Divide the domain into strata and sample each proportionally, reducing variance from clumping
Pro Tip
Always report the standard error (or a confidence interval) alongside a Monte Carlo estimate -- the point estimate alone hides how many samples you'd need to trust the third decimal place.
Was this cheat sheet helpful?
Explore Topics
#MonteCarloSimulation#MonteCarloSimulationCheatSheet#DataScience#Intermediate#CoreConcepts#EstimatingPi#MonteCarloIntegration#VarianceReductionTechniques#MachineLearning#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance