Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: gaussian distribution

61 views
Skip to first unread message
Message has been deleted

Barry W Brown

unread,
May 14, 2012, 2:52:44 PM5/14/12
to
On Monday, May 14, 2012 1:31:01 PM UTC-5, Elaheh wrote:
> Hi
> I need some random numbers from an uniform distribution like gaussian
> distribution.
> How can I employ this distribution in fortran 90?
>
> Thanks in advance.

Our library, RANDLIB, contains random number generators for many statistical
distributions including the uniform and Gaussian (although not for a
uniform like Gaussian). It is written in Fortran95 and is available free
from
biostatistics.mdanderson.org/SoftwareDownload

Barry W Brown

Richard Maine

unread,
May 14, 2012, 6:58:36 PM5/14/12
to
Elaheh <elaheh...@gmail.com> wrote:

> I need some random numbers from an uniform distribution like gaussian
> distribution.
> How can I employ this distribution in fortran 90?

Note that the Gaussian and uniform are different distributions, so it
doesn't make much sense to describe something as "uniform like
Gaussian".

Also note that it makes a *LOT* of difference whether you want a
Gaussian distribution or something "like" it. There are several popular
methods for Gaussian. If you want more general distributions, your
options might be far more restricted.

I see that Barry Brown posted a link to a package of routines, so I
won't go dig one up.

--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain

Phillip Helbig---undress to reply

unread,
May 15, 2012, 3:59:20 AM5/15/12
to
In article <1kk3df7.1uxr8npnv5kkiN%nos...@see.signature>,
nos...@see.signature (Richard Maine) writes:

> Note that the Gaussian and uniform are different distributions, so it
> doesn't make much sense to describe something as "uniform like
> Gaussian".

It is relatively easy to get a random number from a Gaussian
distribution once one has one from a uniform distribution.

Or, if you have some spare CPU cycles, just build the sum on N random
numbers from a uniform distribution and divide by N. As N approaches
infinity, the sums so built approach a Gaussian distribution.

Of course, this is not very efficient. However, it does illustrate WHY
error distributions are often Gaussian (i.e. they are the sums of
random, uncorrelated errors).

Thomas Jahns

unread,
May 15, 2012, 4:36:46 AM5/15/12
to
On 05/14/2012 08:31 PM, Elaheh wrote:
> I need some random numbers from an uniform distribution like gaussian
> distribution.

I take "like" to mean "as well" here, otherwise it doesn't make sense. I also
assume you are satisfied with non-cryptographically secure, pseudo-random,
otherwise you might want to look into some library like OpenSSL.

> How can I employ this distribution in fortran 90?

real :: u
call random_number(u)

random_number will give you a pseudo-random number under a uniform distribution
regime.

In case you already have two random numbers u and v from a uniform distribution
(0.0,1.0), you might try the algorithm from wikipedia to obtain a
normal-distributed number r.

real, parameter :: pi = 3.1415
r = mean + variance * sqrt(-2.0 * log(u)) * cos(2.0 * pi * v)

Hint: you might want look into the distribution random_number actually gives
you, also pi is probably not given exactly enough in my example.

Regards, Thomas

Paul Anton Letnes

unread,
May 15, 2012, 7:00:55 AM5/15/12
to
On 14.05.12 20:31, Elaheh wrote:
> Hi
> I need some random numbers from an uniform distribution like gaussian
> distribution.
> How can I employ this distribution in fortran 90?
>
> Thanks in advance.


There's always the Box--Muller transform. It turns uniformly distributed
random numbers into normal gaussian distributed ones. (See other
comments on what "uniform distribution" means, too.)

https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform

Paul

e p chandler

unread,
May 15, 2012, 11:57:12 AM5/15/12
to


"Phillip Helbig---undress to reply" wrote in message
news:jot2co$vr4$1...@online.de...
---> It's not that difficult to calculate the exact pdf and cdf for the sum
of two uniforms or three uniforms. For three, it is remarkably close to a
standard normal. But the practical drawback to this method, which was once
proposed and once used, is that the tails will be too light.

-- e

Gordon Sande

unread,
May 15, 2012, 2:00:45 PM5/15/12
to
On 2012-05-15 12:57:12 -0300, e p chandler said:

> "Phillip Helbig---undress to reply" wrote in message
> news:jot2co$vr4$1...@online.de...
>
> In article <1kk3df7.1uxr8npnv5kkiN%nos...@see.signature>,
> nos...@see.signature (Richard Maine) writes:
>
>> Note that the Gaussian and uniform are different distributions, so it
>> doesn't make much sense to describe something as "uniform like
>> Gaussian".
>
> It is relatively easy to get a random number from a Gaussian
> distribution once one has one from a uniform distribution.
>
> Or, if you have some spare CPU cycles, just build the sum on N random
> numbers from a uniform distribution and divide by N. As N approaches
> infinity, the sums so built approach a Gaussian distribution.

You scaling is off but otherwise a sort of a statement of the Central Limit
Theorem but only worth partial marks in an undergraduate course. You divide
by the standard deviation which is grows like sqrt( N ) as your scaling yields
all values at zero. The correction to the mean is half N. See below for the
mindless version.

> Of course, this is not very efficient. However, it does illustrate WHY
> error distributions are often Gaussian (i.e. they are the sums of
> random, uncorrelated errors).

A sum of Cauchy variates does not behave so well so there are some technical
regularities involved. A Cauchy is the ratio of two standard Gaussians and has
infinite variance. The infinite variance comes from the "dividing by zero"
and is all too common in ratios of statisitcs.

> ---> It's not that difficult to calculate the exact pdf and cdf for the
> sum of two uniforms or three uniforms. For three, it is remarkably
> close to a standard normal. But the practical drawback to this method,
> which was once proposed and once used, is that the tails will be too
> light.
>
> -- e

For those in a hurry and willing to tolerate some amount of approximation a
common rule is to sum 12 uniforms and subtract 6. The result has a mean of zero
and a variance of 1. The 12 gives the variance of 1 and the approximateion does
get beyond + or - 3 now and then but never beyond + or - 6.

This rule is a common instant mindless approxiamtion to a standard Gaussian.


glen herrmannsfeldt

unread,
May 15, 2012, 3:48:05 PM5/15/12
to
e p chandler <ep...@juno.com> wrote:

(snip)
> It is relatively easy to get a random number from a Gaussian
> distribution once one has one from a uniform distribution.

> Or, if you have some spare CPU cycles, just build the sum on N random
> numbers from a uniform distribution and divide by N. As N approaches
> infinity, the sums so built approach a Gaussian distribution.

http://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution

I remember reading about this one before I even knew about Normal
distributions. It is commonly done by adding up 12 uniformly
distributed values and subtracting six, which approximates the usual
normalized Gaussian with variance of 1.0. (The variance is N/12.)

> Of course, this is not very efficient. However, it does illustrate WHY
> error distributions are often Gaussian (i.e. they are the sums of
> random, uncorrelated errors).

Depending on the speed of COS, SIN, LOG, and SQRT, it could be a
lot faster than Box-Muller.

> ---> It's not that difficult to calculate the exact pdf and cdf for the sum
> of two uniforms or three uniforms. For three, it is remarkably close to a
> standard normal. But the practical drawback to this method, which was once
> proposed and once used, is that the tails will be too light.

Tails are always the problem. While Box-Muller should give pretty
good tails, though they do somewhat depend on how close to uniform
the uniform generator is for smaller values. But to get good tails,
you need a really large number of samples.

-- glen

Paul Anton Letnes

unread,
May 16, 2012, 1:47:03 AM5/16/12
to

>> Of course, this is not very efficient. However, it does illustrate WHY
>> error distributions are often Gaussian (i.e. they are the sums of
>> random, uncorrelated errors).
>
> Depending on the speed of COS, SIN, LOG, and SQRT, it could be a
> lot faster than Box-Muller.

Without going into the "speed" debate, I'd like to point out that
Box-Muller can be done without any COS or SIN.
https://en.wikipedia.org/wiki/Box_muller

There's only one SQRT and one LOG evaluation, at most. That should help
performance a bit, too.

Paul
0 new messages