手算反向傳播:輸出層誤差項與參數梯度
Agent輔助工程檢查
前置要求
第34日 N1 的前向賬本:$o=3.1255$,$L=4.5179$。
學習目標
對 N1 的線性輸出與平方損失 $L=(o - y)^2$ 分步應用鏈式法則,求輸出誤差項與三個輸出層參數梯度。
操作指引
先推符號,再代數值。N1 的輸出是線性單元 $o=w_{o1}a_1+w_{o2}a_2+b_o$,不是 sigmoid;損失沒有 $1/2$ 係數。
1. $\delta_o=\partial L/\partial o=2(o-y)$。
2. 局部輸入導數為 $\partial o/\partial a_1=w_{o1}$、$\partial o/\partial a_2=w_{o2}$。
3. 局部參數導數為 $a_1$、$a_2$、$1$,因此參數梯度是上游 $\delta_o$ 乘局部導數。
4. 使用第34日 $a_1=0.8741$、$a_2=-0.9757$、$o=3.1255$、$y=1.0$ 預測三個輸出梯度,再看答案。
自主實作與記錄
1. 推導 $\delta_o$。2. 算出兩個輸出權重與偏置的梯度。3. 解釋線性單元偏置的局部導數為何是1。4. 指出傳到 $a_1$ 的梯度還需通過哪個激活導數才能到達 $z_1$。
$\delta_o=2(3.1255-1.0)=4.2511$;權重乘對應激活,偏置的局部導數是1。
$\delta_o=4.2511$;$\partial L/\partial w_{o1}=4.2511\times0.8741=3.7157$,$\partial L/\partial w_{o2}=4.2511\times(-0.9757)=-4.1480$,$\partial L/\partial b_o=4.2511$。偏置以係數1進入線性輸出。到達 $a_1$ 的梯度是 $\delta_o w_{o1}=4.2511$,還需乘 $\tanh'(z_1)=1-a_1^2$。
不看答案重現全部三個輸出梯度(3.7157、-4.1480、4.2511),與引擎誤差小於 $10^{-3}$,並解釋上游乘局部的結構。
權威來源資源與權利證明
Neural Networks and Deep Learning: How the backpropagation algorithm works
對應章節 / 時間戳: The four fundamental equations of backpropagation
驗證版本與日期: Online book (Verified: 2026-10-30)
Clear four-equation derivation of backpropagation with scalar and matrix notation.
Matrix multiplication and the multivariable chain rule from Days 19-24.
All four backprop equations and derivations are self-contained within the lesson text.
對比候選資源與選型分析 (2)
Comprehensive graduate reference, but heavier tensor notation than needed for first MLP derivations.
Modular computational graph view; used as secondary source on Days 35-36.
CS231n: Backpropagation and Intuitions
對應章節 / 時間戳: Patterns in backward flow
驗證版本與日期: Course notes (Verified: 2026-10-30)
Modular local-gradient interpretation (gate operations: add, multiply, max) and gradient flow intuition.
Multivariable calculus and basic Python.
Local gate definitions and circuit flow diagrams in the lesson provide full coverage.
對比候選資源與選型分析 (2)
Raw circuit view; CS231n notes are more structured with explicit gate derivations.
Top-down approach; CS231n bottom-up modular view matches our first-principles curriculum.