Re: normal distribution pdfs and cdf: speed and accuracy
- From: "John D'Errico" <woodchips@xxxxxxxxxxxxxxxx>
- Date: Fri, 5 Jun 2009 09:15:03 +0000 (UTC)
"Misha Koshelev" <mk144210@xxxxxxx> wrote in message <h09h17$obm$1@xxxxxxxxxxxxxxxxxx>...
Dear All:
I am working on a Gibbs sampler with Markov Chain Monte Carlo.
In the marginal likelihood calculation, I compute a lot of normpdf's currently using the Lightspeed package.
Technically, what I would like to compute is $\Delta\cdot \rho$, that is
Delta * normpdf(a).
Very very technically what I am computing is:
normcdf(a+Delta/2)-normcdf(a-Delta/2)
which is approximately equal to
Delta * normpdf(a)
for the small values of Delta that I am using.
Now the normcdf computation is _significantly_ slower, and I'm not honestly sure since an expansion is used to approximate it (?) that it is actually more accurate than just calculating Delta * normpdf.
It IS more accurate to use the cdf here. Perhaps you
should test that fact rather than worrying about it.
You will see that it is more accurate. Do a numerical
integration using quadgk to verify the result and the
accuracy obtained.
I would appreciate any input on this. Specifically:
(a) is it any more accurate in the case of small Deltas (say Delta = 0.05 or 0.05/3) to use the cdf here?
Yes, the cdf is a better approximation than your
simple rectangle rule approximation.
See above.
(b) if so, is there a faster implementation?
The cdf implementation is even reasonably fast. But
your desire for speed is apparently more than your
CPU can satisfy. There will always be someone out
there who demands more speed. It matters not how
fast it runs, someone will say "Not fast enough!"
You can always use a poor approximation to the cdf
to gain speed. There are lots of them out there. In
fact you have chosen one that is quite poor, a
rectangle rule approximation. Depending on the
variance of your distribution, this may be entirely
adequate for your needs. It appears that you are
using a standard normal, so the variance == 1.
Only you know if it is good enough for you.
Compare the results and make the decision. Only
you can make that tradeoff between speed and the
accuracy you will lose. Remember to use
format long g
to display the different results.
John
.
- References:
- normal distribution pdfs and cdf: speed and accuracy
- From: Misha Koshelev
- normal distribution pdfs and cdf: speed and accuracy
- Prev by Date: Re: Gray range
- Next by Date: Re: Gray range
- Previous by thread: Re: normal distribution pdfs and cdf: speed and accuracy
- Next by thread: Re: normal distribution pdfs and cdf: speed and accuracy
- Index(es):
Relevant Pages
|