python - sigmoid 函数在神经网络中的作用导数

标签 python machine-learning neural-network

我尝试了解 sigmoid 函数导数在神经网络中的作用。 enter image description here

首先,我绘制了 sigmoid 函数,以及使用 python 定义的所有点的导数。这个导数到底有什么作用呢? enter image description here

import numpy as np
import matplotlib.pyplot as plt

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

def derivative(x, step):
    return (sigmoid(x+step) - sigmoid(x)) / step

x = np.linspace(-10, 10, 1000)

y1 = sigmoid(x)
y2 = derivative(x, 0.0000000000001)

plt.plot(x, y1, label='sigmoid')
plt.plot(x, y2, label='derivative')
plt.legend(loc='upper left')
plt.show()

但是我发现了这个:

enter image description here

来源:http://www.ai.mit.edu/courses/6.892/lecture8-html/sld015.htm

当我绘制这个导数的结果时,我得到了

enter image description here

完全是另一个情节。为什么?这个衍生品有什么区别?

第二个情节

import numpy as np
import matplotlib.pyplot as plt

def __sigmoid_derivative(x):
    return x * (1 - x)

x = np.linspace(-10, 10, 1000)

y1 = __sigmoid_derivative(x)

plt.plot(x, y1)
plt.legend(loc='upper left')
plt.show()

最佳答案

sigmoid函数求导的公式公式由s(x) * (1 - s(x))给出,其中s为sigmoid函数.

sigmoid 函数的优点是它的导数非常容易计算 - 它是根据原函数计算的。

def __sigmoid_derivative(x):
    return sigmoid(x) * (1 - sigmoid(x))

所以你有

enter image description here

您引用的另一种选择,即

def __sigmoid_derivative(x):
    return x * (1 - x)

假设x已经是sigmoid函数的输出,所以第二次不需要重新计算。

关于python - sigmoid 函数在神经网络中的作用导数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49977063/

相关文章:

python - Pytorch:如何从 2D 矢量/图像预测 1D 矢量?

python - pyTorch 中的矩阵乘法

python - 神经网络 sigmoid 函数

python - Django:SQL 防注入(inject)管理器.py

python - 忽略 python 地址中的序号

machine-learning - 将复值图像输入神经网络( tensorflow )

Python 多项逻辑回归 : ValueError: bad input shape (326L, 559L)

python - 如何向量化Python单词列表?

python - 我能以某种方式查询 peewee/postgres 中的所有现有表吗?

python - AWS 开发工具包 boto3 相对于 AWS CLI 命令的优势