-2

I have a large number of type float (3.7625745528893614e-83) which must go through the sigmoid function:

def sigmoid_one(x):#sigmoid computation function
 return (1/(1+math.e**(-x)))

,but after passing a large number (that is, a number with many characters after the decimal point) through the function, 0.5 is always obtained. For a solution, I wanted to try the round() function:

round(3.7625745528893614e-83,10)

, but after calculations it gives zero. Does anyone know a solution to this problem? maybe there is a replacement for the round () function or an alternative solution?

viv3000
  • 1
  • 2
  • 1
    That's not a very large fraction. That's an extremely *small* number. Note the `e-83`, which means "times ten to the power of negative 83". – user2357112 Oct 15 '20 at 14:00
  • 1
    Why would you expect rounding to help? – user2357112 Oct 15 '20 at 14:01
  • 1
    That's standard-behavior of the logistic function. `sigmoid_one(0)` is 0.5 and your input is almost zero (close enough for internal rounding of `float` to remove the difference). –  Oct 15 '20 at 14:09
  • Not that it matters for this question, but you should never use `math.e**(something)`. Use `math.exp(something)` instead. It's more accurate, and likely faster, too. – Mark Dickinson Oct 16 '20 at 08:04

1 Answers1

1

For small x, the function exp(-x) is about the same as 1-x, so your function is approximately equal to 1/(2-x) which, for small x is about 1/2. So your program is working correctly.

pygri
  • 647
  • 6
  • 17