An Overview of Monte Carlo Methods
By: Christopher Pease
Tags: Machine Learning, Algorithms, Finance, Physics, Data Science

Monte Carlo (MC) methods are a subset of computational algorithms that use the process of repeated random sampling to make numerical estimations of unknown parameters. They allow for the modeling of complex situations where many random variables are involved, and assessing the impact of risk. The uses of MC are incredibly wide-ranging, and have led to a number of groundbreaking discoveries in the fields of physics, game theory, and finance. There are a broad spectrum of Monte Carlo methods, but they all share the commonality that they rely on random number generation to solve deterministic problems. I hope to outline some of the basic principles of MC, and perhaps infect you with a bit of the excitement that I have about their possible applications.

source: mathworks.com

The concept was invented by Stanislaw Ulam, a mathematician who devised these methods as part of his contribution to the Manhattan Project. He used the tools of random sampling and inferential statistics to model likelihoods of outcomes, originally applied to a card game (Monte Carlo Solitaire). Ulam later worked with collaborator John von Neumann, using newly developed computer technologies to run simulations to better understand the risks associated with the nuclear project. As you can imagine, modern computational technology allows us to model much more complex systems, with a larger number of random parameters, like so many of the scenarios that we encounter during our everyday lives. Before we consider the complicated systems however, lets talk about a simple case; a game of blackjack.

If we wanted to find the probability of getting blackjack (an ace along with a ten-valued card), we could simply count the number of possible hands where this is the case, and divide by the total number of possible combinations of cards to get the probability (its around 1/21, if you are curious). But now imagine our sample space is much harder to compute, for example our deck of cards has thousands as opposed to just 52 cards, or better yet we don’t even know how many cards there are. There is another way to find this probability.

Photo by Kay on Unsplash

We could hunker down at the table and play a hundred games, recording the outcomes as we play. We might get a blackjack 19, 20 or even 28 times, and assign the probability using any of those values. Seems like a pretty bad way to assess our odds at the casino, but hopefully we’re just playing for fun. Now if we go again and play a thousand, ten thousand, millions of times, the Law of Large Numbers states:

“As the number of identically distributed, randomly generated variables increases, their sample mean (average) approaches their theoretical mean.”

Besides being easily one of the most important laws of statistics, this is the basis for Monte Carlo simulations and allows us to build a stochastic model by the method of statistical trials. Lets look at my favorite (and probably the simplest) example of a MC estimate.

Monte Carlo Estimate of Pi

As we are all taught in grammar school geometry, pi is a constant that represents the ratio of the circumference to the diameter of a circle. It is irrational, meaning it has infinite digits which follow no pattern. Would you believe me if I told you we can estimate pi to as many digits as we like by simply playing a game of darts? To a certain degree of uncertainty, of course, after all we are playing a game of chance! Lets write a short python script to see how.

As you can see, we are generating random points within a box, and counting the number of points which fall within an embedded circle. For the sake of simplicity, we only look at the upper quadrant of our dartboard, which has a radius R and is mounted on a square piece of wood of the same width. If we throw 100 darts, and count the number of darts which successfully hit the dartboard, we might obtain the following plot.

If you’re thinking: “Why are we so bad at this?” you are asking the right question. For this example, the location of our darts must be uniformly distributed throughout the area, so we’re definitely not winning too many games here. From the setup of our game, the probability of a darts hitting the board will be π/4 . As we keep playing, and as n –> ∞ we approach this true value(Thanks Bernoulli!). We can see that this happens below as we increase n by an order of ten.