POV-Ray : Newsgroups : povray.advanced-users : Normal distribution Server Time
27 Dec 2024 23:41:39 EST (-0500)
  Normal distribution (Message 1 to 10 of 13)  
Goto Latest 10 Messages Next 3 Messages >>>
From: Andrew C on Mozilla
Subject: Normal distribution
Date: 5 May 2004 17:01:21
Message: <40995621@news.povray.org>
POV-Ray's random number generator gives uniformly distributed real numbers.

Any idea how to transform these into normally distributed numbers?

Andrew @ home.


Post a reply to this message

From: Warp
Subject: Re: Normal distribution
Date: 5 May 2004 17:14:10
Message: <40995922@news.povray.org>
Andrew C on Mozilla <voi### [at] devnull> wrote:
> POV-Ray's random number generator gives uniformly distributed real numbers.

  Actually no. It gives uniformly distributed real numbers between 0 and 1,
which is a slightly different thing.

  (And we can also split hairs by noting that floating points numbers aren't
real numbers but a finite set of rational numbers, but would not be relevant
here... :) )

> Any idea how to transform these into normally distributed numbers?

  You can approximate a normal distribution of numbers between 0 and 1
by taking the sum of n equally-distributed numbers and dividing the
result by n. The higher the n, the more closely it resembles normal
distribution, but for practical purposes you don't need a very large n.
Even n=3 already gives a pretty good distribution.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: Warp
Subject: Re: Normal distribution
Date: 5 May 2004 17:16:35
Message: <409959b3@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>   You can approximate a normal distribution of numbers between 0 and 1
> by taking the sum of n equally-distributed numbers

(which are between 0 and 1, of course)

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: ingo
Subject: Re: Normal distribution
Date: 5 May 2004 18:15:35
Message: <Xns94E12A3B686Eseed7@news.povray.org>
in news:40995621@news.povray.org Andrew C on Mozilla wrote:

> Any idea how to transform these into normally distributed numbers?
> 

From "rand.inc"

Rand_Normal(Mu, Sigma, Stream). Normal distribution.
Parameters: 
Mu = Mean. 
Sigma = Standard deviation. 
Stream = Random number stream. 

Rand_Gauss(Mu, Sigma, Stream). Gaussian distribution. Like Rand_Normal
(), but a bit faster.
Parameters: 
Mu = Mean. 
Sigma = Standard deviation. 
Stream = Random number stream. 


Ingo


Post a reply to this message

From: Chris Johnson
Subject: Re: Normal distribution
Date: 5 May 2004 21:47:07
Message: <4099991b$1@news.povray.org>
-[You can approximate a normal distribution of numbers...]-
...but this is an inefficient method. The standard method is the Box-Muller
transform, given here in C.

float v1,v2,rsq,fac;
do
{
  v1=rand()*2.0-1.0; v2=rand()*2.0-1.0;
  rsq=v1*v1+v2*v2;
} while (rsq>=1.0 || rsq==0.0)
fac=sqrt(-2.0*log(rsq)/rsq);

This generates two independent normal deviates (v1*fac) and (v2*fac) (with
zero mean and unit variance). The "rand()" function here generates uniform
deviates between 0 and 1.


-[...and dividing the result by n]-
Actually, with this method you need to divide by sqrt(n) if you want to keep
the variance independent of n.

-Chris


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Normal distribution
Date: 6 May 2004 14:49:14
Message: <409a88aa$1@news.povray.org>
>>POV-Ray's random number generator gives uniformly distributed real numbers.
> 
>   Actually no. It gives uniformly distributed real numbers between 0 and 1,
> which is a slightly different thing.

Well yeah, but you know what I *mean* ;-)

>   (And we can also split hairs by noting that floating points numbers aren't
> real numbers but a finite set of rational numbers, but would not be relevant
> here... :) )

True. (I do recall asking how far apart these numbers are, but never 
really got an answer...)

>>Any idea how to transform these into normally distributed numbers?
> 
>   You can approximate a normal distribution of numbers between 0 and 1
> by taking the sum of n equally-distributed numbers and dividing the
> result by n. The higher the n, the more closely it resembles normal
> distribution, but for practical purposes you don't need a very large n.
> Even n=3 already gives a pretty good distribution.

...because the means of different samples from a given population are 
normally distributed around the true mean of the population? (And the 
true mean of a *truely* uniform distribution from 0 to 1 would be 0.5)

Andrew @ home.


Post a reply to this message

From: Andrew C on Mozilla
Subject: Re: Normal distribution
Date: 6 May 2004 14:49:41
Message: <409a88c5$1@news.povray.org>
> From "rand.inc"
> 
> Rand_Normal(Mu, Sigma, Stream). Normal distribution.
> Parameters: 
> Mu = Mean. 
> Sigma = Standard deviation. 
> Stream = Random number stream. 
> 
> Rand_Gauss(Mu, Sigma, Stream). Gaussian distribution. Like Rand_Normal
> (), but a bit faster.
> Parameters: 
> Mu = Mean. 
> Sigma = Standard deviation. 
> Stream = Random number stream. 

Ah... yes, that's easier! ;-)

Andrew @ home


Post a reply to this message

From: Chris Johnson
Subject: Re: Normal distribution
Date: 6 May 2004 16:30:36
Message: <409aa06c@news.povray.org>
-[I do recall asking how far apart these numbers are]-
Pov-ray uses the IEEE double floating point standard (unless you're
compiling it on a DEC VAX or something obscure), which has 52 bits of
fractional precision, which gives about 2^-52 as the distance between random
numbers. However, pov-ray actually uses a 32-bit linear congruential random
number generator, which only uses 32 bits of precision.

-[because the means of different samples from a given population are
normally distributed around the true mean of the population]-
Yes - or rather, they approach a normal distribution as the number in each
sample tends to infinity (the Central Limit Theorem)

-Chris


Post a reply to this message

From: Christopher James Huff
Subject: Re: Normal distribution
Date: 6 May 2004 20:32:34
Message: <cjameshuff-486021.19315106052004@news.povray.org>
In article <4099991b$1@news.povray.org>,
 "Chris Johnson" <chris(at)chris-j(dot)co(dot)uk> wrote:

> -[You can approximate a normal distribution of numbers...]-
> ...but this is an inefficient method. The standard method is the Box-Muller
> transform, given here in C.

If you can easily generate a few random numbers and don't need a very 
close approximation, the averaging method can be faster. The problem 
isn't really efficiency, it's accuracy...the result isn't all that close 
to a normal distribution unless you use lots of points and rescale the 
numbers to get out of the range of the original numbers.


> -[...and dividing the result by n]-
> Actually, with this method you need to divide by sqrt(n) if you want to keep 
> the variance independent of n.

In the places where this approximation is used, that is rarely a 
problem. It's often more useful to have a known range that the random 
numbers are limited to. It's a very fast and easy way to get objects to 
bunch up around a point with a roughly Gaussian distribution.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

From: Christopher James Huff
Subject: Re: Normal distribution
Date: 7 May 2004 08:47:28
Message: <cjameshuff-E9E2AE.07464607052004@news.povray.org>
In article <409aa06c@news.povray.org>,
 "Chris Johnson" <chris(at)chris-j(dot)co(dot)uk> wrote:

> -[I do recall asking how far apart these numbers are]-
> Pov-ray uses the IEEE double floating point standard (unless you're
> compiling it on a DEC VAX or something obscure), which has 52 bits of
> fractional precision, which gives about 2^-52 as the distance between random
> numbers.

Not quite correct. You're forgetting that floating point numbers are not 
fixed point...they're quite a bit more complicated. In addition to the 
52-bit plus-one mantissa, IEEE 754 double precision numbers also have an 
11 bit exponent, which can go down to -1023 and up to 1024. You end up 
with a pretty complex distribution of possible numbers...just how big a 
step there is between a value and the next possible larger or smaller 
value depends on what that value is.


> However, pov-ray actually uses a 32-bit linear congruential random
> number generator, which only uses 32 bits of precision.

At most, it may be even less. Assuming it fills the entire 32 bit range, 
that gives you 2^32 steps, 4294967296 steps with 2.328306436538696e-10 
between each step.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

Goto Latest 10 Messages Next 3 Messages >>>

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.