How to calculate a logistic sigmoid function in Python?

后端 未结 15 1901
情话喂你
情话喂你 2020-11-29 16:14

This is a logistic sigmoid function:

\"enter

I know x. How can I calculate F(x

15条回答
  •  孤街浪徒
    2020-11-29 17:14

    Good answer from @unwind. It however can't handle extreme negative number (throwing OverflowError).

    My improvement:

    def sigmoid(x):
        try:
            res = 1 / (1 + math.exp(-x))
        except OverflowError:
            res = 0.0
        return res
    

提交回复
热议问题