博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Introduction To Monte Carlo Methods
阅读量:7082 次
发布时间:2019-06-28

本文共 4654 字,大约阅读时间需要 15 分钟。

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 . 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.  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 , and for visualizing it in Processing .

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.

 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. 

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

3. Kevin Murphy’s .

转载地址:http://zdlml.baihongyu.com/

你可能感兴趣的文章
Delphi内嵌汇编语言BASM精要(转帖)
查看>>
ASP.NET MVC 在控制器中接收视图表单POST过来的数据方法
查看>>
云计算这么火,但市场发展依然存在着7大障碍
查看>>
Oracle 11g AMM与ASMM切换
查看>>
bootstrap-wysiwyg中JS控件富文本中的图片由本地上传到服务器(阿里云、七牛、自己的数据库)...
查看>>
H3 BPM SharePoint解决方案
查看>>
[原]linux 修改 hostname 立即生效
查看>>
图片抖动效果(兼容)
查看>>
windows查看端口占用情况
查看>>
ASA NAT Priority
查看>>
ping -R和traceroute的测试
查看>>
10.python网络编程(解决粘包问题 part 2)
查看>>
自动移动域中计算机到目标OU的脚本
查看>>
grep/sed/awk实战
查看>>
nagios图像(pnp4nagios)
查看>>
如何清除Xcode8打印的系统日志
查看>>
RAID概述
查看>>
mysql主从复制
查看>>
PHPWAMP站点管理的“域名模式”和“端口模式”详解、均支持自定义
查看>>
date(时间),timedatectl(时区),cal(日历)的用法
查看>>