Introduction To Monte Carlo Methods

I’m going to keep this tutorial light on math, because the goal is just to give a general understanding.

The idea of Monte Carlo methods is this—generate some random samples for some random variable of interest, then use these samples to compute values you’re interested in.

I know, super broad. The truth is Monte Carlo has a ton of different applications. It’s used in product design, to simulate variability in manufacturing. It’s used in physics, biology and chemistry, to do a whole host of things that I only partially understand. It can be used in AI for games, for example the chinese game Go. And finally, in finance, to evaluate financial derivatives or option pricing [1]. In short—it’s used everywhere.

The methods we use today originated from the Manhattan Project, as a way to simulate the distance neutrons would travel through through various materials [1]. Ideas using sampling had been around for a little while, but they took off in the making of the atomic bomb, and have since appeared in lots of other fields.

The big advantage with Monte Carlo methods is that they inject randomness and real-world complexity into the model. They are also more robust to adjustments such as applying a distribution to the random variable you are considering. The justification for a Monte Carlo method lies in the law of large numbers. I’ll elaborate in the first example.

The examples I give are considered simple Monte Carlo. In this kind of problem we want to know the expected value of some random variable. We generate a bunch of these random variables and take their average. The random variable will often have a probability distribution.

Estimating Pi

We can use something called the random darts method, a Monte Carlo simulation, to estimate pi. Here is my R code for this example.

The logic goes as follows—

If we inscribe a circle in a square, where one side length of the square equals the diameter of the circle we can easily calculate the ratio of circle area to square area.

Now if we could estimate this value, we would be able to estimate pi.

We can do this by randomly sampling points in the square, and calculating the proportion of those inside the circle to the total points. So I just calculate red points over total points, and multiply by 4.

Now as the number of points increases, the closer our value will get to pi.

This is a very simple example of a Monte Carlo method at work.

Simulating Traffic

Here is a more useful example. We can simulate traffic using the Nagel–Schreckenberg model. In this model, we have a road, which is made up by cells or spaces and contains a speed limit, and then a certain number of cars. We iterate through the cars and update their velocity based on the four following rules. Note – a car’s velocity = v.

  1. Cars not at the maximum velocity will increase their velocity by one unit.
  2. We then assess the distance d between a car and the car in front of it. If the car’s velocity is greater than or equal to the distance, we adjust it’s velocity to d-1.
  3. Now we add some randomization. This is the step that makes it Monte Carlo-esque. With a probability p, we will reduce the cars velocity by 1.
  4. Then, we move the car up v units.

This model is simple, but it does a pretty good job of simulating traffic behavior. It doesn’t deal with accidents or bad drivers; it’s purpose is to assess those times when traffic just appears and vanishes without any apparent reason. More sophisticated models exist, but many of them are based on this model.

View my code for getting the simulated data here, and for visualizing it in Processing here.

I love how some of the “cars” are right on the bumper of the one in front of it, and others are just chilling out taking their time. Haha

Challenges with Monte Carlo Methods

The first big challenge for Monte Carlo is how to come up with independent samples for whatever distribution your dealing with. This is a harder than you might think. In my code I just called R or Python’s built in random functions, but sampling can become much more sophisticated. That is a lot of what you will read about from more academic sources.

Here is a link on how R’s built in uniform sampling distribution works.

Another problem is getting the error to converge. Notice with the pi example how the error stopped converging quickly for the latter part of the graph. Most Monte Carlo applications just use really large samples due to low computing costs to compensate.

Monte Carlo methods are an awesome topic to explore, and I hope this post popularizes them even a little bit more (outside of finance and physics, that is).

Sources

1. Wikipedia

2. Art Owen’s textbook on the subject. My favorite resource so far.

3. Kevin Murphy’s textbook.

Introduction To Monte Carlo Methods的更多相关文章

  1. 强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods)

    强化学习读书笔记 - 05 - 蒙特卡洛方法(Monte Carlo Methods) 学习笔记: Reinforcement Learning: An Introduction, Richard S ...

  2. Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)

    Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)  部分翻译自“Monte Carlo Tree Search and Its Applicati ...

  3. History of Monte Carlo Methods - Part 1

    History of Monte Carlo Methods - Part 1 Some time ago in June 2013 I gave a lab tutorial on Monte Ca ...

  4. Monte Carlo methods

    Monte Carlo methods https://zh.wikipedia.org/wiki/蒙地卡羅方法 通常蒙地卡羅方法可以粗略地分成两类:一类是所求解的问题本身具有内在的随机性,借助计算机 ...

  5. 增强学习(四) ----- 蒙特卡罗方法(Monte Carlo Methods)

    1. 蒙特卡罗方法的基本思想 蒙特卡罗方法又叫统计模拟方法,它使用随机数(或伪随机数)来解决计算的问题,是一类重要的数值计算方法.该方法的名字来源于世界著名的赌城蒙特卡罗,而蒙特卡罗方法正是以概率为基 ...

  6. Ⅳ Monte Carlo Methods

    Dictum:  Nutrition books in the world. There is no book in life, there is no sunlight; wisdom withou ...

  7. PRML读书会第十一章 Sampling Methods(MCMC, Markov Chain Monte Carlo,细致平稳条件,Metropolis-Hastings,Gibbs Sampling,Slice Sampling,Hamiltonian MCMC)

    主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:05:00  今天的主要内容:Markov Chain Monte Carlo,M ...

  8. (转)Markov Chain Monte Carlo

    Nice R Code Punning code better since 2013 RSS Blog Archives Guides Modules About Markov Chain Monte ...

  9. 马尔科夫链蒙特卡洛(Markov chain Monte Carlo)

    (学习这部分内容大约需要1.3小时) 摘要 马尔科夫链蒙特卡洛(Markov chain Monte Carlo, MCMC) 是一类近似采样算法. 它通过一条拥有稳态分布 \(p\) 的马尔科夫链对 ...

随机推荐

  1. 基于系统的UIMenuController的使用及自定义UIMenuItem

    1.前言 在开发中 UIMenuController 用得较少,偶尔遇到了,一时竟想不起来,因此做个回顾 2.系统默认支持 UIMenuController 的UI控件 UITextField UIT ...

  2. 数据挖掘:实用机器学习技术P295页:

    数据挖掘:实用机器学习技术P295页: 在weka软件中的实验者界面中,新建好实验项目后,添加相应的实验数据,然后添加对应需要的分类算法 ,需要使用多个算法时候重复操作添加add algorithm. ...

  3. 数据结构与算法课程作业--1014. Translation

    这道题思想很简单,就是用map将foreign的作为键值,english的值作为对应的映射值,然后通过直接用foreign作为map对象的下标直接查找. 本题比较烦人的一点就是输入数据,我使用了get ...

  4. CustomMessageBox使用总结

    开发过程中难免要使用到消息框,然而系统提供的MessageBox却难以满足许多需求.一.MessageBox的背景颜色无法更改,这就无法满足需求要求的消息框颜色.二.MessageBox的提示形式过于 ...

  5. 《iptables详解 》RHEL6

          iptables详解    Iptables原理 现在防火墙主要分以下三种类型:包过滤.应用代理.状态检测 包过滤防火墙:现在静态包过滤防火墙市面上已经看不到了,取而代之的是动态包过滤技术 ...

  6. [sql server] 如何阻止SELECT * 语句

    我们每个人都知道是个不好的做法,但有时我们还是要这样做:我们执行SELECT * 语句.这个方法有很多弊端: 你从你的表里返回每个列,甚至后期加的列.想下如果你的查询里将来加上了VARCHAR(MAX ...

  7. C# 解析XML格式的字符串

    public CreateOrderReturnResult GetCreateOrderReturnApi() { var result = new CreateOrderReturnResult( ...

  8. PHPcms 摘要

    一  常量 /** *  主要定义了路径常量,项目中经常用到 **/ define('PHPCMS_PATH',dirname(__FILE__).DIRECTORY_SEPARATOR);// 项目 ...

  9. UDP HelloWord

    Client.cpp #include <stdio.h> #include <winsock2.h> #pragma comment (lib,"ws2_32&qu ...

  10. CLR via C# 线程基础知识读书笔记

    1.线程的开销 a.线程内核对象 b.线程环境块 c.用户模式栈(1MB) d.内核模式栈 f.DLL线程连接和线程分离通知 2.线程的优先级由进程优先级和线程优先级共同组成 3.进程中所有的前台线程 ...