random value from a probability distribution
Author Message random value from a probability distribution

I would like to choose a value for X by drawing a random number from a
probability distribution.. in fortran77..
I have 201 values possible for a variable X. for each of this value I
have calculated a probability distribution and I would like to picks a
value for X from this probability distribution..
Thank you.

Sat, 12 Jan 2008 02:17:43 GMT  random value from a probability distribution

"to draw a random number from a probability distribution"

Quote:
>I would like to choose a value for X by drawing a random number from a
> probability distribution.. in fortran77..
> I have 201 values possible for a variable X. for each of this value I
> have calculated a probability distribution and I would like to picks a
> value for X from this probability distribution..
> Thank you.

You don't say what your pdf is, or what your budget is.

Possibilities:

1. NAG library - www.nag.co.uk
2. IMSL library
If you are at a university you should have access to one or the other of
these.

3. Numerical Recipes - www.nr.com

4. Netlib - www.netlib.org
4.1    ACM TOMS
4.2    Random numbers library
4.3    SLATEC

5. Statcodes - www.astro.psu.edu/statcodes

6. Alan Miller's website - http://users.bigpond.net.au/amiller

Sat, 12 Jan 2008 05:47:26 GMT  random value from a probability distribution

Quote:
> I would like to choose a value for X by drawing a random number from a
> probability distribution.. in fortran77..
> I have 201 values possible for a variable X. for each of this value I
> have calculated a probability distribution and I would like to picks a
> value for X from this probability distribution..
> Thank you.

It sounds as though you want to draw samples from a probability
distribution that you supply.

Do a Google search on "Walker's alias method". There is a particularly
informative explanation by George Marsaglia of a refinement he calls
the "Robin Hood" method!

Sorry, I don't have any Fortran code but there is some code posted in
C/C++

Ref:

Alastair J. Walker
An Efficient Method for Generating Discrete Random Variables with
General Distributions
ACM Transactions on Mathematical Software (TOMS)
3(3):253-256, Sep 1977.

or Knuth's "The Art of Computer Programming", vol 2, 2nd ed, p.115
[exercise 7]

Sat, 12 Jan 2008 06:18:29 GMT  random value from a probability distribution

Quote:
> I would like to choose a value for X by drawing a random number from a
> probability distribution.. in fortran77..
> I have 201 values possible for a variable X. for each of this value I
> have calculated a probability distribution and I would like to picks a
> value for X from this probability distribution..
> Thank you.

I think maybe you mean that X can take discrete values, and you have
determined the probability p(i) that X takes the value x(i), such that
Sum(p(i),i=1,201) = 1.0.

First generate a value R from a uniform distribution, using the random
number generator that your Fortran compiler supplies (you can do better
than this, but I doubt that you care).  This is a value between 0 and 1.

You then want to find the number k such that:
Sum(p(i),i=1,k-1) < R
and
Sum(p(i),i=1,k) >= R

The value of X corresponding to R is then x(k).

Gib
------------ And now a word from our sponsor ---------------------
For a secure high performance FTP using SSL/TLS encryption

Sat, 12 Jan 2008 12:21:48 GMT  random value from a probability distribution

Quote:

> > I would like to choose a value for X by drawing a random number from a
> > probability distribution.. in fortran77..
> > I have 201 values possible for a variable X. for each of this value I
> > have calculated a probability distribution and I would like to picks a
> > value for X from this probability distribution..
> > Thank you.

> It sounds as though you want to draw samples from a probability
> distribution that you supply.

> Do a Google search on "Walker's alias method". There is a particularly
> informative explanation by George Marsaglia of a refinement he calls
> the "Robin Hood" method!

Note: Marsaglia's post from 3/8/1999 has some errors. The figures have
been slightly messed up. The values for table T are incorrect. It is
not exactly clear where they come from. This method generates a pseudo
random variable using *one* uniform variate U. So the cutoff values in
each bin have to be adjusted because they are *conditional*
probabilities, and their range depends on the bin that they are in!

So the actual values for table T are

(0+15/20)/5,(1+19/20)/5,(2+20/20)/5,(3+12/20)/5,(4+3/20)/5.

If a second uniform variate V, uniform on (0,1) was used instead, then
the cutoff values would be 15/20,19/20,20/20,12/20,3/20.

Sat, 12 Jan 2008 13:39:12 GMT  random value from a probability distribution
Thank you very much for your help!

Sat, 12 Jan 2008 22:31:24 GMT

 Page 1 of 1 [ 6 post ]

Relevant Pages