• Support PF! Buy your school textbooks, materials and every day products via PF Here!

Monte Carlo integration

  • Thread starter Sonden
  • Start date
1. The problem statement, all variables and given/known data
I am supposed to calculate/estimate pi using a Monte Carlo method. This is of course trivial: create N uniformly distributed random pairs (x,y) in [0,1]^2 and check how many, M, that have x^2+y^2<1. Then M/N=pi/4.

Now, the strange thing is that I am not supposed to do it that way. Instead I'm supposed to use a double integral (Monte Carlo integration): "At a first glance, this may not seem like a integration problem, but it can be formulated as such. Write down the (double) integral (and thus the expected value) that correspond to this procedure, i.e. the integral I = 4E[g(X)] = pi", where E[g(X)] is the expected value for a function g and X a random variable. I've glanced at it for several hours now, I still haven't got a clue how to do it. Of course,
[tex]\int_0^1 \int_0^{2 \pi}rdrd\theta=\pi[/tex]
but is this useful here?
 
2,956
4
This seems dumb, since the upper bound of the integral w.r.t. [itex]\theta[/itex] contains the mathematical constant you are trying to evaluate. I think your initial approach is correct.
 

vela

Staff Emeritus
Science Advisor
Homework Helper
Education Advisor
14,380
1,075
I think your original idea, the one you ruled out, is the method intended in the problem. It is essentially evaluating a double integral. Why do you think you're not supposed to do it that way?
 

HallsofIvy

Science Advisor
Homework Helper
41,667
858
1. The problem statement, all variables and given/known data
I am supposed to calculate/estimate pi using a Monte Carlo method. This is of course trivial: create N uniformly distributed random pairs (x,y) in [0,1]^2 and check how many, M, that have x^2+y^2<1. Then M/N=pi/4.

Now, the strange thing is that I am not supposed to do it that way. Instead I'm supposed to use a double integral (Monte Carlo integration): "At a first glance, this may not seem like a integration problem, but it can be formulated as such. Write down the (double) integral (and thus the expected value) that correspond to this procedure, i.e. the integral I = 4E[g(X)] = pi", where E[g(X)] is the expected value for a function g and X a random variable. I've glanced at it for several hours now, I still haven't got a clue how to do it. Of course,
[tex]\int_0^1 \int_0^{2 \pi}rdrd\theta=\pi[/tex]
but is this useful here?
Useful? If that weren't true this method of approximating [itex]\pi[/itex] wouldn't work!

The whole point is that since that integral is equal to [itex]\pi[/itex], approximating that integral, with a Monte Carlo method, approximates [itex]\pi[/itex].
 
vela: because the teacher wants MC *integration* (that the unit circle's area is pi perhaps follows from integration but...). :)

Is this true?:

4 times the expected value for a function g(X,Y), where X, Y are random variables with some probability distribution f(x,y), is

[tex]4E[g(X,Y)]=4\int\int_{\mathbb{R}^2}g(x,y)f(x,y)dxdy[/tex]

Then if f(x,y)=1/4 in [-1,1]^2 and 0 elsewhere,

[tex]4\int\int_{\mathbb{R}^2}g(x,y)f(x,y)dxdy=\int\int_{[-1,1]^2}g(x,y)dxdy[/tex].

Now if g(x,y)=1 inside the unit circle and 0 elsewhere, we get

[tex]4E[g(X,Y)]=\int\int_{unit \; circle}dxdy=\pi[/tex]

so

[tex]\pi/4=E[g(X,Y)] \approx 1/N\sum_{i=1}^N g(x_i,y_i)[/tex]

according to the law of large numbers (I think?), where (x_i, y_i) are random pairs with f:s distribution, ie they are uniformly distributed on [-1,1]^2 and g(x_i,y_i)=1 if they are inside the unit circle, ie if x_i^2+y_i^2<1, and g(x_i,y_i)=0 otherwise (that is, between the unit circle and [-1,1]^2). Is this derivation correct?
 
Last edited:

vela

Staff Emeritus
Science Advisor
Homework Helper
Education Advisor
14,380
1,075
You do realize, I hope, that you essentially just rederived the "trivial" method you alluded to in your first post.
 
But this time I used the law of large numbers, so I know that I can get as close to pi as I wish by taking N large enough. Which was obvious from the start, but still... ;)
 
2,956
4
If you denote:

[tex]
I(A) = \left\{\begin{array}{ll}
1&, A \, \mathrm{occurs} \\

0 &, \bar{A} \, \mathrm{occurs}
\end{array}\right.
[/tex]

the indicator of a random event A ([itex]P(A) = p, P(\bar{A}) = q, \, p + q = 1[/itex]), then:

[tex]
E(I) = 1 \cdot p + 0 \cdot q = p
[/tex]

and

[tex]
\sigma^{2}(I) = (1 - p)^2 \cdot p + (0 - p)^2 \cdot q = p q^{2} + p^{2} q = p q (p + q) = p q = p(1 - p) \le \frac{1}{4}
[/tex]

Thus, this random variable satisfies the provisions of the Law of Large numbers and the sample mean is a good estimate of the probability of the event.
 
Last edited:

Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving
Top