Re: random numbers with gamma distribution [message #13343] |
Mon, 09 November 1998 00:00 |
Alejandro C. Frery
Messages: 2 Registered: March 1998
|
Junior Member |
|
|
In fact T. Osborn is right, IDL only generates gamma deviates with integer
shape parameter. This may be due to the fact that it is easier to compute
this kind of Gamma random variables, since they are the sum of independent
exponentially distributed ones, and these are generated by a simple
transformation of uniform random variables.
I'll soon post a program that generates outcomes from arbitrary Gamma
distributed random variables but, in the meantime, some references on this
topic are
@book{devro86,
author = {L. Devroye},
address = {New York},
publisher = {Springer-Verlag},
title = {Non-uniform random variate generation},
year = {1986}
}
@book{buseu92,
author = {Bustos, O. H. and A. C. Frery},
address = {Rio de Janeiro, RJ, Brazil},
publisher = {CNPq/IMPA},
series = {Monografias de Matem\'atica, 49},
title = {Simula\c{c}\~{a}o estoc\'{a}stica: teoria e algoritmos
(vers\~{a}o completa)},
year = {1992}
}
Alejandro
Alejandro C. Frery http://www.di.ufpe.br/~frery
UFPE-DI, CP 7851, 50732-970 Recife, PE - Brazil
Tel: +55-81-2718430 # 3324 Fax: +55-81-2718438
David Fanning escreveu na mensagem ...
> T.Osborn (f055@uea.ac.uk) writes:
>
>> I'm trying to generate a random series that has a gamma distribution,
using
>> the randomu() function with the gamma keyword. The online help says to
set
>> gamma to an integer > 0. WHY DOES IT HAVE TO BE AN INTEGER? The gamma
>> distribution is in fact defined for all gamma > 0, not just integers.
>> I want to set gamma=0.5, which currently fails as it converts it to the
>> integer 0, which is not > 0, and so it fails.
>>
>> Is this a bug, and is there any work-around?
>
> Which gamma function are you running? Certainly not IDL's
> GAMMA function which works perfectly well with non-integer
> values:
>
> IDL> print, gamma(0.5)
> % Compiled module: GAMMA.
> 1.77245
>
> Cheers,
>
> David
>
> ----------------------------------------------------------
> David Fanning, Ph.D.
> Fanning Software Consulting
> E-Mail: davidf@dfanning.com
> Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Note: A copy of this article was e-mailed to the original poster.
>
|
|
|
|
Re: random numbers with gamma distribution [message #13417 is a reply to message #13416] |
Wed, 04 November 1998 00:00  |
steinhh
Messages: 260 Registered: June 1994
|
Senior Member |
|
|
In article <MPG.10aa14fba7d2a20d989703@news.frii.com> davidf@dfanning.com \
(David Fanning) writes:
> T.Osborn (f055@uea.ac.uk) writes:
>
>> I'm trying to generate a random series that has a gamma distribution, using
>> the randomu() function with the gamma keyword. The online help says to set
>> gamma to an integer > 0. WHY DOES IT HAVE TO BE AN INTEGER? The gamma
>> distribution is in fact defined for all gamma > 0, not just integers.
>> I want to set gamma=0.5, which currently fails as it converts it to the
>> integer 0, which is not > 0, and so it fails.
>>
>> Is this a bug, and is there any work-around?
>
> Which gamma function are you running? Certainly not IDL's
> GAMMA function which works perfectly well with non-integer
> values:
>
> IDL> print, gamma(0.5)
> % Compiled module: GAMMA.
> 1.77245
:-)
Read his post one more time, David - and open your eyes this time :-)
A number of useful options have been added to the RANDOMU function
since I (we?) "learned" it. I don't know which version added the stuff,
but you can now generate random numbers with various distributions
(poisson, binomial, gamma, normal, uniform) straight away by setting
some keywords. The /NORMAL keyword gives you the same as RANDOMN.
As far as I can make out a gamma distribution is proportional to
x^(g-1)*exp(-x)
--------------
(g-1)
From the formula you wouldn't expect any problems with g being
fractional...since x is always positive. But I guess the
implementation is easier if g is restricted to integers...
Regards,
Stein Vidar
|
|
|
Re: random numbers with gamma distribution [message #13420 is a reply to message #13416] |
Wed, 04 November 1998 00:00  |
davidf
Messages: 2866 Registered: September 1996
|
Senior Member |
|
|
T.Osborn (f055@uea.ac.uk) writes:
> I'm trying to generate a random series that has a gamma distribution, using
> the randomu() function with the gamma keyword. The online help says to set
> gamma to an integer > 0. WHY DOES IT HAVE TO BE AN INTEGER? The gamma
> distribution is in fact defined for all gamma > 0, not just integers.
> I want to set gamma=0.5, which currently fails as it converts it to the
> integer 0, which is not > 0, and so it fails.
>
> Is this a bug, and is there any work-around?
Which gamma function are you running? Certainly not IDL's
GAMMA function which works perfectly well with non-integer
values:
IDL> print, gamma(0.5)
% Compiled module: GAMMA.
1.77245
Cheers,
David
----------------------------------------------------------
David Fanning, Ph.D.
Fanning Software Consulting
E-Mail: davidf@dfanning.com
Phone: 970-221-0438, Toll-Free Book Orders: 1-888-461-0155
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Note: A copy of this article was e-mailed to the original poster.
|
|
|