← ~/visualizations

monte-carlo-methods

Visualizes expectations as integrals under a target distribution p(x), then approximates E_p[f(X)] with Monte Carlo averages. The animation alternates between direct sampling (X~p) and importance sampling (X~q with weights p/q), while a live error panel shows the characteristic 1/√N accuracy scaling and how variance controls estimator noise.

canvasclick to interact
t=0s

practical uses

  • 01.Estimating integrals that are hard to compute analytically (Bayesian posteriors, high-dimensional integrals)
  • 02.Simulation-based forecasting and risk estimation (finance, queueing, reliability)
  • 03.Rendering/light transport and probabilistic inference with importance sampling

technical notes

Pure Canvas2D. Uses a closure to maintain sample state and running variance (Welford). Densities are drawn on [-1,1] with block-snapped geometry for a retro grid aesthetic; samples accumulate over time and the estimator/error panels update each frame. The “true” expectation is approximated via dense quadrature for a stable reference.