I tried various solutions for below, but I still get the errors as described:
log1p(1 + math.exp(comp * -1))
Error: OverflowError: math range error
So I changed it to: log1p(1 + np.exp(comp * -1))
Now I get error : RuntimeWarning: overflow encountered in exp
So again based on some suggestion on previous questions asked I changed it to: log1p(1 + np.exp((comp * -1), dtype=np.float256))
Now my error is : module 'numpy' has no attribute 'float256'
Any other suggestions? Please help thanks!
EDIT: X -> Input feature array of 'N' rows and 'm' features. w -> weight vector of size 'm'
for rowIndex in range(len(X)):
val1 = np.sum(np.dot(X[rowIndex], w))
val2 = y[rowIndex]
comp = np.dot(val2, val1)
loss = loss + log1p(1 + np.exp((comp * -1)))
comp? Also, what you are attempting to compute isln(2 + exp(-comp)). Is this really what you want?log1p(x) = log(x + 1)? Also,log1p(1 + math.exp(comp * -1))works fine for various values ofcomp, including6000. Please provide a complete example demonstrating the problem.comp= 40, theexppart can be treated as zero:log1p(1+exp(-40))-log(2)is zero.compbe negative? What you describe doesn't seem possible otherwise. And ifcompis large and negative, then the1 + ...will be insignificant, so your expressionlog1p(1 + math.exp(comp * -1))will be simply-comp, to within numerical error. (Also: what @jmd_dk said: are you sure you wantlog(1 + 1 + math.exp(...))?