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

How to generate 3D Gaussian distribution with mean 0 covariance matrix I

220 views
Skip to first unread message

MBALOVER

unread,
Apr 3, 2010, 6:45:50 PM4/3/10
to
Hi all,

I need to generate data from a 3D Gaussian distribution with mean 0
and Covariance matrix I (identity matrix).

I read from some statistic books but they only talk about sampling a
2D Gaussian distribution, for example using Box-Muller.

The Box-Muller for 2D Gaussian can be described as

" First convert to the P(x,y) to pole-coordinates Q(theta, r) , it
will be product of two pdf of two independent RVs theta and r, where
theta is uniform distribution (0,2pi)
Then use inverse transform to generate the distribution of r. Finally
convert back to xy coordinates to get data from the desired 2D
Gaussian distribution."

The problem is that I want to extend it to 3D. Could you please guide
me how to do it?

Or please refer me to some papers, book chapters?

Thank you very much.

Regards,

Richard Startz

unread,
Apr 3, 2010, 9:01:05 PM4/3/10
to

Since you specify independent normals, just generate 3 individual,
random variables.
-Dick Startz

Ray Vickson

unread,
Apr 3, 2010, 9:38:31 PM4/3/10
to

Use Box-Mueller three times (to get six Gaussians). Take these in
groups of three, to get two of your required samples.

R.G. Vickson

C Hanck

unread,
Apr 4, 2010, 4:04:17 AM4/4/10
to
If you want another covariance matrix than Identity, say Sigma, you
can generate three independent samples and muliply these with the
Cholesky decomposition of Sigma.

Christoph

geo

unread,
Apr 4, 2010, 6:30:45 AM4/4/10
to
----------------------------------------------------------------------------------------

What is often called the Box-Muller method
is actually the generation of a point in the unit
circle, projecting it onto the unit circumference,
then into 2-D space by means of the Marsaglia
Polar Method:
Choose x,y uniform in (-1,1) until
s = x^2+y^2 < 1.
Then the point
p=(x,y)/sqrt(s)
is uniform on the unit circumference,
and---the key point--- s is independent
of p and is itself uniform in (0,1).
Thus -2*ln(s) is a chi-square-2
variate and (r*x,r*y) is a standard normal
point in the plane, with
r=sqrt(-2*ln(s)/s).

If a point p=(x,y,z) is uniform on the
surface of the unit 3-sphere, then it has been
known since Archimedes related the volumes
of spherical segments to cylinders,
that z is uniform in (-1,1), but of course
z and p are not independent, so we cannot
use z, but must get another independent uniform
variate to form a chi-3 variate that projects
p into 3-space.

However, getting the point (x,y,z) uniformly
distributed on the surface of the unit 3-sphere
may be done by the Marsaglia method,
Annal Math. Statistics, V43, No 2, 645-646:

Generate x,y uniform in (-1,1) until
s = x^2+y^2 < 1.
If t=sqrt(1-s), the point
(2xt,2yt,1-2s)
is uniform on the surface of the unit sphere,
but an additional chi-3 variate is needed
to project it into a 3-D normal point.

Whether for two or three, it is probably much faster
to get the required number of independent normal
variates by means of
the Ziggurat Method of Marsaglia and Tsang.
Journal Statistical Software, V5, Issue 8,

Gordon Sande

unread,
Apr 4, 2010, 9:15:14 AM4/4/10
to

This is a question of trying to see the forest or trying to see the trees.

The basic observation is that if you have a black box that gives you Gaussians
then use three of then to get a 3-d ditribution with unit covariance. For
other covariances you do a linear transformation. That was the forest. Or
just two for 2-d or four for ... well you get the idea.

Now for the trees. To convert a uniform random variable into a Gaussian random
variable there are awkward slow methods like inverting the cumulative and slick
quick methods. Box-Muller is slick and quick and actually does pairs.
Many black
boxes for Gaussians use Box-Muller to get a pair and then give them out one at
a time. There is no common slick quick method for triples but then there is no
real need for one given the earlier paragraph. Some think Box-Muller is awkward
amd slow as it uses inversion of cumulatives that happen to convenient
analytically.
So there are quick elaborate methods for one Gaussian. There seems to
be a small
contest to come up with the most "something" for this problem and text
books get
trapped into describing the details of such "trees" and forget the forest.

MBALOVER

unread,
Apr 4, 2010, 1:19:19 PM4/4/10
to
Great!!!, Thank you guys very much. Your answers are very clear and
helpful.

I get it and have successfully generated the data as I desire.

Thank you.

Best

0 new messages