My program seems to be crashing almost arbitrarily.
My code includes these two lines:
z[i, j] = -math.exp(oneminusbeta[j, i])
weights[i,j] = math.exp(beta[j,i] + oneminusbeta[j,i])
I've run my whole code before on data that had 2 dimensions, it was 7341 x 648. I had no issues at all running that code.
But now the data I'm using is about ten times as big. It's 71678 x 648, and I'm getting this error:
OverflowError: math range error
And I'm not getting this on any specific point. I'm logging comments before every line of code so that I can see what's causing the crash, and it appears the crash is happening more often on the second line mentioned above (weights[i,j] = math.exp(beta[j,i] + oneminusbeta[j,i])).
The thing is, it crashes at different times.
At first, it crashed at weights[30816, 42]. Then at weights[55399, 43]. Then at z[33715,45]. But the data is the same in all 3 cases.
What could the problem be? Is this a memory related issue with python? I'm using Numba too, by the way.
Edit
I forgot to mention, I've put thresholds so that what goes into the exp() function doesn't exceed what 709 or -708, so technically there shouldn't be an overflow.
解决方案
The result of your calculation cannot be represented on your computer. This probably means that math.exp(...) is greater than about 10308, or the argument passed to math.exp() is greater than about 710.
Try printing the values of beta[j,i] and oneminusbeta[j,i] before each calculation.
In fact, you don't have to print comments before every line of code. Instead, try wrapping the calculations with a try block, like so:
try:
weights[i,j] = math.exp(beta[j,i] + oneminusbeta[j,i])
except OverflowError:
print "Calculation failed! j=%d i=%d beta=%f oneminusbeta=%f"%(j,i,beta[j,i],oneminusbeta[j,i])
raise