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 the domain using dif

 From: Martin Jansche Subject: Re: [Help-gsl] Random numbers within some ranges in the domain using different distributipons? Date: Wed, 18 Jun 2008 13:36:50 -0400

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?

-- 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
>


reply via email to

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