help-gsl
[Top][All Lists]
Advanced

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

Re: [Help-gsl] Random numbers within some ranges in th e domain using di


From: Mohammad Khaleghi
Subject: Re: [Help-gsl] Random numbers within some ranges in th e domain using different distributipons?
Date: Wed, 18 Jun 2008 20:42:29 +0200

Hello Martin,
Thank you for the kind and informative reply.

> -----Ursprüngliche Nachricht-----
> Von: "Martin Jansche" <address@hidden>
> Gesendet: 18.06.08 19:37:02
> An: "Mohammad Khaleghi" <address@hidden>
> CC: "Daniel J Farrell" <address@hidden>, address@hidden
> Betreff: Re: [Help-gsl] Random numbers within some ranges in the domain using 
> different distributipons?


> On Tue, Jun 17, 2008 at 12:44, Mohammad Khaleghi <address@hidden> wrote:
> > Hello Dan,
> >
> > Thank you very much for the email and the explaination which is very 
> > useful. I might have still some problems. It is maybe due to lack of enough 
> > knowledge in statistics :-)
> > I saw that most of the functions return double. Do you mean all these are 
> > distributed between (0, 1)? Then your solution is in these case perfect. 
> > But what should I do in the cases where a long int is returned?
> > I copied and pasted an example from the documents, where an unsined int is 
> > generated. Almost the same goes for all uniform distributions.
> >
> >
> >  Function: unsigned int gsl_ran_poisson (const gsl_rng * r, double mu)
> > This function returns a random integer from the Poisson distribution with 
> > mean mu. The probability distribution for Poisson variates is,
> > p(k) = {\mu^k \over k!} \exp(-\mu)
> > for k >= 0.
> >
> > Does the above means that the function produces long int values between (0, 
> > +inf)?
> 
> Not +inf, since you cannot represent that in C's integral types; more
> likely UINT_MAX.
> 
> > If so how can I produce (or get) say long ints between (100, 200)?
> 
> So you want to sample from the truncated Poisson distribution.  A
> simple and correct way is the naive rejection method:
> 
>   do {
>     k = gsl_ran_poisson(rng, mu);
>   } while (100 <= k && k <= 200);
> 
> Its efficiency, however, will depend on the value of mu.  If mu << 100
> or mu >> 200, rejection sampling is going to be very inefficient.
> 
> Depending on which distribution you want to sample from, there may be
> solutions in GSL already.  For example, there are routines for
> sampling from the tail of a Gaussian.
> 
> What's the high-level goal you're trying to accomplish?

I need to develope a module which is a basic ingredient of my tool for test 
case generation for program testing. 
I will need to generate random numbers (mostly integers - positive and 
negative) at a specific range (min, max) from as many distributions as 
possible. The efficiency also matters till some extend. Some distributions like 
bernoulli and binomial and maybe geomethric won't make sense in this regards, 
but I want to sample from as many possible distribution as I can, at a specific 
range (only when the range makes sense for the underlying distribution).
I had implemented some parts using a library developed in Vienna university 
called UNU.RAN But I was not comfortable with it and thought if I can do it in 
simpler way. That is why I looked for GSL. Once I'll get totally cleared about 
the range issue, I'll be almost done.

Could you please tell me if double value returned from other distributions than 
uniform are uniformly distributed between (0, 1)? Will your suggestion f(r) = a 
+ (b - a) * r be correct for these too?

thanks and regards,
Mohd
> 
> -- mj
> 
> > Does it make sense even thinking of something between (-100, 150)?
> >
> > Thanks a lot
> > Mohd
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: "Daniel J Farrell" <address@hidden>
> >> Gesendet: 17.06.08 18:01:50
> >> An: Mohammad Khaleghi <address@hidden>
> >> CC: address@hidden
> >> Betreff: Re: [Help-gsl] Random numbers within some ranges in the domain 
> >> using different distributipons?
> >
> >
> >> Hello Mohd,
> >>
> >> I think you are looking for this function:
> >>
> >> f(r) = a + (b - a) * r
> >>
> >> where a is the min value, b is the max values and r is a random number
> >> distributed between 0 and 1 (e.g. use gsl_rng_uniform_pos() to
> >> generate r).
> >>
> >> This come up a lot on the mailing list maybe it should be added to the
> >> library?
> >>
> >> Cheers,
> >>
> >> Dan.
> >>
> >>
> >>
> >> On 17 Jun 2008, at 16:26, Mohammad Khaleghi wrote:
> >>
> >> > Hi everybody!
> >> >
> >> > Could somebody please tell me how to generate random numbers within
> >> > some ranges in the domain?
> >> > I saw the documentation and did not see anything like setting a min
> >> > and max. I mean for a distribution that has a domain (-inf, + inf)
> >> > could one set some range (min, max) to sample from? Or it is not
> >> > possible with gsl?
> >> >
> >> > thans, Mohd
> >> >
> >> > _______________________________________________________________________
> >> > EINE FÜR ALLE: die kostenlose WEB.DE-Plattform für Freunde und Deine
> >> > Homepage mit eigenem Namen. Jetzt starten! http://unddu.de/?
> >> > address@hidden
> >> >
> >> >
> >> >
> >> > _______________________________________________
> >> > Help-gsl mailing list
> >> > address@hidden
> >> > http://lists.gnu.org/mailman/listinfo/help-gsl
> >>
> >>
> >
> >
> > ______________________________________________________________
> > Jeden Monat 1 hochkarätiger maxdome-Blockbuster GRATIS!
> > Exklusiv für alle WEB.DE Nutzer. http://www.blockbuster.web.de
> >
> >
> >
> > _______________________________________________
> > Help-gsl mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-gsl
> >
> 


____________________________________________________________________
Ihre Messenger, Communities und E-Mails jetzt in einem Programm!
WEB.DE MultiMessenger http://www.produkte.web.de/messenger/?did=3071





reply via email to

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