help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: radial gaussian distribution


From: Ted Harding
Subject: Re: radial gaussian distribution
Date: Tue, 20 Sep 2005 15:27:06 +0100 (BST)

On 20-Sep-05 roberto wrote:
> On 9/20/05, Ted Harding <address@hidden> wrote:
>> On 20-Sep-05 roberto wrote:
>> > Hello,
>> > i have to generate a gaussian distribution of points which depends
>> > only on the distance from a fixed point O, that is i need a radial
>> > gaussian distribution;
>>
>> If you want a bivariate gaussian distribution (i.e. (X,Y) are
>> jointly gaussian) where the probability density depends only
>> on the distance r = sqrt((x-x0)^2 + (y-y0)^2) from a fixed
>> point (x0,y0), then you are in fact dealing with a "circular"
>> (or, in 3 dimensions, "spherical", etc.) gaussian distribution.
>>
>> So, if 's' is the marginal standard deviation of either X or Y
>> (i.e. s^2 is the variance),
>> 
>>  [x0 + s*randn(N,1)  y0 + s*randn(N,1)]
>> 
>> will generate a matrix of N rows, each with 2 elements(X,Y)
>> where X and Y are independent, each with variance s^2, with
>> X centred on x0 and Y on y0, so that the centre of (X,Y is
>> (x0,y0) and their joint distrubution is centred on (x0,y0).
>>
> thank you for your clear answer;
> i restate my need: my problem is i want to compute a certain function
> "c(r)" on a set of points gaussian-distributed around an origin O(0,0)
> on a two dimensional region and whose distance from this point O is
> just r;
> 
> in my opinion the codes posted before both achieve the same result: 
> - one generate the following "r" variable using "randn":
> r = R*randn(N,1);
> with width "R"
> on which i have to compute my function c(r);
> 
> and this "r" should correspond to the other one (posted by Ted)
> r = sqrt((x-x0)^2 + (y-y0)^2)
> 
> made up of two gaussian distributed x and y coordinates;
> so, once i got this set of points gaussian distributed around O(0,0)
> with distance r from O, i will compute my c(r) on them,
> 
> hope i have been simpler in my explanation and tell me if something
> still not clear thank you for any help

Be careful, Roberto! The "solution"

  r = R*randn(N,1);

(followed by "x = r.*sin(phi); y = r.*cos(phi);" to generate
corresponding x and y coordinates) posted by Shai Ayal is in fact
not correct for what you want!

If you were in 1 dimension, then it would be OK since there is
no distinction between r and |x| when x has a gaussian distribution.

In 2 or more dimensions, however, if the coordinates (x,y,...)
have gaussian distributions then the radius 'r' does not have
a gaussian distribution (whereas Shai's suggestion would make
it have such a distribution).

In fact the distribution of r^2 in 2 dimensions [or k dimensions]
is what is called the "chi-squared distribution with 2 [or k]
degrees of freedom", provided the (x,y,...) are independent and
have zero means and equal variances.

Octave already has a function

  chisquare_rnd

which will generate random variables of this kind, so e.g.

  r = sqrt(chisquare_rnd (n, r, c))

would generate an rxc matrix of suitable distributed values of r.

The advantage of using a more "primitive" method such as the
one I suggested is that you can easily vary the underlying
assumptions.

For instance, if x and y did not have the same variance, then
you could multiply the first set of values (for x) by s1, and
the second set (for y) by s2, say, as in

  [s*randn(N,1)  s2*randn(N,1)]

If the variances are the same but the means (x0,y0) are not zero,
then you get what I gave before:

  [x0 + s*randn(N,1)  y0 + s*randn(N,1)]

If what you wanted was the function c(r) where r is the distance
from (0,0) to (x,y), but the gaussian distributions are centred on
(x0,y0), then you simply take the sqrt of (the square of column 1
plus the square of column 2).

And so on.

When (x0,y0) is not (0,0) then the distribution of r^2 is no longer
the simple chisquared, but a "non-central chisquared" with
"non-centrality parameter" equal to (x0^2 + y0^2). This is a
difficult distribution to generate directly (i.e. without passing
through the constituent gaussian distributions in a preliminary stage),
and since it is so simple to do it as described you might as well take
that route.

Hoping this helps,
Ted.


--------------------------------------------------------------------
E-Mail: (Ted Harding) <address@hidden>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Sep-05                                       Time: 15:26:48
------------------------------ XFMail ------------------------------



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]