Re: TRandom PoissonD returns int

From: Alex Read <a.l.read_at_fys.uio.no>
Date: Sat, 17 Mar 2012 18:04:55 +0100


Hi Michele,

A Poisson distribution is for counting some sort of event. If you just need the output to be floats for technical reasons you can recast it. If you need to simulate measurements of a continuous distribution then maybe you should consider a more appropriate pdf?

Cheers, Alex

On Mar 16, 2012, at 2:14 PM, Vassili Maroussov wrote:

> Alternatively, you can use the UNURAN package:
> 
> Double_t PoissonReal(const Double_t *k, const Double_t *lambda) {
>    return TMath::Exp(k[0]*TMath::Log(lambda[0])-lambda[0]) / TMath::Gamma(k[0]+1.);
> }
> 
> TF1 MyPoisson = new TF1("MyPoisson", PoissonReal,0.,MaxPoissArg,1)
> 
> TUnuran u;
> 
> u.Init(TUnuranDistrCont(MyPoisson));
> 
> X = u.Sample();
> 
> On 03/16/2012 01:56 PM, Vassili Maroussov wrote:

>>
>> Dear Michele,
>>
>> You can generalize the Poisson in the real domain as:
>>
>> f(k,\lambda)=\frac{\lambda^{k} e^{-\lambda}}{k!}=\frac{e^{k \ln{\lambda}-\lambda}}{\Gamma{(k+1)}}
>>
>> One possible way is to use TF1:GetRandom() :
>>
>> Double_t PoissonReal(const Double_t *k, const Double_t *lambda) {
>> return TMath::Exp(k[0]*TMath::Log(lambda[0])-lambda[0]) / TMath::Gamma(k[0]+1.);
>> }
>>
>> //Max. argument expected, depends on your application. Cannot be too big to avoid overflow in TMath::Gamma
>> Double_t MaxPoissArg = 99.;
>>
>> TF1 MyPoisson("MyPoisson", PoissonReal,0.,MaxPoissArg,1)
>>
>> //Then you should set \lambda :
>> MyPoisson.SetParameters(SomeLambdaValue);
>>
>> //To assign a random number to variable X
>> X = MyPoisson.GetRandom();
>>
>> Cheers,
>>
>> Vassili
>>
>> On 03/16/2012 12:27 PM, Michele Selvaggi wrote:
>>> 
>>> Dear ROOT experts,
>>> 
>>> I am trying to generate random numbers according to a poisson distribution. I need non integer values. I thought the PoissonD method does the job, but i seem do get only int as an           output.
>>> 
>>> TRandom *rd = new TRandom();
>>> cout<<rd->Poisson(5)<<endl;
>>> 
>>> I get as expected an integer, but if I do
>>> 
>>> cout<<rd->PoissonD(5)<<endl;
>>> 
>>> then I also get an integer.. Maybe I am using the wrong method? Isn't the continuous version of a poissonian still called a poissonian?
>>> 
>>> Thanks
>>> 
>>> Michele

>>

>

Received on Sat Mar 17 2012 - 18:04:37 CET

This archive was generated by hypermail 2.2.0 : Mon Mar 19 2012 - 11:50:02 CET