【发布时间】:2021-10-04 17:30:08
【问题描述】:
我正在尝试使用批处理从头开始反向传播,但在计算 dx 时遇到问题。首先,我想先定义变量以避免混淆:
a - The activation value calculated by passing z through an activation function
z - The value before the activation function of the layer
x - The inputs into the layer
w - The weights that connect the inputs to the output nodes
da - The derivative of a
dz - The derivative of z
dx - The derivative of x
我知道这是 x 的导数:
dx = w.T*dz
Note: * means dot and .T means transpose
现在让我介绍一下这个问题。假设我有一个具有 2 个输入、3 个输出节点和 5 批大小的神经网络。我将如何计算 dx?在这种情况下,权重在转置之前的形状为 (z, x) 或 (3, 2),而 dz 的形状为 (z, batches) 或 (3, 5)。如果我使用上面的公式,我会得到 (x, batches) 或 (2, 5) 的形状。在使用上面的公式得到 dx 后,我是否会取最后一个维度的总和(导致形状为 (2, 1))?下面是使用虚构值的点积表示:
w.T * dz = dx
[[1, 2, 3, 4, 5],
[[1, 0.5, 1], * [1, 2, 3, 4, 5], = [[2.5, 5, 7.5, 10, 12.5],
[-1, -1, -0.5] [1, 2, 3, 4, 5]] [-2.5, -5, -7.5, -10, -12.5]]
【问题讨论】:
标签: python numpy neural-network backpropagation