Integration and Probability
Lab 3: Integration and Probability
Integration connects calculus to probability: probability densities are defined by integrals, expected values are integrals, entropy is an integral. This lab makes those connections concrete — you will compute integrals numerically and analytically, verify the Fundamental Theorem, and recover the key probabilistic quantities you will use throughout the rest of the platform.
What You'll Build
- A trapezoidal integrator from scratch and a convergence plot showing error vs number of trapezoids, confirming the rate
- A Fundamental Theorem verifier: compare computed numerically vs from the analytic antiderivative, for several and interval pairs
- A Gaussian normalization check: numerically integrate the standard normal PDF over (using a wide finite range) and confirm the result is 1 — then verify the 68–95–99.7 rule by integrating over , ,
- A Monte Carlo integrator: estimate by sampling uniform points in the unit square and checking whether they fall in the unit circle (area ), then plot how the estimate improves with sample count
- A KL divergence calculator: numerically integrate for two Gaussians with different means, confirming non-negativity and asymmetry ()
Key Concepts Practiced
By the end you will understand that the probabilistic quantities from the probability-foundations module — PDFs, expected values, KL divergence — are all just integrals, and that numerical integration via Monte Carlo sampling is why those quantities are tractable in high-dimensional ML systems.