Try   HackMD

Gaussian random variable and CLT

To generate two independent Gaussian random variables

x and
y
we use these equation
x=σ2lnξ1cos(2πξ2),y=σ2lnξ1sin(2πξ2)

This figure show total number
N=105
Gaussian random numbers.
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

We can plot the semi-log to again verified the result.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

For generating two independent Gaussian variables

x1 and
x2
to form a distribution
y=x1+x2
, we use same approach above.I then use KDE (kernel density estimation) to fit two Gaussian distribution.

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Interesting happened when I generate

nindependent uniform random numbers
ξ1
,
ξ2
, ,
ξn
, then I measure the probability of the random variable
y=σk=1nξk
. As you can see when
n=1
it is just a uniform random distribution,
however when
n=2
or even larger number, the distribution looks gradually like Gaussian distribution. At
n=20
, it looks like a pretty decent Gaussian distribution which I use theoretical result which states that
μ=12σn2=112n

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

I then use totally different random distribution consist of one-third of exponential distribution, another one-third of uniform distribution and one-third of Gaussian distribution. The parameter are given below.

P1(x)=0.2e0.2xP2(x)=1P3(x)=12π×0.2e(xμ)22×0.2
As you can see it become Gaussian again when n is larger (roughly at
n=10
).

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Code

Gaurand

program main implicit none double precision, external :: gaurand integer, parameter :: n=100000 double precision :: x(n), sig=dsqrt(.2d0) integer :: i do i = 1, n x(i) = gaurand(sig) end do open(66, file='a.dat', status='unknown') do i = 1, n write(66, *) x(i) end do end program main function gaurand(sig) implicit none double precision, parameter :: tpi=8.d0*atan(1.d0) double precision :: a, b, gaurand, sig call random_seed() call random_number(a) call random_seed() call random_number(b) gaurand = sig * dsqrt(-2.d0 * log(a)) * dcos(tpi * b) end function

CLT

program clt implicit none integer, parameter :: n=1000, m=50 double precision :: x(n, m), y(n) integer :: i, j open(66, file='c50.dat', status='unknown') call random_seed() do i = 1, n call random_number(x) end do y = 0.d0 do j = 1, m y(:) = y(:) + x(:, j) end do y = y / m do i = 1, n write(66, *) y(i) end do end program clt
program clt implicit none double precision, external :: gaurand integer, parameter :: n=10000, m=3 double precision :: x1(n, m), x2(n, m), x3(n, m), y(n) integer :: i, j double precision :: a = .2d0 open(66, file='d3.dat', status='unknown') call random_seed() call random_number(x1) x1 = - 1.d0 / a * dlog(x1) call random_number(x2) do j = 1, m do i = 1, n x3(i, j) = gaurand(dsqrt(.2d0)) end do end do y = 0.d0 do j = 1, m y(:) = y(:) + x1(:, j) + x2(:, j)+ x3(:, j) end do y = y / m do i = 1, n write(66, *) y(i) end do end program clt function gaurand(sig) implicit none double precision, parameter :: tpi=8.d0*atan(1.d0) double precision :: a, b, gaurand, sig call random_seed() call random_number(a) call random_seed() call random_number(b) gaurand = sig * dsqrt(-2.d0 * log(a)) * dcos(tpi * b) end function