# Integration of a 2D Gaussian

1. Jul 10, 2015

This is a seemingly simple question, though I'm not exactly sure where I'm going wrong (if in fact I am going wrong).

To start off: you have a 2D un-normalized Gaussian function centred at the origin and with a sigma of 4. If you integrate it over a circle of radius 4 also centred at the origin, you will get a value. Let's call this value A. Then, if you integrate this same un-normalized function, but now over a circle of radius 7 once again centred at the origin, you will get another value. Let's call this value B.

Now, for a regular normal distribution, within 1 standard deviation of the mean is 0.68 of all data points. Within two standard deviation is 0.95 of all data points. In this case, a circle of radius 4 should contain 0.68 of all data points, and a circle of radius 8 should contain 0.95 of all data points, right? Using this logic, since a circle of radius 7 would contain less data points than a circle of radius 8, shouldn't A/B > 0.68/0.95?

I am currently doing a computation involving this same problem. I've done a few conversions to ensure the equation is in cylindrical coordinates, and there seems to be no problem. I even plug in points corresponding to the same points in space and get the same answer. I even did the integration earlier over the same spaces in X,Y and R,θ and got the same answers. Yet I am doing this exact problem and finding that A/B is less than 0.68/0.95. This has made me second guess my work, but I feel like I am not seeing the entire picture. Is there something I am overlooking here? Is normalization necessary if I am always working with the same amplitude? Any advice you have is greatly appreciated!

2. Jul 11, 2015

### jasonRF

A zero-mean 2D Gaussian has 3 parameters, $\sigma_x, \sigma_y, r_{x,y}$. When you say the sigma is 4 what do you mean? Are you saying
$\sigma_x = \sigma_y = 4$ and $r_{x,y}=0$?

EDIT: the text below does NOT answer your question - I was thinking you were integrating over a square, in which case the ratio will be the square of the 1D case. Integrating over a circle is more complicated ... in any case your ratio should not be the same as in the 1D case.

If so, then note that when you do the 2d integral, the x and y integrals can be separated so you effectively have a product of two 1-D integrals. What does that tell you about how the 2D results should compare to the 1D results?

jason

Last edited: Jul 11, 2015
3. Jul 12, 2015

I've been looking at this problem for very long now and I think I have found the problem on my end. But I don't quite understand exactly why this is happening. Originally, what I did was convert an un-normalized 2D Gaussian (I'll call this f1) from Cartesian to Cylindrical coordinates (I'll call this f2). This conversion seemed fine and to test it out I plugged in numerous points (at the same point in space) into f1 and f2 and found I got the same values. I also plotted f2 on polar axes and also found it was the same in shape as f1 plotted on Cartesian axes. Now, the next thing I did was try to integrate both f1 and f2 over the same intervals in space. I am using an integration function from Python to do this. When I complete the integration, though, I find two things:

1. I would always compare the integration of f2 in polar coordinates (which is done on Python) with f1's integration in Cartesian coordinates on WolframAlpha. When I integrate f2 in r and theta in Python, to get the same answer as the integration in WolframAlpha, I would have to multiply the integrand by r. This seemed to make sense since when switching from Cartesian to Polar, the Jacobian of this transformation is equal to r.

2. When I did a simple task of assigning a particular sigma, I tried to find the fractional value of the integration values. For example, I set sigma = 4 (i.e. I let sigmax = sigmay = 4) and I integrated f2 over a circle of radius 4 centred at the origin and got a value (I'll call this value A). I then did the same thing (i.e. I let sigmax = sigmay = 4) but integrated f2 over a circle of radius 8 centred at the mean (I'll call this C). To be more specific, when I integrated f2 without multiplying the integrand by r, I'll call this A1 and C1. When I did multiply the integrand by r, the values I got I will call A2 and C2. Now, what I found was that A1/C1 = 0.68/0.95 while A2/C2 != 0.68/0.95.

Point 2 seems to contradict point 1, which seems to imply my function (f2) simply isn't right. f2 seems to be analogous to f1, though, so maybe my equation for f1 is simply wrong, too. (I have shown f1 centred at the origin with a sigma = 4 and integrated over a circle of radius 4 and also radius 8 in the WolframAlpha file attached.)

I can clarify the code I used and the exact general equations for f1 and f2 if wanted, but just want to ensure if anything I have done above sounds wrong in logic. Namely, if I covert the function from cartesian to polar coordinates, then to get equivalent answers when integrating f1 and f2 over the same space, shouldn't f2 be multiplied by r before it's integrated to yield the appropriate transformation? Shouldn't A2/C2 = 0.68/0.95 in that case?

I've attached an example of what A2/4 should equal (since it's only a fourth of the space and the Gaussian is symmetric in x and y). What I find odd is that when I integrate f2 over the same space and multiply it by r, I get the exact same value. But when I don't multiply it by r, and then integrate, I get a different value (5.376 to be exact, if it's 1/4 of the the entire circle of radius 4 again).

Please let me know if you would like any further clarification. I just can't figure out why the integration seems to work perfectly when I multiply the integrand by r, but it doesn't give me the right fraction in terms of 0.68/0.95. I also checked what the integration of f2 over a radius of 8 should be (1/4th of the space again) on WolframAlpha and it shows that 9.88896/21.73 is once again not equal to 0.68/0.95, which the ratio of circular Gaussian integrated over a circle of radius = sigma1 and radius = sigma2 should equal, right? Everything I'm doing on WolframAlpha seems to match up with what I get when I integrate f2 after multiplying it by r. So maybe there's an error you can possibly spot in the function I put in the WolframAlpha image I attached?

#### Attached Files:

File size:
1.4 KB
Views:
93
• ###### Screen Shot 2015-07-12 at 7.21.53 PM.png
File size:
1.4 KB
Views:
80
Last edited: Jul 12, 2015
4. Jul 12, 2015

### jasonRF

I'm thinking your integration is probably fine. What I was trying to say above is that I would not expect the ratio to be the same as in the 1D case at all (eg. if you integrated over a square instead of a circle, the ratio would be the square of what it was for the 1D case).

jason

5. Jul 12, 2015

Hmm...I don't quite follow, though you maybe fully right. As shown in the attached file, wouldn't a function of the type $e^{-(x^2 + y^2)/2 \sigma^2}$ have 0.68 of all its data points within a circle of radius $\sigma$ centred at the origin since $\sigma _x = \sigma _y$? Going from 1D to 2D is simply an extension of the normal distribution, but all its properties would still hold valid, right? The equation above is analogous to $e^{-(x^2)/2 \sigma^2}$ so wouldn't the fraction of an integration over $1\sigma$ and $2\sigma$ in either 1D or 2D be the same? Isn't a circle the of radius $\sigma$ in 2D equivalent to the interval [-$\sigma$,$\sigma$] in 1D if the Gaussian itself has a circular base (not a square like you mentioned)?

Essentially something like this (just for clarity's sake--the scales are off, I'm just talking about the general shape of the two functions):

1D: http://www.icn.ucl.ac.uk/courses/MA.../html/complex_stimuli_tutorial3_gabors_01.png
2D: http://campar.in.tum.de/twiki/pub/Chair/HaukeHeibelGaussianDerivatives/gauss2d00.png

What I find odd is that when I multiply the integrand (of the function in polar coordinates) by r and take the integral over the circle of radius $\sigma$ and also divide that by the integral over a circle of radius $2\sigma$ (both centred at the origin), I don't get the value as 0.68/0.95 (I will have to do the computation again to check the exact answer, but it's closer to the squared value, like you said). But when I do the same operation as above but do NOT multiply the integrand by r, I get 0.68/0.95.

I seem to be missing exactly why that's the case. Any further explanation or references to other material would be greatly appreciated!

Last edited: Jul 12, 2015
6. Jul 13, 2015

### jasonRF

When you do the change of variables in 2D, $dx \, dy$ goes to $r \, d\theta \, dr$. If you do not include the $r$ then you are doing something wrong and your answer is meaningless. In your case, the $\theta$ integral is simply $2 \pi$ for both numerator and denominator, so when you do the integral incorrectly (leave out the r) then of course the ratio is the same as the 1D case because the remaining integrals look the same as in the 1D case. But again, this is wrong.

jason

7. Jul 13, 2015

Absolutely. Okay, that makes sense since integrating from 0 to 2$\pi$ would be equivalent to the 1D integration in just dr. Thank you! I was erroneously thinking something was true when it most certainly is not.

Yes, you're right. When I integrate the 2D Gaussian with $\sigma = 4$ over $[-\sigma,\sigma]$ in both the x- and y-axes and also compare this to the integration over $[-2\sigma,2\sigma]$ in both the x- and y-axes, I do get the answer to be ~$(0.68/0.95)^2$. I guess this clarifies the concept that 0.68 of the data will not be found within a 1 sigma radius from the origin of the 2D Gaussian (also centred at the origin in this case) nor will it be found from the space $[-\sigma,\sigma]x[-\sigma,\sigma]$.

If anything I have stated above in this post seems inaccurate, please just let me know. Thank you once again for all the help!

#### Attached Files:

File size:
1.8 KB
Views:
88
• ###### Screen Shot 2015-07-13 at 10.19.09 AM.png
File size:
1.7 KB
Views:
78
8. Jul 13, 2015