tags:

views:

49

answers:

2

This is a sigmoid function:

alt text

I know x. How can I calculate F(x) in Python now?

Let's say x = 0.458.

F(x) = ?

+3  A: 

This should do it:

import math

def sigmoid(x):
  return 1 / (1 + math.exp(-x))

And testing it:

>>> sidmoid(0.458)
0.61253961344091512
unwind
Thanks. I will accept your answer asap. I have to wait 10 minutes though.
Richard Knop
+1  A: 

another way

>>> def sigmoid(x):
...     return 1 /(1+(math.e**-x))
...
>>> sigmoid(0.458)
ghostdog74
What is the difference between this and unwind's function? Is math.e**-x better than math.exp(-x)?
Richard Knop
There is no difference in terms of output result. If you want to know the difference in terms of speed, you can use timeit to time their execution. But that's really not important.
ghostdog74