赞
踩
def sigmoid(x):
return 1 / (1 + np.exp(-x))
x = np.linspace(start=-10, stop=10, num=30)
plt.plot(x, sigmoid(x))
plt.grid()
def softmax(logits):
"""
softmax:
- 原始数字比较大,模拟概率也比较大
"""
# 转为 array
logits = np.array(logits)
# 转为正数
logits = np.exp(logits)
# 模拟概率
return logits / logits.sum()
softmax([0.6, -3.6, 18.9]) # :array([1.12826464e-08, 1.69189790e-10, 9.99999989e-01])
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。