help-octave
[Top][All Lists]
Advanced

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

Re: Integrating a normal distribution many times


From: Tarmigan Casebolt
Subject: Re: Integrating a normal distribution many times
Date: Tue, 22 May 2007 11:15:08 -0700 (PDT)


Søren Hauberg wrote:
> 
> David Bateman skrev:
>> Closed forms, always a bit faster :-)
> Wow, that was quite a speed up. I'll be having no problems with doing 
> this in real-time. Thanks.
> 
> Søren
> 

You could also try normal_cdf, which is the integral of the pdf.

Here's an example using normal_cdf.  After several layers of indirection and
checking, it also calls erf, so David's version is still 10x faster.

The normal_* functions have been deprecated in recent versions of octave, in
favor of norm*.  Be a little careful with the norm* functions as they have
recently been changed for compatability with matlab to take the standard
deviation instead of the variance.

-Tarm


%%%%%%%%%%%
clear

a = 19;
b = 26;
variance = 2.5;

n=100;

tic
for t = linspace(0,32,n)
  qq = @(x) normal_pdf(x, t, variance);
  result = quad(qq, a, b, 0);
end
toc

tic
for mean = linspace(0,32,n)
  result = normal_cdf(b,mean,variance) - normal_cdf(a,mean,variance);
end
toc

mean = linspace(0,32,n);
tic
result = normal_cdf(b,mean,variance) - normal_cdf(a,mean,variance);
toc

sigma = sqrt(variance);
tic
f = @(x) erf((x  - mean)/ sqrt(2) / sigma) / 2;
result = f(b) - f(a); 
toc
-- 
View this message in context: 
http://www.nabble.com/Integrating-a-normal-distribution-many-times-tf3771481.html#a10744610
Sent from the Octave - General mailing list archive at Nabble.com.




reply via email to

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