In general, the conversion function between two distributions g(x) and h(y) is,

g(x)dx=h(y)dy

By integration on both side, we have

G(x) = H(y) \Rightarrow y=H^{-1}(G(x))=f(x)

We are going to show a generation of uniform distribution on a Disk first. We set the distribution g(x) = 1 be a uniform distribution form (0,1). From the polar coordinate, we have,

dx dy=rdrd\theta

the right side is the unit area element in polar coordinate. We can set dy = d\theta, h(r) = r, thus,

H(r) = r^2/2 \Rightarrow x=r^2/2 \Rightarrow f(x)=\sqrt(2x)

in Mathematica,

n=10000;
θ=RandomReal[{0,2 pi},n];
f[x_]:=Sqrt[x];
r=Table[f[RandomReal[{0,1}]],{i,1,n}];
disk=Table[r[[i]]{Cos[θ[[i]]],Sin[θ[[i]]]},{i,1,n}]
ListPlot[disk]

Screenshot from 2016-01-29 17:00:46.png

 

Similarly, For a uniform sphere,

dxdydz=r^2dr sin(\theta)d\theta d\phi

Thus we have,

f_{r}(x) = (3x)^{1/3}, f_{\theta}(y)=Cos^{-1}(2y-1), f_{\phi}(z)=z

Advertisements