I'm trying to calculate $\prod_k{p_k}$ where $p_k$ are (potentially) very high probabilities of independent, zero-mean, standard normal random variables and $k>100$. However, I'm running into numerical problems using MATLAB (although the same problem occurs in Python/Scipy). Let's say $x=30$, then
normcdf(x)
returns 1, which is not precise. However, if I use normcdf(-x) (or normcdf(x,'upper')) instead, I get a value of 4.906713927148764e-198. I was hoping that I could then take 1 minus this value to get a more accurate probability. Unfortunately, the result gets rounded, as soon as I apply the subtraction:
>> normcdf(-x)
ans =
4.906713927148764e-198
>> 1-(1-normcdf(-x))
ans =
0
Is there any way to work around this issue?
If you really need to compute such tiny probabilities, one way is to use symbolic math and/or variable precision arithmetic.
For example, using the
vpafunction in the Symbolic Math toolbox:which returns
Of course converting this result back to floating-point (
double(P2)) results in zero asP2is less thaneps(realmin). However, it's possible that if you do your calculations in variable precision and convert back to floating-point at the end you may be able gain a bit more accuracy. Just check to make sure that you're not wasting compute cycles.