How to calculate a logistic sigmoid function in Python?

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

This is a logistic sigmoid function:

\"enter

I know x. How can I calculate F(x

15条回答
  •  旧时难觅i
    2020-11-29 16:58

    A numerically stable version of the logistic sigmoid function.

        def sigmoid(x):
            pos_mask = (x >= 0)
            neg_mask = (x < 0)
            z = np.zeros_like(x,dtype=float)
            z[pos_mask] = np.exp(-x[pos_mask])
            z[neg_mask] = np.exp(x[neg_mask])
            top = np.ones_like(x,dtype=float)
            top[neg_mask] = z[neg_mask]
            return top / (1 + z)
    

提交回复
热议问题