Sridhar Srinivasan
3 min readJul 2, 2021

--

Monte Carlo Integration to estimate AUC of a normal curve

Monte Carlo integration is a way of computing the definite integral of a function i.e. a way of getting the area under a curve. This post applies Monte Carlo integration to compute probabilities using normal distribution.

Monte Carlo simulation

Monte Carlo algorithms are used in many branches of science to estimate quantities that are difficult to calculate exactly. Monte Carlo simulations are just a way of estimating a fixed parameter by repeatedly generating random numbers. By taking the random numbers generated and doing some computation on them, Monte Carlo simulations provide an approximation of a parameter where calculating it directly is impossible or prohibitively expensive.

Normal Distribution

This is also known as the Gaussian Distribution or the bell curve. It is a symmetrical distribution which occurs naturally in many fields such as heights of adults and scores in exams.

The density curve of this continuous distribution is given by:

Pseudo code

· Select an upper limit (Zu) and a lower limit(Zl)

· Generate 100,000 sample points for horizontal axis in this range

· Generate matching 100,000 points for vertical axis between 0 to 1/sqrt(2*pi)

· This forms a rectangle with area = (Zu-Zl) * 1/sqrt(2*pi)

· For each point, check if it falls under the curve or not using the pdf

· Calculate the area under curve as the proportion of the rectangle area

Example:

· Compute the area under a normal curve between Z values of -1.96 and 1.96

· Zu — Zl = 1.96 — (-1.96) = 3.92

· Height of rectangle is 1/sqrt(2Pi) = 0.3989

· Area of the rectangle is 3.92 * 1/sqrt(2Pi) = 2.372

· Total # of points = 100,000 of which points which fell under the normal curve between -1.96 and 1.96 is 60695, or 60.695% of the generated points

· Therefore, area under the curve is 2.372 * 0.60695 = 0.9492

This is close to the theoretically expected value of 0.95

The code used for this post is available in my github @sridharsrini

Let me know your views and if you found this interesting.

--

--