Uncertainty calculation for calculating pi using Monte Carlo integration

In summary, the code calculates pi using accept&reject monte carlo integration. It finds the area of a unit circle around points that are randomly chosen and counts the number of points that fall within the unit circle. The ratio of the number of points that fall within the unit circle to the total number of trials is equal to pi / 4. 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.
  • #1
googlygluon
2
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 propogation? Thanks in advance.
 
Physics news on Phys.org
  • #2
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 [itex]\pi[/itex], 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.
 
  • #3
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, probabilty 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'.
 
  • #4
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 propogation? 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.
 
  • #5
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 [itex]\pi[/itex], 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.
 
  • #6
Thanks everyone, I appreciate your help.
 

1. How does Monte Carlo integration work for calculating pi?

Monte Carlo integration is a method of approximating the value of pi by randomly selecting points within a square and determining the proportion that fall within a quarter of a circle inscribed in the square. By repeating this process with a large number of points, the estimated value of pi approaches the true value.

2. What is the formula for uncertainty calculation in Monte Carlo integration?

The formula for uncertainty calculation in Monte Carlo integration is σ = (√N/N) * (4P - P2), where σ represents the uncertainty, N is the number of points used, and P is the proportion of points that fall within the quarter circle.

3. How many points are needed in Monte Carlo integration to accurately estimate pi?

The number of points needed in Monte Carlo integration depends on the desired level of accuracy. Generally, the more points that are used, the more accurate the estimation of pi will be. A good rule of thumb is to use at least 10,000 points for a reasonable approximation.

4. Are there any limitations to using Monte Carlo integration for calculating pi?

One limitation of Monte Carlo integration for calculating pi is that it is a probabilistic method, meaning there is always a level of uncertainty in the results. Additionally, the method can be computationally intensive and may not be practical for very large numbers of points.

5. How can I improve the accuracy of my pi estimation using Monte Carlo integration?

To improve the accuracy of your pi estimation using Monte Carlo integration, you can increase the number of points used, use a more sophisticated random number generator, or adjust the size and shape of the square and quarter circle. It is also important to carefully analyze and reduce any sources of bias in the process.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
12
Views
1K
  • Advanced Physics Homework Help
Replies
1
Views
1K
  • Advanced Physics Homework Help
Replies
11
Views
2K
  • Programming and Computer Science
Replies
1
Views
662
  • Set Theory, Logic, Probability, Statistics
Replies
2
Views
744
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
1K
Replies
0
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
  • High Energy, Nuclear, Particle Physics
Replies
2
Views
1K
Back
Top