Help needed!! [message #70513] |
Fri, 16 April 2010 08:49  |
bala murugan
Messages: 23 Registered: April 2010
|
Junior Member |
|
|
Hi people,
I am new to IDL. This is my first program in IDL. Can somebody point
out the errors in my code. I have been struggling to get it right.
CODE:
FUNCTION poissondist,fLambda,N
r = RANDOMU(SEED,1)
FOR j=1,N,1 DO BEGIN
x=poisson(j,fLambda)
if (x EQ r) THEN a[i]=j
ENDFOR
RETURN,a
END
In the above code, the function "poisson" was written by me. It is as
follows,
CODE:
FUNCTION poisson,a,b
x = (b^a)/(exp(b)*factorial(a))
RETURN,x
END
Looking forward to your reply.
Thanks,
B
|
|
|
Re: Help needed!! [message #70540 is a reply to message #70513] |
Tue, 20 April 2010 11:31  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
bala murugan writes:
> David,
>
> Can you please check if I am right about the second method?
Are you talking to me!? I don't know anything about Poisson
distributions. I believe anything Craig Markwardt tells me.
I do know I would probabably use Histoplot to make
a histogram plot, though, rather than that strange thing
you can make with the Plot command. :-)
http://www.dfanning.com/programs/histoplot.pro
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
|
|
|
Re: Help needed!! [message #70543 is a reply to message #70513] |
Tue, 20 April 2010 10:43  |
bala murugan
Messages: 23 Registered: April 2010
|
Junior Member |
|
|
On Apr 19, 12:26 pm, David Fanning <n...@dfanning.com> wrote:
> Craig Markwardt writes:
>> A Poisson deviate is the thing you originally desired! A single
>> Poisson deviate is one random draw from the Poisson distribution. A
>> histogram of N deviates will approximate the Poisson distribution, and
>> as N tends to infinity, the histogram will tend to the Poisson
>> distribution exactly.
>
> We shall not cease from exploration
> And the end of all our exploring
> Will be to arrive where we started
> And know the place for the first time.
>
> From The Four Quartets
> T.S. Eliot
>
> --
> David Fanning, Ph.D.
> Fanning Software Consulting, Inc.
> Coyote's Guide to IDL Programming:http://www.dfanning.com/
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")
My objective like I said is as follows,
an IDL routine that takes as input the mean of a Poisson
distribution (fLambda = a floating point number >= 0.0) and a number
of realizations (N), and generates N samples from the Poisson
distribution with mean fLambda. The output samples should be
provided
as a vector (list) of integers (each >= 0).I will also want to plot
a histogram of the samples (IDL probably has a built-in histogramming
routine).
I couldnt make the following work :( (Its just too complicated!!)
FUNCTION poi,fLambda,N
a = FLTARR(N)
FOR i=1,N-1,1 DO BEGIN
r = RANDOMU(SEED,1)
FOR j=1,(5*N),1 DO BEGIN
x = ((fLambda^j)/(exp(fLambda)*factorial(j)))
z=abs(x-r)
if z lt 0.1 THEN a[i]=j & print,r,abs(x-r) & ENDFOR
ENDFOR
RETURN,a
END
Rather I guess the following satisfies my objective,
IDL> data = RANDOMU(SEED,N,POISSON=fLambda)
IDL> PLOT,HISTOGRAM(data,BINSIZE=1),PSYM=10
Where, N- number of realizations
fLambda - mean of the poisson distribution
David,
Can you please check if I am right about the second method?
Thanks,
Thanks to all the guys who replied, I got to learn a lot from your
replies.
|
|
|
Re: Help needed!! [message #70559 is a reply to message #70513] |
Mon, 19 April 2010 11:26  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Craig Markwardt writes:
> A Poisson deviate is the thing you originally desired! A single
> Poisson deviate is one random draw from the Poisson distribution. A
> histogram of N deviates will approximate the Poisson distribution, and
> as N tends to infinity, the histogram will tend to the Poisson
> distribution exactly.
We shall not cease from exploration
And the end of all our exploring
Will be to arrive where we started
And know the place for the first time.
From The Four Quartets
T.S. Eliot
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
|
|
|
Re: Help needed!! [message #70561 is a reply to message #70513] |
Mon, 19 April 2010 11:21  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Apr 19, 1:16 pm, bala murugan <bala2...@gmail.com> wrote:
> On Apr 17, 11:07 am, "R.G. Stockwell" <noem...@please.com> wrote:
>
>> "bala murugan" <bala2...@gmail.com> wrote in message
>
>> news:29ee4ec6-4803-44fd-aa5c-00fc0d2c9376@u21g2000yqc.google groups.com...
>
>> one general piece of advice, if you plan on doing a fair bit of IDL
>> programming
>> in the future, is to get David Fannings book and read it completely
>> (then read it again).
>
>> http://www.dfanning.com/documents/books.html
>
>> Also, many questions have already been answered on his website.http://www.dfanning.com/
>
>> cheers,
>> bob
>
> Thanks for the advice :).
>
> I have a question in statistics.
>
> What is a poisson deviate ?
>
> Is it a point in the poisson distribution curve?
>
> Can anybody explain it?
A Poisson deviate is the thing you originally desired! A single
Poisson deviate is one random draw from the Poisson distribution. A
histogram of N deviates will approximate the Poisson distribution, and
as N tends to infinity, the histogram will tend to the Poisson
distribution exactly.
|
|
|