Path: news.mathworks.com!not-for-mail
From: Ilya Narsky <inarsky@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: summation
Date: Mon, 17 May 2010 20:09:16 -0400
Organization: The MathWorks, Inc.
Lines: 55
Message-ID: <hsslrb$qjh$1@fred.mathworks.com>
References: <hsg4kv$3vg$1@fred.mathworks.com> <hshkd1$kb1$1@fred.mathworks.com> <hsr76f$pi6$1@fred.mathworks.com> <hss44q$f6v$1@fred.mathworks.com> <hss5jk$o48$1@fred.mathworks.com> <hssfic$ge7$1@fred.mathworks.com>
NNTP-Posting-Host: vpn-client-122-13-ah.mathworks.com
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: fred.mathworks.com 1274141356 27249 144.212.122.13 (18 May 2010 00:09:16 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 18 May 2010 00:09:16 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.24 (Windows/20100228)
In-Reply-To: <hssfic$ge7$1@fred.mathworks.com>
Xref: news.mathworks.com comp.soft-sys.matlab:636686

Roger Stafford wrote:
> "Ozge Taskan" <lordgy@yahoo.com> wrote in message 
> <hss5jk$o48$1@fred.mathworks.com>...
>> Could you please explain >  (lambda-s)*(1-poisscdf(s-2,lambda)) + ...
>> >  s*lambda^(s-1)*exp(-lambda)/factorial(s-1) .
>> part, did you get this from x*P(X)-S(i)*P(X)?
>> In addition, did you mean to say that by defining x,P(x) and S as in 
>> vector form, can I solve this without any for loop?
>>
>> Thank you very much in advance.
>>
>> Regards,
>> Ozge
> 
>  I'll try to explain that identity, Ozge.  First, let us agree on a 
> temporary notation just for this occasion.  For 'lambda' I'll write 
> 'b'.  I'll use n! for factorial n.  By
> 
> sum{n=0:inf}#(b^n/n!)
> 
> I'll mean the sum:
> 
> (b^0/0! + b^1/1! + b^2/2! + b^3/3! + ...) (infinitely many)
> 
>  The reasoning goes like this.  Temporarily drop exp(-b) out of things.
> 
> sum{n=s:inf}#((n-s)*b^n/n!) = sum{n=s:inf}#(n*b^n/n!) - 
> sum{n=s:inf}#(s*b^n/n!) =
> b*sum{n=s:inf}#(b^(n-1)/(n-1)!) - s*sum{n=s:inf}#(b^n/n!) =
> b*sum{n=s-1:inf}#(b^n/n!) - s*(sum{n=s-1:inf}#(b^n/n!)-b^(s-1)/(s-1)!) =
> (b-s)*(sum{n=0:inf)#(b^n/n!)-sum(n=0:s-2}#(b^n/n!)) + s*b^(s-1)/(s-1)! =
> (b-s)*exp(b)*(1-poisscdf(s-2,b)) +  s*b^(s-1)/(s-1)!
> 
> Now multiply both first and last by exp(-b) and you have your identity.  
> (You perhaps see why I chose to use an abbreviated notation.)
> 
>  The answer to your second question is yes.  Everything in the derived 
> expression can handle vector arguments, so you should be able to use the 
> 'sum' operator to sum over i and j and never use any for-loops.  I'm not 
> sure it will make it much faster but you can compare it with using 
> for-loops and see.
> 
>  Don't forget my caution about using s values that are too large for 
> this method and losing accuracy.  If only Mathworks had a "backwards" 
> cumulative distribution for poisson distributions, it would help in this 
> issue, but I haven't heard of such a thing.
> 
> Roger Stafford

While MathWorks does not have a backwards cdf for Poisson, you can use 
identity

1-poisscdf(x,lambda) = gammainc(lambda,x+1,'lower')

This improves accuracy.          -Ilya