Introduction

The Montre Carlo Method was invented in the late 1940s by Stanislaw Ulam, they were used at Los Alamos for early work relating to the development of the hydrogen bomb, and became popularized in the fields of physics, physical chemistry, and operations research.

The Montre Carlo Method used for drawing a sample at random from the empirical distribution. The oldest well-known example is that of the Buffon’s needle, where supposing a needle of the same length as the width between cracks we have: implying , the is a constant.

What is a Monte Carlo Method?

In physics and statistics many of the problems Monte Carlo is used on is under the form of the estimate of an integral unkown in closed form: , which can be seen as the evalutaion of , where .

The hit-or-miss Monte Carlo method generates random points in a bounded graph and counts the number of ‘hits’ or points that are in the region whose area we want to evaluate, . As shown in the Buffon’s needle, the can be calculated by the sumilation.

Here, one of the simulations of by function MC.hitormiss()in the animation package is shown. This function can generate uniform random numbers and compute the proportion of points under the curve. Consider a circle inscribed in a unit square. Given that the circle and the square have a ratio of areas that is , the value of can be approximated using a Monte Carlo method. We only need to counts the number of ‘hits’ or points that are in the circle, the .

library(animation)
ani.options(nmax = 200)
f = function(x) sqrt(1 - x^2)
P = MC.hitormiss(f, from = 0, to = 1)$est
Pi = P * 4
Pi
## [1] 3.064

Note

This function is for demonstration purpose only; the integral might be very inaccurate when n is small.

ani.options('nmax') specifies the maximum number of trials.

Reference

1.Monte Carlo,http://www-stat.stanford.edu/~susan/courses/s208/node14.html



Published

30 April 2013

Tags