惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Schneier on Security
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
A
Arctic Wolf
Security Latest
Security Latest
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Troy Hunt's Blog
Latest news
Latest news
Help Net Security
Help Net Security
S
Security Affairs
Webroot Blog
Webroot Blog
The Hacker News
The Hacker News
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tor Project blog
Forbes - Security
Forbes - Security
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
Attack and Defense Labs
Attack and Defense Labs
P
Proofpoint News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Help Net Security
L
Lohrmann on Cybersecurity
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog
Cyberwarzone
Cyberwarzone
The Last Watchdog
The Last Watchdog
S
Securelist
N
News and Events Feed by Topic
S
Secure Thoughts
F
Fortinet All Blogs
博客园_首页
C
Cybersecurity and Infrastructure Security Agency CISA
量子位
M
MIT News - Artificial intelligence
F
Full Disclosure
T
The Blog of Author Tim Ferriss
T
Tailwind CSS Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ
P
Privacy International News Feed
L
LangChain Blog
Know Your Adversary
Know Your Adversary
C
CERT Recently Published Vulnerability Notes

Louis C Deng's Blog

CS231n Lecture Note: Generative Models CS231n Lecture Note: Self-Supervised Learning CS231n Lecture Note: Large Scale Distributed Training 自動微分 | DIY 實現自己的 PyTorch From RNNs to Transformers CS231n Lecture Note VII: Recurrent Neural Networks Uncovering Batch & Layer Normalization CS231n Lecture Note VI: CNN Architectures and Training CS231n Lecture Note V: Convolution Neural Networks Basics Demystifying Softmax Loss: A Step-by-Step Derivation for Linear Classifiers CS231n Lecture Note IV: Neural Networks and Backpropagation CS231n Lecture Note III: Optimization CS231n Lecture Note II: Linear Classifiers CS231n Lecture Note I: Image Classification CSAPP Cache Lab II: Optimizing Matrix Transposition CSAPP Cache Lab I: Let's simulate a cache memory! CS188 Search Lecture Notes III CS188 Search Lecture Notes II How to Use TouchID for Sudo Commands on macOS CS188 Search Lecture Notes I RECAP2025: 留白 CSAPP Bomb Lab 解析 x64 暫存器速查表 CSAPP Data Lab 解析 矩陣的 Modified Gram Schmidt 方法 聊一聊位掩碼(Bit Mask) 整數溢位與未定義行為 快速排序 幾種劃分方法討論 等待 記夢(DeepSeek 輔助創作) 午夜飛行 橋樑 黎明 或 2012 RECAP2024: 水檻臥聽雨 太陽、潮落 RECAP2023: 泡沫 題解 P1622 釋放囚犯 題解 P5888 傳球遊戲 殘陽似火 再會 飢餓藝術家 卡夫卡 Python 中的 zip() 和 enumerate() 泡沫 “救救孩子……”——談魯迅和《狂人日記》 想念 淺灘 蟬 · 夏 微風 觀星 浮塵 復活 【摘錄 | 轉載】普魯斯特 《追憶似水年華》第一卷 《在斯萬家那邊》(一) Time - Pink Floyd - The Dark Side of the Moon 【轉載】靜夜思變調 高樓 幻夢 冰 RECAP2022: 流星雨 清夜 割點 Tarjan 演算法 P3147 USACO16OPEN 262144 P 題解 P3354 Riv 河流 題解 馬拉車演算法 夜雨 層霧 從愚人節玩笑到真的玩笑(bushi): 淺談 lsnotes I made my own Hexo theme 題解 紀念品分組 題解 導彈攔截 如何高效使用搜尋引擎 用 GitHub Actions 格式化 C/C++ 程式碼 四季的天空 洛谷 7 月月賽 Div.2 總結 題解 最近公共祖先 (LCA) 用簡單的物理方法證明牛頓萊布尼茨公式 簡評榮耀手環6 海上生明月,天涯共此時。 我為什麼重新拿出了 iPod Swift 中的 SharedPreferance —— UserDefaults 凝視那一輪明月 用 GitHub Actions 部署 Hexo 部落格 遲來的日誌 - WWDC 2020 獎學金 vcpkg - 方便的 C/C++ 庫管理器 vimrc 配置指南 NextCloud - DIY NAS 解決方案 sudo shutdown -r now sudo shutdown -r now
Backpropagation: A Vector Calculus Perspective
Louis C Deng · 2026-02-14 · via Louis C Deng's Blog

The primary goal of backpropagation is to calculate the partial derivatives of the cost function CC with respect to every weight W\mathbf{W} and bias b\mathbf{b} in the network.

1. Notation (Matrix Form)

To facilitate a clean derivation using matrix calculus, we adopt the following conventions:

  • al\mathbf{a}^l: Activation vector of the ll-th layer (nl×1n_l \times 1).
  • zl\mathbf{z}^l: Weighted input vector of the ll-th layer (nl×1n_l \times 1), where zl=Wlal−1+bl\mathbf{z}^l = \mathbf{W}^l \mathbf{a}^{l-1} + \mathbf{b}^l.
  • Wl\mathbf{W}^l: Weight matrix of the ll-th layer (nl×nl−1n_l \times n_{l-1}).
  • bl\mathbf{b}^l: Bias vector of the ll-th layer (nl×1n_l \times 1).
  • δl\boldsymbol{\delta}^l: Error vector of the ll-th layer, defined as δl≡∂C∂zl\boldsymbol{\delta}^l \equiv \frac{\partial C}{\partial \mathbf{z}^l}.
  • ⊙\odot: Hadamard product (element-wise multiplication).
  • σ′(zl)\sigma'(\mathbf{z}^l): The derivative of the activation function applied element-wise to zl\mathbf{z}^l.

2. Derivation of the Equations

BP1: Error at the Output Layer

Goal: δL=∇aLC⊙σ′(zL)\boldsymbol{\delta}^L = \nabla_{\mathbf{a}^L} C \odot \sigma'(\mathbf{z}^L)

Derivation Steps:

  1. Apply the Chain Rule: The error δL\boldsymbol{\delta}^L represents how the cost CC changes with respect to the weighted input zL\mathbf{z}^L. Since CC depends on zL\mathbf{z}^L through the activations aL\mathbf{a}^L:

δL=∂C∂zL=(∂aL∂zL)T∂C∂aL\boldsymbol{\delta}^L = \frac{\partial C}{\partial \mathbf{z}^L} = \left( \frac{\partial \mathbf{a}^L}{\partial \mathbf{z}^L} \right)^T \frac{\partial C}{\partial \mathbf{a}^L}

  1. Compute the Jacobian: Because ajL=σ(zjL)a^L_j = \sigma(z^L_j) (each output depends only on its own input), the Jacobian matrix ∂aL∂zL\frac{\partial \mathbf{a}^L}{\partial \mathbf{z}^L} is a diagonal matrix:

∂aL∂zL=diag(σ′(z1L),…,σ′(znL))\frac{\partial \mathbf{a}^L}{\partial \mathbf{z}^L} = \text{diag}(\sigma'(z^L_1), \dots, \sigma'(z^L_n))

  1. Result: Multiplying a diagonal matrix by a vector is equivalent to the Hadamard product:

δL=∇aLC⊙σ′(zL)\boldsymbol{\delta}^L = \nabla_{\mathbf{a}^L} C \odot \sigma'(\mathbf{z}^L)

BP2: Propagating Error to Hidden Layers

Goal: δl=((Wl+1)Tδl+1)⊙σ′(zl)\boldsymbol{\delta}^l = ((\mathbf{W}^{l+1})^T \boldsymbol{\delta}^{l+1}) \odot \sigma'(\mathbf{z}^l)

Derivation Steps:

  1. Link Consecutive Layers: We express the error at layer ll in terms of the error at layer l+1l+1 using the multivariate chain rule:

δl=∂C∂zl=(∂zl+1∂zl)T∂C∂zl+1=(∂zl+1∂zl)Tδl+1\boldsymbol{\delta}^l = \frac{\partial C}{\partial \mathbf{z}^l} = \left( \frac{\partial \mathbf{z}^{l+1}}{\partial \mathbf{z}^l} \right)^T \frac{\partial C}{\partial \mathbf{z}^{l+1}} = \left( \frac{\partial \mathbf{z}^{l+1}}{\partial \mathbf{z}^l} \right)^T \boldsymbol{\delta}^{l+1}

  1. Differentiate the Linear Transformation: Recall zl+1=Wl+1al+bl+1\mathbf{z}^{l+1} = \mathbf{W}^{l+1} \mathbf{a}^l + \mathbf{b}^{l+1} and al=σ(zl)\mathbf{a}^l = \sigma(\mathbf{z}^l). Applying the chain rule to find ∂zl+1∂zl\frac{\partial \mathbf{z}^{l+1}}{\partial \mathbf{z}^l}:

∂zl+1∂zl=∂zl+1∂al⋅∂al∂zl=Wl+1⋅diag(σ′(zl))\frac{\partial \mathbf{z}^{l+1}}{\partial \mathbf{z}^l} = \frac{\partial \mathbf{z}^{l+1}}{\partial \mathbf{a}^l} \cdot \frac{\partial \mathbf{a}^l}{\partial \mathbf{z}^l} = \mathbf{W}^{l+1} \cdot \text{diag}(\sigma'(\mathbf{z}^l))

  1. Transpose and Simplify: Substitute back and use the property (AB)T=BTAT(AB)^T = B^T A^T:

δl=(Wl+1⋅diag(σ′(zl)))Tδl+1=diag(σ′(zl))(Wl+1)Tδl+1\boldsymbol{\delta}^l = \left( \mathbf{W}^{l+1} \cdot \text{diag}(\sigma'(\mathbf{z}^l)) \right)^T \boldsymbol{\delta}^{l+1} = \text{diag}(\sigma'(\mathbf{z}^l)) (\mathbf{W}^{l+1})^T \boldsymbol{\delta}^{l+1}

  1. Final Form:
    Convert the diagonal matrix multiplication to a Hadamard product:

δl=((Wl+1)Tδl+1)⊙σ′(zl)\boldsymbol{\delta}^l = ((\mathbf{W}^{l+1})^T \boldsymbol{\delta}^{l+1}) \odot \sigma'(\mathbf{z}^l)

BP3: Gradient for Biases

Goal: ∂C∂bl=δl\frac{\partial C}{\partial \mathbf{b}^l} = \boldsymbol{\delta}^l

Derivation Steps:

  1. Chain Rule via Intermediate zz:

∂C∂bl=(∂zl∂bl)T∂C∂zl\frac{\partial C}{\partial \mathbf{b}^l} = \left( \frac{\partial \mathbf{z}^l}{\partial \mathbf{b}^l} \right)^T \frac{\partial C}{\partial \mathbf{z}^l}

  1. Compute Local Gradient: From zl=Wlal−1+bl\mathbf{z}^l = \mathbf{W}^l \mathbf{a}^{l-1} + \mathbf{b}^l, we see that bl\mathbf{b}^l is added directly to the weighted sum. Thus, ∂zl∂bl\frac{\partial \mathbf{z}^l}{\partial \mathbf{b}^l} is the Identity matrix I\mathbf{I}.

  2. Conclusion:

∂C∂bl=ITδl=δl\frac{\partial C}{\partial \mathbf{b}^l} = \mathbf{I}^T \boldsymbol{\delta}^l = \boldsymbol{\delta}^l

BP4: Gradient for Weights

Goal: ∂C∂Wl=δl(al−1)T\frac{\partial C}{\partial \mathbf{W}^l} = \boldsymbol{\delta}^l (\mathbf{a}^{l-1})^T

Derivation Steps:

  1. Element-wise Approach: Consider a single weight wjklw^l_{jk} connecting neuron kk in layer l−1l-1 to neuron jj in layer ll:

∂C∂wjkl=∂C∂zjl∂zjl∂wjkl=δjl∂zjl∂wjkl\frac{\partial C}{\partial w^l_{jk}} = \frac{\partial C}{\partial z^l_j} \frac{\partial z^l_j}{\partial w^l_{jk}} = \delta^l_j \frac{\partial z^l_j}{\partial w^l_{jk}}

  1. Solve for Partial Derivative: Since zjl=∑mwjmlaml−1+bjlz^l_j = \sum_m w^l_{jm} a^{l-1}_m + b^l_j, the derivative with respect to wjklw^l_{jk} is simply akl−1a^{l-1}_k. Therefore, ∂C∂wjkl=δjlakl−1\frac{\partial C}{\partial w^l_{jk}} = \delta^l_j a^{l-1}_k.

  2. Vectorize as an Outer Product: The collection of all such derivatives δjlakl−1\delta^l_j a^{l-1}_k for all j,kj, k forms the Outer Product of the error vector δl\boldsymbol{\delta}^l and the input activation vector al−1\mathbf{a}^{l-1}:

∂C∂Wl=δl(al−1)T\frac{\partial C}{\partial \mathbf{W}^l} = \boldsymbol{\delta}^l (\mathbf{a}^{l-1})^T