![]() The estimate is within 0.0008 of the true value, which is closer than the value from the average value method.Ĭan we conclude from one simulation that the second method is better at estimating pi? Absolutely not! Longtime readers might remember the article "How to lie with a simulation" in which I intentionally chose a random number seed that produced a simulation that gave an uncharacteristic result. PiEst2 = 4*mean(isBelow) /* proportion of (u, u2) under curve */ ![]() IsBelow = (u2 < Y) /* binary indicator variable */ The following statements continue the previous SAS/IML program: It is easy to use a Monte Carlo simulation to estimate the probability P: generate N random points inside the unit square and count the proportion that fall in the quarter circle. That is, P(point inside circle) = Area(quarter circle) / Area(unit square) = π/4. If you generate a 2-D point (an ordered pair) uniformly at random within the unit square, then the probability that the point is inside the quarter circle is equal to the ratio of the area of the quarter circle divided by the area of the unit square. You could generate a larger sample size (like a million values) to improve the estimate, but instead let's see how the area method performs.Ĭonsider the same quarter circle as before. Maybe this particular sample was "unlucky" due to random variation. This doesn't seem to be a great estimate. In spite of generating a random sample of size 10,000, the average value of this sample is only within 0.01 of the true value of pi. PiEst1 = 4*mean(Y) /* average value of a function */ Multiplying that estimate by 4 gives an estimate for pi.Ĭall randseed(3141592) /* use digits of pi as a seed! */ The following SAS/IML program generates N=10,000 uniform variates in and uses those values to estimate f avg = E(f(X)). It is easy to estimate the mean of a random variable: you draw a random sample and compute the sample mean. Recall that if X is a uniformly distributed random variable on, then Y= f( X) is a random variable on whose mean is f avg. If you can estimate the left hand side of the equation, you can multiply the estimate by 4 to estimate pi. In particular, for f( x) = sqrt(1 – x 2), the average value is π/4 because the integral is the area under the curve. In calculus you learn that the average value of a continuous function f on the interval is given by the following integral: The second is the "area method," which enables you to estimate areasīy generating a uniform sample of points and counting how many fall into a planar region. The first is the "average value method," which uses random points in an interval to estimate the average value of a continuous function on the interval. Two common Monte Carlo techniques are described in an easy-to-read article byĭavid Neal ( The College Mathematics Journal, 1993). There are dozens of ways to use Monte Carlo simulation to estimate pi. The graph of the function forms a quarter circle of unit radius. ![]() The graph of the function on the interval is shown in the plot. To compute Monte Carlo estimates of pi, you can use the function f( x) = sqrt(1 – x 2). #PiDay computation teaches lesson for every day: Choose estimator with smallest variance #StatWisdom Click To Tweet Monte Carlo estimates of pi Namely, I describe two seemingly equivalent Monte Carlo methods that estimate pi and show that one method is better than the other "on average." 197).ĭemonstrates an important principle for statistical programmers that can be applied 365 days of the year. not a serious way to determine pi" (Ripley 2006, p. This article uses a Monte Carlo simulation to estimate pi, in spite of the fact that On Pi Day, many people blog about how to approximate pi. ![]() Today's date, written as 3/14/16, represents the best five-digit approximation of pi. Today is March 14th, which is annually celebrated as Pi Day.
0 Comments
Leave a Reply. |