Re: normal distribution pdfs and cdf: speed and accuracy



"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
.



Relevant Pages

  • Re: Maintaining a constant speed
    ... speed is v.   How do I compute xand ysuch that vis ... So it seems you want to find increments (delta x, ... y is g'times delta x to first order approximation. ... I would imagine the third derivatives can be handled in similar ...
    (sci.math.symbolic)
  • Re: Maintaining a constant speed
    ... speed is v.   How do I compute xand ysuch that vis ... So it seems you want to find increments (delta x, ... y is g'times delta x to first order approximation. ... I would imagine the third derivatives can be handled in similar ...
    (sci.math.symbolic)
  • Re: Assign a generic name to a function based on user decision
    ... Jason Blevins wrote: ... I think what Nick is getting at is that ERF only allows you to ... approximate the CDF of the Gaussian distribution, ... The CDF approximation is straightforward, ...
    (comp.lang.fortran)
  • Re: Maintaining a constant speed
    ... So it seems you want to find increments (delta x, ... y is g'times delta x to first order approximation. ... forward and backward difference estimates. ... where primes mean derivatives with respect to x. ...
    (sci.math.symbolic)
  • Re: Bounding the beta function
    ... variable from the beta distribution with mean 0.5 and variance ... Normal cdf as N)). ... Is this approximation an application ...
    (sci.math)