Deep Learning (1) - Neural Network with 1 Hidden Layer

Edit

在之前学习Andrew NG的Coursera课程《Machine Learning》的时候,针对Neural Network做过一篇笔记:Machine Learning (2) - Neural Network。当时通过学习知道了如何计算2层(1个隐藏层)Neural Network的偏导数问题。但是理解只是局限于一堆公式,不够深刻。这次在学习Andrew NG的Deep Learning课程时,Andrew在介绍深层网络之前也介绍了浅层网络的基本原理,包括导数公式的推导。我现在终于理解了这些公式是如何来的了。对比了之前Machine Learning的课件和笔记,我认为此次课程中使用的符号标记方式更容易理解和推导。
在这一篇笔记中,我会主要记录浅层神经网络的forward propagation & backward propagation计算方法。

Forward Propagation

Backward Propagation

在神经网络的学习中,我们往往能听到这个词汇。听起来很玄乎,其实他并不神秘。
Backward Propagation,中文翻译为反向传播。它是用来计算导数的。下图为Logistic Regression的计算图:

上式也是我们在求导数时最常用到的链式法则(chain rule)。若



则有下图:

纠错

  • 上图应为
  • 应为

先看Andrew给出的计算结果:

sigmoid函数的导数为:
而其他的隐藏层采用为其激活函数,即有可能是tanh或者ReLU,也有可能是sigmoid。

分步求导

损失函数

其导数为:
代入:

代入,可得:

代入,可得:

这个就很简单了

至此全部得证。

矩阵求导

在计算的时候,会发现这里有一个矩阵求导的问题。是列向量,型矩阵,是列向量。
网上搜到的矩阵求导方法的帖子有很多,但都没有很好的解释为什么
根据我自己的理解,可以看作个列向量。关于的导数就是对所有列向量的导数的stack。
因为

所以
stack到一块儿就是
所以得证。

Vectorization

Forward propagation




Backward propagation






np.sum(A, axis=1, keepdims=True) 求取矩阵A各行的和
axis: =1 按行求和,=0 按列求和,没有axis则全矩阵求和
keepdims: =True 求和出来后仍然保存矩阵结构,即按行求和,则得到列向量,按列求和得到行向量,全矩阵求和得到一个1x1矩阵。

分析

先看single training example:

训练样本按照下面的方法stack,也类似可得如下:

为什么?
最直观的b应该是,因为
那为什么要按照行求和再按m求均值呢?因为为模型参数,与样本无关。针对每个样本b, db应当相同。所以要按上面这么算。

总结

在浅层神经网络中,正向传播求节点值,反向传播利用链式法则求导数。在向量化的时候,针对所有的样本,向量按照列组合成矩阵,即矩阵的一列对应一个样本。

%23%20Deep%20Learning%20%281%29%20-%20Neural%20Network%20with%201%20Hidden%20Layer%0A@%28myblog%29%5Bdeep%20learning%2C%20neural%20network%5D%0A%0A%u5728%u4E4B%u524D%u5B66%u4E60Andrew%20NG%u7684Coursera%u8BFE%u7A0B%u300AMachine%20Learning%u300B%u7684%u65F6%u5019%uFF0C%u9488%u5BF9Neural%20Network%u505A%u8FC7%u4E00%u7BC7%u7B14%u8BB0%uFF1A%5BMachine%20Learning%20%282%29%20-%20Neural%20Network%5D%28https%3A//zhougy0717.github.io/2017/04/03/Machine%2520Learning%2520%282%29%2520-%2520Neural%2520Network/%29%u3002%u5F53%u65F6%u901A%u8FC7%u5B66%u4E60%u77E5%u9053%u4E86%u5982%u4F55%u8BA1%u7B972%u5C42%uFF081%u4E2A%u9690%u85CF%u5C42%uFF09Neural%20Network%u7684%u504F%u5BFC%u6570%u95EE%u9898%u3002%u4F46%u662F%u7406%u89E3%u53EA%u662F%u5C40%u9650%u4E8E%u4E00%u5806%u516C%u5F0F%uFF0C%u4E0D%u591F%u6DF1%u523B%u3002%u8FD9%u6B21%u5728%u5B66%u4E60Andrew%20NG%u7684Deep%20Learning%u8BFE%u7A0B%u65F6%uFF0CAndrew%u5728%u4ECB%u7ECD%u6DF1%u5C42%u7F51%u7EDC%u4E4B%u524D%u4E5F%u4ECB%u7ECD%u4E86%u6D45%u5C42%u7F51%u7EDC%u7684%u57FA%u672C%u539F%u7406%uFF0C%u5305%u62EC%u5BFC%u6570%u516C%u5F0F%u7684%u63A8%u5BFC%u3002%u6211%u73B0%u5728%u7EC8%u4E8E%u7406%u89E3%u4E86%u8FD9%u4E9B%u516C%u5F0F%u662F%u5982%u4F55%u6765%u7684%u4E86%u3002%u5BF9%u6BD4%u4E86%u4E4B%u524DMachine%20Learning%u7684%u8BFE%u4EF6%u548C%u7B14%u8BB0%uFF0C%u6211%u8BA4%u4E3A%u6B64%u6B21%u8BFE%u7A0B%u4E2D%u4F7F%u7528%u7684%u7B26%u53F7%u6807%u8BB0%u65B9%u5F0F%u66F4%u5BB9%u6613%u7406%u89E3%u548C%u63A8%u5BFC%u3002%0A%u5728%u8FD9%u4E00%u7BC7%u7B14%u8BB0%u4E2D%uFF0C%u6211%u4F1A%u4E3B%u8981%u8BB0%u5F55%u6D45%u5C42%u795E%u7ECF%u7F51%u7EDC%u7684forward%20propagation%20%26%20backward%20propagation%u8BA1%u7B97%u65B9%u6CD5%u3002%0A%0A%23%23%20Forward%20Propagation%0A%21%5BAlt%20text%5D%28./1513332445189.png%29%0A%u524D%u5411%u4F20%u64AD%u8BA1%u7B97%u6BCF%u4E2A%u8282%u70B9%u7684%u503C%uFF0C%u540E%u9762%u7684%u53CD%u5411%u4F20%u64AD%u4E2D%u4F1A%u7528%u5230%u3002%0A%21%5BAlt%20text%5D%28./1513574653750.png%29%0A%23%23%20Backward%20Propagation%0A%u5728%u795E%u7ECF%u7F51%u7EDC%u7684%u5B66%u4E60%u4E2D%uFF0C%u6211%u4EEC%u5F80%u5F80%u80FD%u542C%u5230%u8FD9%u4E2A%u8BCD%u6C47%u3002%u542C%u8D77%u6765%u5F88%u7384%u4E4E%uFF0C%u5176%u5B9E%u4ED6%u5E76%u4E0D%u795E%u79D8%u3002%0ABackward%20Propagation%uFF0C%u4E2D%u6587%u7FFB%u8BD1%u4E3A%u53CD%u5411%u4F20%u64AD%u3002%u5B83%u662F%u7528%u6765%u8BA1%u7B97%u5BFC%u6570%u7684%u3002%u4E0B%u56FE%u4E3ALogistic%20Regression%u7684%u8BA1%u7B97%u56FE%uFF1A%0A%21%5BAlt%20text%7C500x0%5D%28./1513330613563.png%29%0A%u6309%u7167%u6C42%u5BFC%u516C%u5F0F%u53EF%u77E5%uFF1A%0A%24%24%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20%5Comega%7D%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20a%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20z%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20z%7D%7B%5Cpartial%20%5Comega%7D%24%24%0A%u4E0A%u5F0F%u4E5F%u662F%u6211%u4EEC%u5728%u6C42%u5BFC%u6570%u65F6%u6700%u5E38%u7528%u5230%u7684%u94FE%u5F0F%u6CD5%u5219%28chain%20rule%29%u3002%u82E5%0A%24da%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20a%7D%24%0A%24dz%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20z%7D%20%3D%20da%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20z%7D%24%0A%24d%20%5Comega%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20%5Comega%7D%20%3D%20dz%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20%5Comega%7D%24%0A%u5219%u6709%u4E0B%u56FE%uFF1A%0A%21%5BAlt%20text%7C550x0%5D%28./1513331905347.png%29%0A%u8FD9%u5C31%u662F%u6240%u8C13%u7684%u53CD%u5411%u4F20%u64AD%28Backward%20Propagation%29%u3002%u524D%u4E00%u5C42%u4E3A%u540E%u4E00%u5C42%u63D0%u4F9B%u8FDB%u4E00%u6B65%u8BA1%u7B97%u5BFC%u6570%u7684%u4FE1%u606F%u3002%0A%u63A8%u8FDB%u52302%u5C42%u795E%u7ECF%u7F51%u7EDC%uFF0C%u5C31%u8981%u591A%u7B97%u4E00%u5C42%uFF1A%0A%21%5BAlt%20text%5D%28./1513332172423.png%29%0A%0A%3E**%u7EA0%u9519**%0A-%20%u4E0A%u56FE%24z%5E%7B%5B2%5D%7D%24%u5E94%u4E3A%24%5Comega%5E%7B%5B2%5D%7Da%5E%7B%5B1%5D%7D%20+%20b%5E%7B%5B2%5D%7D%24%0A-%20%24a%5E%7B%5B1%5D%7D%24%u5E94%u4E3A%24g%5E%7B%5B1%5D%7D%28z%5E%7B%5B1%5D%7D%29%24%0A%0A%u5148%u770BAndrew%u7ED9%u51FA%u7684%u8BA1%u7B97%u7ED3%u679C%uFF1A%0A%21%5BAlt%20text%7C280x0%5D%28./1513332236320.png%29%0A%u5982%u679C%u76F4%u63A5%u81EA%u5DF1%u53BB%u7B97%u4F1A%u6709%u4E00%u4E9B%u7591%u95EE%u3002%u8981%u7B97%u51FA%u8FD9%u4E2A%u7ED3%u679C%uFF0C%u5176%u5B9E%u662F%u6709%u4E00%u4E9B%u524D%u63D0%u7684%u3002%0A%21%5BAlt%20text%5D%28./1513332445189.png%29%0A%u5728%u8F93%u51FA%u5C42%uFF0C%u5373%24a%5E%7B%5B2%5D%7D%24%u5C42%uFF0C%u91C7%u7528sigmoid%u6FC0%u6D3B%u51FD%u6570%uFF0C%u5373%0A%24%24a%5E%7B%5B2%5D%7D%20%3D%20%5Csigma%28z%5E%7B%5B2%5D%7D%29%20%3D%20%5Cdfrac%20%7B1%7D%7B1+e%5E%7B-z%7D%7D%24%24%0Asigmoid%u51FD%u6570%u7684%u5BFC%u6570%u4E3A%3A%0A%24%24%5Cdfrac%20%7Bda%7D%7Bdz%7D%20%3D%20%5Cdfrac%20%7Be%5E%7B-z%7D%7D%7B%281+e%5E%7B-z%7D%29%5E2%7D%20%3D%20%5Cdfrac%20%7B1%7D%7B1+e%5E%7B-z%7D%7D%20-%20%5Cdfrac%20%7B1%7D%7B%281+e%5E%7B-z%7D%29%5E2%7D%20%3D%20a%281-a%29%24%24%0A%u800C%u5176%u4ED6%u7684%u9690%u85CF%u5C42%u91C7%u7528%24g%5E%7B%5Bi%5D%7D%28%29%24%u4E3A%u5176%u6FC0%u6D3B%u51FD%u6570%uFF0C%u5373%u6709%u53EF%u80FD%u662Ftanh%u6216%u8005ReLU%uFF0C%u4E5F%u6709%u53EF%u80FD%u662Fsigmoid%u3002%0A%0A%23%23%23%20%u5206%u6B65%u6C42%u5BFC%0A%23%23%23%20%24dz%5E%7B%5B2%5D%7D%24%0A%u635F%u5931%u51FD%u6570%0A%24%24L%20%3D%20-%28ylog%20a%5E%7B%5B2%5D%7D%20+%20%281-y%29log%20%281-a%5E%7B%5B2%5D%7D%29%29%24%24%0A%u5176%u5BFC%u6570%u4E3A%uFF1A%0A%24%24%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20a%7D%20%3D%20-%5Cdfrac%20%7By%7D%7Ba%5E%7B%5B2%5D%7D%7D%20-%20%5Cdfrac%20%7B1-y%7D%7B1-a%5E%7B%5B2%5D%7D%7D%24%24%0A%u4EE3%u5165%uFF1A%0A%24%24dz%5E%7B%5B2%5D%7D%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20a%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20z%7D%20%3D%20a%5E%7B%5B2%5D%7D%281-a%5E%7B%5B2%5D%7D%29%28-%5Cdfrac%20%7By%7D%7Ba%5E%7B%5B2%5D%7D%7D%20-%20%5Cdfrac%20%7B1-y%7D%7B1-a%5E%7B%5B2%5D%7D%7D%29%20%3D%20a%5E%7B%5B2%5D%7D%20-%20y%24%24%0A%0A%0A%0A%23%23%23%23%20%24d%5Comega%5E%7B%5B2%5D%7D%20%2C%20b%5E%7B%5B2%5D%7D%24%0A%24%24d%5Comega%5E%7B%5B2%5D%7D%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20%5Comega%5E%7B%5B2%5D%7D%7D%20%3D%20dz%5E%7B%5B2%5D%7Da%5E%7B%5B1%5DT%7D%24%24%0A%24%24db%5E%7B%5B2%5D%7D%20%3D%20%5Cdfrac%20%7B%5Cpartial%20L%7D%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20b%5E%7B%5B2%5D%7D%7D%20%3D%20dz%5E%7B%5B2%5D%7D%24%24%0A%0A%23%23%23%23%20%24da%5E%7B%5B1%5D%7D%24%0A%24%24da%5E%7B%5B1%5D%7D%20%3D%20dz%5E%7B%5B2%5D%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20a%5E%7B%5B1%5D%7D%7D%24%24%0A%u4EE3%u5165%24%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20a%5E%7B%5B1%5D%7D%7D%20%3D%20%5Comega%5E%7B%5B2%5DT%7D%24%uFF0C%u53EF%u5F97%uFF1A%0A%24%24da%5E%7B%5B1%5D%7D%20%3D%20%5Comega%5E%7B%5B2%5DT%7D%20dz%5E%7B%5B2%5D%7D%24%24%0A%0A%0A%23%23%23%23%20%24dz%5E%7B%5B1%5D%7D%24%0A%24%24dz%5E%7B%5B1%5D%7D%20%3D%20da%5E%7B%5B1%5D%7D%20%5Ccenterdot%20%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20z%5E%7B%5B1%5D%7D%7D%24%24%0A%u4EE3%u5165%24%5Cdfrac%20%7B%5Cpartial%20a%7D%7B%5Cpartial%20z%5E%7B%5B1%5D%7D%7D%20%3D%20g%5E%7B%5B1%5D%7D%5Cprime%20%28z%5E%7B%5B1%5D%7D%29%24%uFF0C%u53EF%u5F97%uFF1A%0A%24%24dz%5E%7B%5B1%5D%7D%20%3D%20%5Comega%5E%7B%5B2%5DT%7D%20dz%5E%7B%5B2%5D%7D%20*g%5E%7B%5B1%5D%7D%5Cprime%20%28z%5E%7B%5B1%5D%7D%29%24%24%0A%0A%23%23%23%23%20%24d%5Comega%5E%7B%5B1%5D%7D%20%2C%20db%5E%7B%5B1%5D%7D%24%0A%u8FD9%u4E2A%u5C31%u5F88%u7B80%u5355%u4E86%0A%24%24d%5Comega%5E%7B%5B1%5D%7D%20%3D%20dz%5E%7B%5B1%5D%7Dx%24%24%0A%24%24db%5E%7B%5B1%5D%7D%20%3D%20dz%5E%7B%5B1%5D%7D%24%24%0A%0A%u81F3%u6B64%u5168%u90E8%u5F97%u8BC1%u3002%0A%0A%23%23%23%20%u77E9%u9635%u6C42%u5BFC%0A%u5728%u8BA1%u7B97%24da%5E%7B%5B1%5D%7D%24%u7684%u65F6%u5019%uFF0C%u4F1A%u53D1%u73B0%u8FD9%u91CC%u6709%u4E00%u4E2A%u77E9%u9635%u6C42%u5BFC%u7684%u95EE%u9898%u3002%24z%5E%7B%5B2%5D%7D%24%u662F%u5217%u5411%u91CF%uFF0C%24%5Comega%20%5E%7B%5B2%5D%7D%24%u662F%24n%5E%7B%5B2%5D%7D%5Ctimes%20n%5E%7B%5B1%5D%7D%24%u578B%u77E9%u9635%uFF0C%24a%5E%7B%5B1%5D%7D%24%u662F%u5217%u5411%u91CF%u3002%0A%u7F51%u4E0A%u641C%u5230%u7684%u77E9%u9635%u6C42%u5BFC%u65B9%u6CD5%u7684%u5E16%u5B50%u6709%u5F88%u591A%uFF0C%u4F46%u90FD%u6CA1%u6709%u5F88%u597D%u7684%u89E3%u91CA%u4E3A%u4EC0%u4E48%24%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20%5Comega%5E%7B%5B2%5D%7D%7D%20%3D%20a%5E%7B%5B1%5DT%7D%24%u3002%0A%u6839%u636E%u6211%u81EA%u5DF1%u7684%u7406%u89E3%uFF0C%24%5Comega%20%5E%7B%5B2%5D%7D%24%u53EF%u4EE5%u770B%u4F5C%24n%5E%7B%5B1%5D%7D%24%u4E2A%u5217%u5411%u91CF%u3002%24z%5E%7B%5B2%5D%7D%24%u5173%u4E8E%24%5Comega%5E%7B%5B2%5D%7D%24%u7684%u5BFC%u6570%u5C31%u662F%u5BF9%u6240%u6709%u5217%u5411%u91CF%u7684%u5BFC%u6570%u7684stack%u3002%0A%u56E0%u4E3A%0A%24%24z_%7B%28i%29%7D%20%3D%20%5CSigma_%7Bj%3D0%7D%5E%7Bn%5E%7B%5B1%5D%7D-1%7D%20%5Comega_%7B%28i%29%28j%29%7Da_%7B%28j%29%7D%24%24%0A%u6240%u4EE5%0A%24%24%5Cdfrac%20%7B%5Cpartial%20z%5E%7B%5B2%5D%7D%7D%7B%5Cpartial%20%5Comega_%7B%28j%29%7D%7D%20%3D%20a_%7B%28j%29%7D%24%24%0Astack%u5230%u4E00%u5757%u513F%u5C31%u662F%24%5Ba_%7B%280%29%7D%2C%20a_%7B%281%29%7D...a_%7B%28n-1%29%7D%5D%20%3D%20a%5ET%24%0A%u6240%u4EE5%u5F97%u8BC1%u3002%20%0A%0A%23%23%23%20Vectorization%0A%0A%0A%0A%0A%23%23%23%23%20Forward%20propagation%0A%24Z%5E%7B%5B1%5D%7D%20%3D%20W%5E%7B%5B1%5D%7DX%20+%20b%5E%7B%5B1%5D%7D%24%0A%24A%5E%7B%5B1%5D%7D%20%3D%20g%5E%7B%5B1%5D%7D%28Z%5E%7B%5B1%5D%7D%29%24%0A%24Z%5E%7B%5B2%5D%7D%20%3D%20W%5E%7B%5B2%5D%7DA%5E%7B%5B1%5D%7D%20+%20b%5E%7B%5B2%5D%7D%24%0A%24A%5E%7B%5B2%5D%7D%20%3D%20g%5E%7B%5B2%5D%7D%28Z%5E%7B%5B2%5D%7D%29%20%3D%20%5Csigma%28Z%5E%7B%5B2%5D%7D%29%24%0A%23%23%23%23%20Backward%20propagation%0A%24dZ%5E%7B%5B2%5D%7D%20%3D%20A%5E%7B%5B2%5D%7D%20-%20Y%24%0A%24dW%5E%7B%5B2%5D%7D%20%3D%20%5Cdfrac%20%7B1%7D%7Bm%7D%20dZ%5E%7B%5B2%5D%7DA%5E%7B%5B1%5DT%7D%24%0A%24db%5E%7B%5B2%5D%7D%20%3D%20%5Cdfrac%20%7B1%7D%7Bm%7D%20np.sum%28dZ%5E%7B%5B2%5D%7D%2C%20axis%3D1%2C%20keepdims%3DTrue%29%24%0A%24dZ%5E%7B%5B1%5D%7D%20%3D%20W%5E%7B%5B2%5DT%7DdZ%5E%7B%5B2%5D%7D%20*%20g%5E%7B%5B1%5D%5Cprime%7D%28Z%5E%7B%5B1%5D%7D%29%24%0A%24dW%5E%7B%5B1%5D%7D%20%3D%20%5Cdfrac%20%7B1%7D%7Bm%7D%20dZ%5E%7B%5B1%5D%7DX%5ET%24%0A%24db%5E%7B%5B1%5D%7D%20%3D%20%5Cdfrac%20%7B1%7D%7Bm%7D%20np.sum%28dZ%5E%7B%5B1%5D%7D%2C%20axis%3D1%2C%20keepdims%3DTrue%29%24%0A%0A%3E%20**np.sum**%28A%2C%20axis%3D1%2C%20keepdims%3DTrue%29%20%u6C42%u53D6%u77E9%u9635A%u5404%u884C%u7684%u548C%0A%3E%20**axis**%3A%20%3D1%20%u6309%u884C%u6C42%u548C%uFF0C%3D0%20%u6309%u5217%u6C42%u548C%uFF0C%u6CA1%u6709axis%u5219%u5168%u77E9%u9635%u6C42%u548C%0A%3E%20**keepdims**%3A%20%3DTrue%20%u6C42%u548C%u51FA%u6765%u540E%u4ECD%u7136%u4FDD%u5B58%u77E9%u9635%u7ED3%u6784%uFF0C%u5373%u6309%u884C%u6C42%u548C%uFF0C%u5219%u5F97%u5230%u5217%u5411%u91CF%uFF0C%u6309%u5217%u6C42%u548C%u5F97%u5230%u884C%u5411%u91CF%uFF0C%u5168%u77E9%u9635%u6C42%u548C%u5F97%u5230%u4E00%u4E2A1x1%u77E9%u9635%u3002%0A%0A%23%23%23%23%20%u5206%u6790%0A%u5148%u770Bsingle%20training%20example%3A%20%0A%21%5BAlt%20text%5D%28./1513575221043.png%29%0A%u518D%u770Bvectorized%u7248%u672C%uFF1A%0A%21%5BAlt%20text%5D%28./1513577070931.png%29%0A%0A%u8BAD%u7EC3%u6837%u672C%u6309%u7167%u4E0B%u9762%u7684%u65B9%u6CD5stack%uFF0C%24A%5E%7B%5B1%5D%7D%24%u4E5F%u7C7B%u4F3C%u53EF%u5F97%u5982%u4E0B%uFF1A%0A%21%5BAlt%20text%7C250x0%5D%28./1513576811182.png%29%0A%u5176%u4F59%u77E9%u9635%24Z%5E%7B%5Bi%5D%7D%2C%20A%5E%7B%5Bi%5D%7D%2C%20W%5E%7B%5Bi%5D%7D%2C%20dZ%5E%7B%5Bi%5D%7D%2C%20dW%5E%7B%5Bi%5D%7D%24%u4E5F%u53EF%u7C7B%u4F3C%u5F97%u5230%u3002%0A%u7A0D%u7A0D%u9700%u8981%u6CE8%u610F%u7684%u662F%u5411%u91CF%24b%5E%7B%5Bi%5D%7D%24%uFF0CAndrew%u5728%u8BFE%u7A0B%u4E2D%u4E5F%u6CA1%u6709%u8FC7%u591A%u7684%u63D0%u5230%u3002%u8FD9%u91CC%u5199%u51FA%u6211%u7684%u7406%u89E3%u3002%0A%u9996%u5148%uFF1A%0A%24%24Z%5E%7B%5Bi%5D%7D%20%3D%20W%5E%7B%5Bi%5D%7DA%5E%7B%5Bi-1%5D%7D%20+%20b%5E%7B%5Bi%5D%7D%24%24%0A%u4E3A%u4EC0%u4E48%24b%5E%7B%5Bi%5D%7D%24%u662F%24db%5E%7B%5Bi%5D%7D%20%3D%20%5Cdfrac%20%7B1%7D%7Bm%7D%20np.sum%28dZ%5E%7B%5Bi%5D%7D%2C%20axis%3D1%2C%20keepdims%3DTrue%29%24%3F%0A%u6700%u76F4%u89C2%u7684b%u5E94%u8BE5%u662F%24b%5E%7B%5Bi%5D%7D%2C%20db%5E%7B%5Bi%5D%7D%20%5Cin%20%28n%5E%7B%5Bi-1%5D%7D%2C%20m%29%24%uFF0C%u56E0%u4E3A%24A%5E%7B%5Bi-1%5D%7D%20%5Cin%20%28n%5E%7B%5Bi-1%5D%7D%2C%20m%29%uFF0C%20W%5E%7B%5Bi%5D%7D%20%5Cin%20%28n%5E%7B%5Bi%5D%7D%2C%20n%5E%7B%5Bi-1%5D%7D%29%2C%20Z%5E%7B%5Bi%5D%7D%20%5Cin%20%28n%5E%7B%5Bi%5D%7D%2Cm%29%24%0A%u90A3%u4E3A%u4EC0%u4E48%u8981%u6309%u7167%u884C%u6C42%u548C%u518D%u6309m%u6C42%u5747%u503C%u5462%uFF1F%u56E0%u4E3A%24W%5E%7B%5Bi%5D%7D%2C%20b%5E%7B%5Bi%5D%7D%24%u4E3A%u6A21%u578B%u53C2%u6570%uFF0C%u4E0E%u6837%u672C%u65E0%u5173%u3002%u9488%u5BF9%u6BCF%u4E2A%u6837%u672Cb%2C%20db%u5E94%u5F53%u76F8%u540C%u3002%u6240%u4EE5%u8981%u6309%u4E0A%u9762%u8FD9%u4E48%u7B97%u3002%0A%0A%23%23%20%u603B%u7ED3%0A%u5728%u6D45%u5C42%u795E%u7ECF%u7F51%u7EDC%u4E2D%uFF0C%u6B63%u5411%u4F20%u64AD%u6C42%u8282%u70B9%u503C%uFF0C%u53CD%u5411%u4F20%u64AD%u5229%u7528%u94FE%u5F0F%u6CD5%u5219%u6C42%u5BFC%u6570%u3002%u5728%u5411%u91CF%u5316%u7684%u65F6%u5019%uFF0C%u9488%u5BF9%u6240%u6709%u7684%u6837%u672C%uFF0C%u5411%u91CF%u6309%u7167%u5217%u7EC4%u5408%u6210%u77E9%u9635%uFF0C%u5373%u77E9%u9635%u7684%u4E00%u5217%u5BF9%u5E94%u4E00%u4E2A%u6837%u672C%u3002%0A%0A%0A%0A%0A%0A