如何获得 0 到 1 之间的 sigmoid 函数以获得正确答案的概率?

sal*_*cap 1 numpy distribution matplotlib beta-distribution sigmoid

我正在尝试模拟一些数据,其中响应可能是正确的 (1) 或错误的 (0)。因此,我试图找到一个分布,其中有四个条件(在本例中为圆的度数)。

因此,x 轴是 pi/2, pi, pi 1.5, 2 pi。我已将其从 0 标准化为 1 以使其更容易。在 y 轴上,我希望回答正确的概率是 0-1 或 0-100 等。我试图生成/绘制一个 sigmoid 函数,这样当条件接近 1 时概率更高,当条件接近 1 时概率更低条件更接近于 0。

我似乎无法在 0 和 1 之间生成 sigmoid,它只会给我一条直线,除非我设置 x = np.linspace (-10,10,10)。我怎样才能做到这一点?我目前拥有的代码如下。谢谢!

我最初打算使用 beta 分布,因为它更适合(因为它是围绕一个圆的度数),但似乎无法将其变成我想要的形状。任何帮助将不胜感激!

def sigmoid(x,x0=0,k=0.5):
            return (1 / (1 + np.exp(-x)))
x = np.linspace(0,1,10)
Run Code Online (Sandbox Code Playgroud)

Hom*_*mer 5

由于您对标准化到范围感到满意[0,1],请考虑标准化为[-1,1]

import numpy as np
import matplotlib.pyplot as plt

def norm(x):
    # normalise x to range [-1,1]
    nom = (x - x.min()) * 2.0
    denom = x.max() - x.min()
    return  nom/denom - 1.0

def sigmoid(x, k=0.1):
    # sigmoid function
    # use k to adjust the slope
    s = 1 / (1 + np.exp(-x / k)) 
    return s

# un-normalised data
x = np.linspace(-4,+4,100)
# normalise the data
x = norm(x) 

plt.plot(x, sigmoid(x))
plt.show()
Run Code Online (Sandbox Code Playgroud)

Sigmoid 激活函数