0

I keep getting this error for sigmoid function

RuntimeWarning: overflow encountered in exp
  return 1 / (1 + np.exp(-s))

def sigmoid(s):
    return 1 / (1 + np.exp(-s))

I tried fixing it as follows inspired by this answer:

def sigmoid(s):
   s = s.astype(np.float128)
   min_value = np.finfo(s.dtype).min
   max_value = np.finfo(s.dtype).max
   s[s == np.NINF] = min_value
   s[s == np.inf] = max_value
   return 1 / (1 + np.exp(-s))

But this does no effect and I still get the same error, why is it the case? Thanks

3

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.