Uncertainty calculation for calculating pi using Monte Carlo integration

Click For Summary

Homework Help Overview

The discussion revolves around calculating the value of pi using Monte Carlo integration and estimating the associated uncertainty. The original poster describes a method involving pseudo-random points to approximate pi and seeks clarification on how to compute the variance for their results.

Discussion Character

  • Exploratory, Assumption checking, Conceptual clarification

Approaches and Questions Raised

  • Participants discuss various methods for estimating uncertainty, including running multiple trials with different random seeds and calculating standard deviation. Some question the original poster's understanding of variance and error propagation in the context of their Monte Carlo method.

Discussion Status

The discussion is active, with participants offering different perspectives on how to approach the uncertainty calculation. There is no explicit consensus, but several viable methods have been suggested, including the use of binomial distribution properties and relative probability calculations.

Contextual Notes

Participants note that the uncertainty should scale with the number of trials, and there is a discussion about the assumptions regarding the randomness of the points generated. The original poster's approach and understanding of variance are also under scrutiny.

googlygluon
Messages
2
Reaction score
0

Homework Statement


I wrote a code that calculates pi using accept&reject monte carlo integration. It picks -1000000000 pseudo-random points (x,y), and counts the number of points that fall within a unit circle (let's call that number k).

The ratio of k/ N (N = Number of trials = 1000000000) is equal to pi / 4 (the area of the circle / the area of the square around it).

I wish to find the variance so that I may present my result as 3.14158 +- [uncertainty].

The Attempt at a Solution



Now, since this is a random (pseudo random really, but anyway) process, the uncertainty should be 1 / sqrt(N). Am I mistaken? Do I have to calculate the variance for both x and y and use error propagation? Thanks in advance.
 
Physics news on Phys.org
The best way to estimate the uncertainty on your measurement would be to run the program several times, for various random seeds. This will give you a series of measurements of \pi, which you can then compute the mean and standard deviation of. The standard deviation should scale as the inverse square root of the number of trials.
 
The most exact way would be to use probability (assuming a true random uniform generator). Calculate the probability of finding a particular value of 'pi', the value where the probability falls to 1/e or 1/2 can be used as your error.

To calculate this probability, you can use the known probability of a random point being outside or inside the circle. For eg. with n random points, the probability of finding the value of pi as zero would be the case where all points fall outside, probability being (1 - area of circle/total area)^n

For other values there will be more than one case, but you should be able to generalize it and find an expression for any particular value of pi.

Note: when I say probability, I mean relative probability, relative to probability of getting value as 'pi'.
 
googlygluon said:
Now, since this is a random (pseudo random really, but anyway) process, the uncertainty should be 1 / sqrt(N). Am I mistaken? Do I have to calculate the variance for both x and y and use error propagation? Thanks in advance.

The uncertainty scales as 1/sqrt(N), but the proportionality factor is not 1.

We're trying to find the standard deviation of a binomial distribution with n samples, where the two outcomes are "inside the circle" and "outside the circle". It's just sqrt(npq), where p is the probability of a certain point being inside the circle (which is pi/4), and q is the probability of the point being outside.

This means that, with n samples, n*pi/4 +- sqrt(npq) will be inside the circle. Dividing the equation by the relevant constant will give you the right bounds on pi.
 
Mute said:
The best way to estimate the uncertainty on your measurement would be to run the program several times, for various random seeds. This will give you a series of measurements of \pi, which you can then compute the mean and standard deviation of. The standard deviation should scale as the inverse square root of the number of trials.

Bear in mind that this is the only method mentioned above which doesn't require you to already know the value of pi.
 
Thanks everyone, I appreciate your help.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K