# I Sphere probability

1. Apr 8, 2016

### rabbed

Hi

If i'm using this method to generate points inside a sphere with radius K:
X = S^(1/3)*sqrt(1-V^2)*sin(O)
Y = S^(1/3)*V
Z = -S^(1/3)*sqrt(1-V^2)*cos(O)

where (0 < s < K^3), (-1 < v < 1) and (0 < o < 2*pi), i guess that:
S_PDF(s) = 1/(K^3)
V_PDF(v) = 1/2
O_PDF(o) = 1/(2*pi)

How come the joint distribution of S, V and O is 1/(4*pi*K^3)?
Shouldn't it be 1/(4*pi*K^3/3) because the volume of the sphere is 4*pi*K^3/3?

2. Apr 8, 2016

### BvU

A volume element of the sphere is $dV = r^2 \sin\theta \,dr\, d\theta\, d\phi$ so I think it's because you distribute $r^3$ evenly ...

3. Apr 8, 2016

### rabbed

Should S_PDF(s) actually be 3/(K^3) or is really SVO_PDF(s,v,o) = 1/(4*pi*K^3) in this case?

4. Apr 8, 2016

### BvU

I don't speak the jargon. But I guessed you generate a uniform distribution of $s = r^3$ and I think it should be a uniform distribution of $s = r^2$ .

5. Apr 10, 2016

### BvU

Was this useful ? I see you follow a multiple-track approach with loosely coupled threads (which is fine, it's just that I find it an interesting subject ).

6. Apr 10, 2016

### rabbed

Yeah, this is a very interesting subject :)
I haven't studied any of this in school so i'm just picking up bits and pieces from the net trying to make sense of it.
My goal at the moment is to derive the standard normal distribution in the most simple, concrete way possible while heading for the maxwell boltzmann distribution as a part of understanding machine learning.
With this thread I was thinking that since I started with formulas giving cartesian coordinates from spherical coordinates, then calculated the formulas above (giving uniform surface distribution), maybe I need to use these new formulas to fill in the constants of the "unknown" distribution N(n) = C*e^(-K*n^2) which satisfies N(x)*N(y)*N(z) = N(sqrt(x^2+y^2+z^2)), since uniform direction is needed for isotropy which is a requirement of the maxwell boltzmann distribution.
But after I posted this thread I thought that just because the joint distribution of the XYZ-components from spherical coordinates is 1/(4*pi*K^3/3) doesn't mean that the joint SVO distribution need to be the same, since they are in different coordinate systems. So maybe it was a stupid thread to begin with anyway?
Hope it made any sense :) Feel free to push me in any direction if you have experience with this.

7. Apr 10, 2016

### BvU

There's plenty of ways to get a Gaussian distribution (which can then be properly normalized to standard). A few I remember:
• as the sum limit of uniformly distributed numbers (*)
• as a limit of the binomial distribution
I think that even when they are not all that uniformly distributed you still get the gauss function, provided there are no correlations.

Last edited: Apr 12, 2016
8. Apr 11, 2016

### rabbed

Thanks, I can use those ways also to get a feel for what this distribution is.

I still think there should be a way to derive this N(n) from the formulas and PDF's involved in random vectors.
Maybe I should try some more with these formulas of (X,Y,Z) = f(S,V,O):
X = S^(1/3)*sqrt(1-V^2)*sin(O)
Y = S^(1/3)*V
Z = -S^(1/3)*sqrt(1-V^2)*cos(O)
I'm not sure how to get (S,V,O) = f^-1(X,Y,Z) though.
I know I need to substitute this in that etc., but it was a while since I did it. Do you know?

Hm, on second thought maybe it's enough if I use something like:
X = R*sqrt(1-V^2)*sin(O)
Y = R*V
Z = -R*sqrt(1-V^2)*cos(O)
Since it's the uniform direction I need and the radial distribution I want?

Last edited: Apr 11, 2016
9. Apr 11, 2016

### BvU

10. Apr 12, 2016

### rabbed

Hey

This was pretty interesting, if I got the jacobian right for these formulas:
X = s^(1/3)*sqrt(1-v^2)*sin(o)
Y = s^(1/3)*v
Z = -s^(1/3)*sqrt(1-v^2)*cos(o)
I get |J| = (v^2-v-1)/3 which has roots v = (1+/-sqrt(5))/2, the golden ratio?
Not sure what that means if it's correct. But cool :)

11. Apr 12, 2016

### rabbed

Using that Jacobian I get:

XYZ_PDF(o,v,s) = O_PDF(o) * V_PDF(v) * S_PDF(s) / | d(XYZ) / d(OVS) | = 1/(4*pi*K^3) / ((v^2-v-1)/3) = 1/(4*pi*K^3/3) * 1/(v^2-v-1)

So does that mean that it's still not uniform? XYZ_PDF(o,v,s) = 1/(volume of sphere) * 1/(v^2-v-1)
In that case, is it possible to change V_PDF(v) = 1/2 into something which accounts for 1/(v^2-v-1) so that XYZ_PDF(o,v,s) becomes uniform?

12. Apr 12, 2016

### BvU

What is it you are trying to achieve ? (remember I don't speak the jargon, so I have to pass on #11 and #12 ).

Bear in mind that if theta is uniformly distributed you definitely don't get 'uniform direction' ! That of course requires a uniform $\sin\theta$

Last edited: Apr 12, 2016
13. Apr 12, 2016

### rabbed

Sorry, I should have explained some more..
Instead of regular mathematical convention for coordinates, I'm using what I felt was intuitive from my 3D-coding background - a coordinate system where X is to the right, Y is up and Z is into the screen. For the 2D spherical coordinate system, I'm placing (0,0) at (0,0,-K) in the 3D coordinate system. From that point I wanted the positive longitude to increasing towards positive X before heading off into the screen (Z) and positive latitude to start increasing towards positive Y before heading off towards the north pole (at (0,K,0)). With that settled, this is what i've done so far:

Tried randomizing uniform points inside sphere of radius K using:
X = R*cos(A)*sin(O)
Y = R*sin(A)
Z = -R*cos(A)*cos(O)
(0 < o < 2*pi), (-pi/2 < a < pi/2), (0 < r < K)
The Jacobian | d(XYZ / d(OAR) | = r^2*cos(a) <- note that I get cos(a) instead of sin(a) because of the different coordinate convention.
O_PDF(o) = 1/(2pi)
A_PDF(a) = 1/pi
R_PDF(r) = 1/K

This didn't produce a uniform distribution of points inside the sphere:
XYZ_PDF(o,a,r) = O_PDF(o) * A_PDF(a) * R_PDF(r) / | d(XYZ) / d(OAR) | = 1/(2*pi^2*K) / (r^2*cos(a))

So I calculated new distributions for the variables in the volume element:
O_PDF(o) = 1/(2pi)
A_PDF(a) = cos(a)
R_PDF(r) = 3*r^2/K^3
Which gave me:
XYZ_PDF(o,a,r) = O_PDF(o) * A_PDF(a) * R_PDF(r) / | d(XYZ) / d(OAR) | = 3*r^2*cos(a)/(4*pi*K^3) / (r^2*cos(a)) = 1 / (the volume of the sphere)

So having the correct PDF's, I could use the inverse CDF method for A and R to create a new formula:
X = S^(1/3)*sqrt(1-V^2)*sin(O)
Y = S^(1/3)*V
Z = -S^(1/3)*sqrt(1-V^2)*cos(O)
(0 < o < 2*pi), (-1 < v < 1), (0 < s < K^3)
The Jacobian | d(XYZ) / d(OVS) | = (v^2-v-1)/3
O_PDF(o) = 1/(2*pi)
V_PDF(v) = 1/2
S_PDF(s) = 1/K^3

But now I get:
XYZ_PDF(o,v,s) = O_PDF(o) * V_PDF(v) * S_PDF(s) / | d(XYZ) / d(OVS) | = 1/(4*pi*K^3) / ((v^2-v-1)/3) = 1/(4*pi*K^3/3) * 1/(v^2-v-1) =
1 / (the volume of the sphere) * 1/(v^2-v-1)
So does that mean that I still don't get a uniform distribution, or is it just not uniform relative to this new OVS-space in some way?

I'm hoping that changing V_PDF(v) = 1/2 into something else will give me XYZ_PDF(o,v,s) = 1 / (the volume of the sphere) and that it'll will bring me closer to the standard normal distribution the way I explained before. There should be a connection here, since I've read that normalizing a 3D-vector of components coming from a standard normal distribution will give me uniform points on the surface of the sphere.

Does it make any sense?

14. Apr 12, 2016

### rabbed

I calculated | d(XYZ) / d(OVS) | again in a program and came up with | d(XYZ) / d(OVS) | = 1/3, which is probably correct and gives XYZ_PDF(o,v,s) = 1 / (the volume of the sphere), so no luck there..

I think the best bet would be to investigate formulas where the direction is uniform and the radial distribution should be found, by setting up the different conditions of the radial distribution R_PDF(r):

X = R*sqrt(1-V^2)*sin(O)
Y = R*V
Z = -R*sqrt(1-V^2)*cos(O)
| d(XYZ) / d(OVR) | = r^2
O_PDF(o) = 1/(2*pi)
V_PDF(v) = 1/2
R_PDF(r) = N(r)

XYZ_PDF(o,v,r) =
O_PDF(o) * V_PDF(v) * R_PDF(r) / | d(XYZ) / d(OVR) | =
1/(2*pi) * 1/2 * N(r) / r^2 = N(r) = N(x)*N(y)*N(z)

N(n) = C*e^(-K*n^2)

The goal being to find C (and then K, somehow) without knowing about the normal distribution beforehand

Last edited: Apr 13, 2016