21 / 90

Day 21: 計算圖與反向傳播的連結(複習)

這是鞏固複習日:手動沿計算圖前向再反向走一遍,證明共享節點的梯度會累加,並用同一個有限差分工具複驗本單元的全部結果。檢索與複習計入 480 分鐘台帳。

AI 數學與微積分/代數 480 分鐘主動學習(8 小時專注學習)
01 120 分鐘

計算圖:局部導數與反向累加

只有在記錄預測與觀察證據之後才允許求助。

先修條件

Day 19-20 的連鎖律與梯度練習;如有步驟不熟,先開啟當日恢復連結。

學習目標

把純量表達式分解為計算圖,計算每個節點的前向值,再逐條邊乘以局部連鎖因子反向傳播導數。

操作說明

取 L = (a*b + c)^2,a = 2,b = 3,c = 1。前向:n1 = a*b = 6,n2 = n1 + c = 7,L = n2^2 = 49。反向:dL/dn2 = 2*n2 = 14;dL/dn1 = 14 * ∂n2/∂n1 = 14 * 1 = 14;dL/dc = 14 * ∂n2/∂c = 14;dL/da = 14 * ∂n1/∂a = 14 * b = 42;dL/db = 14 * ∂n1/∂b = 14 * a = 28。每一步都是 Day 19-20 連鎖律作用在一條局部邊上。在程式碼中擾動 a 之前先預測 dL/da。

練習與預測記錄

畫出 (2, 3, 1) 處 L = (a*b + c)^2 的計算圖,填入前向值 6、7、49,再手算所有輸入梯度。用中央有限差分驗證 dL/da、dL/db、dL/dc 並記錄一致性。

獨立掌握標準

無幫助下重現前向值 6、7、49 與反向值 42、28、14,說出每條邊上的局部導數,且你的有限差分執行與每個手算梯度一致。

權威來源資源與出處

linking MIT

micrograd: A tiny scalar-valued autograd engine

作者/機構: Andrej Karpathy | 原始連結 ↗

相關章節/時間戳: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

驗證版本與日期: 2022 (verified 2026-10-30)

選擇理由:

The scalar computational graph in this lesson is exactly the micrograd engine walkthrough; it previews the autograd project without importing any material.

來源先修知識:

Chain rule and partial derivatives (Study Days 19-20).

安全回退(離線韌性):

The full forward and backward pass is derived locally with numeric verification; no video is required.

候選來源比較與選擇分析 (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

作者/機構: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始連結 ↗

相關章節/時間戳: Section 4.5: tree-diagram rule used to justify backward accumulation

驗證版本與日期: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

選擇理由:

Provides the formal chain rule statement that the graph walkthrough applies node by node.

來源先修知識:

Scalar chain rule (day-19) and partial derivatives (day-20).

安全回退(離線韌性):

The derivation uses only local rules already proven on Days 19-20.

候選來源比較與選擇分析 (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.

02 120 分鐘

共享節點:梯度貢獻為何累加

獨立練習:先預測並保留已記錄的無協助嘗試;之後的任何幫助屬於單獨的「協助式補救」階段,須再通過一次新的同等無協助檢查,該概念才算獨立證據。

先修條件

完成上一項活動;若受阻請使用列出的恢復連結。

學習目標

證明一個節點供給兩個消費方時,其總梯度是兩份貢獻之和,並用直接代入驗證可複用變數反例。

操作說明

情形 1:L = (a + 1)^2,a = 2。寫成 L = u * v,其中 u = a + 1、v = a + 1——變數 a 被兩個因子共享,沿兩條路徑影響 L。路徑視角:u 路徑貢獻 v * du/da = u * 1 = u,v 路徑貢獻 u * dv/da = u,總計 dL/da = 2u = 6(a = 2 時)。單路徑答案 3 就是反例錯誤。情形 2:w = (u + v)^2,u = x^2,v = 2x,x = 1:dw/dx = 2(u + v) * (2x + 2) = 2 * 3 * 4 = 24。 若在保留的嘗試之後求助,按「協助式補救」處理:原嘗試保持不變,在稱為已補救之前須通過一次新的同等無協助檢查。

練習與預測記錄

計算並驗證:(a) L = (a + 1)^2 在 a = 2 處的 dL/da——寫出兩條路徑的貢獻與錯誤的單路徑值;(b) w = (u + v)^2,u = x^2,v = 2x 在 x = 1 處的 dw/dx——分別用樹形法則和展開 (x^2 + 2x)^2。

獨立掌握標準

無幫助下找出進入共享節點的每條路徑,給出 6 和 24 並各配獨立檢驗,能解釋丟掉一條路徑為何恰好少計該路徑的貢獻。

權威來源資源與出處

linking MIT

micrograd: A tiny scalar-valued autograd engine

作者/機構: Andrej Karpathy | 原始連結 ↗

相關章節/時間戳: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

驗證版本與日期: 2022 (verified 2026-10-30)

選擇理由:

The reusable-variable counterexample in this activity mirrors the accumulation behavior a correct engine must implement.

來源先修知識:

Computational graph walkthrough (day-21-act-01).

安全回退(離線韌性):

The counterexample is proven locally by direct substitution and a finite-difference check.

候選來源比較與選擇分析 (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

作者/機構: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始連結 ↗

相關章節/時間戳: Section 4.5: sum over all dependency paths when a variable is reused

驗證版本與日期: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

選擇理由:

States the rule that total derivatives add contributions along every path, which the counterexample verifies.

來源先修知識:

Scalar chain rule (day-19) and partial derivatives (day-20).

安全回退(離線韌性):

The proof reduces the composition to a single-variable expansion, independent of the external source.

候選來源比較與選擇分析 (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.

03 120 分鐘

有限差分驗證工具與檢索複習

只有在記錄預測與觀察證據之後才允許求助。

先修條件

完成上一項活動;若受阻請使用列出的恢復連結。

學習目標

編寫一個可複用的中央差分工具,複驗本單元的關鍵數字,鞏固 Days 16-20;隨後對本單元定義做一次閉卷檢索。

操作說明

寫出工具 def central_fd(f, x, h=1e-5): return (f(x + h) - f(x - h)) / (2 * h),並在執行前預測每一行:d/dx (3x + 1)^2 在 x = 1 -> 24;d/dx (5x - 2)^3 在 x = 1 -> 135;d/dx (x^2 + 1)^2 在 x = 2 -> 40;x^2 y + 3y - x 在 (2, 1) 的 ∂/∂x 與 ∂/∂y -> 3 與 7;x^2 + y^2 在 (3, 4) 的梯度模長 -> 10;L = (a*b + c)^2 在 (2, 3, 1) 的 dL/da、dL/db、dL/dc -> 42、28、14。

練習與預測記錄

對全部六行執行工具,然後合上筆記憑記憶檢索:導數的極限定義、連鎖律陳述、偏導數定義、梯度模長性質、共享變數的路徑求和規則。標記任何遺漏。

獨立掌握標準

所有工具行與預測值四位小數一致,檢索清單完整複現五條陳述且至多一處標記遺漏並附恢復計畫。

權威來源資源與出處

linking PSF License Version 2

The Python Tutorial: Numbers and Expressions

作者/機構: Python Software Foundation | 原始連結 ↗

相關章節/時間戳: Section 3.1.1 Numbers: arithmetic used by the verification harness

驗證版本與日期: Python 3.12 documentation (verified 2026-10-30)

選擇理由:

Reference for the arithmetic in the central finite-difference helper reused across the block.

來源先修知識:

Able to run a short Python file from the terminal.

安全回退(離線韌性):

The harness listing is embedded and runs on a standard Python install.

候選來源比較與選擇分析 (2)
math — Mathematical functions ↗ compared_alternative [PSF License Version 2]

Extends the operator set to transcendental functions; kept as a follow-on once the arithmetic expressions are fluent.

The Python Tutorial: Floating Point Arithmetic Issues ↗ compared_alternative [PSF License Version 2]

Explains binary float representation limits; deferred to the numerics days where tolerance reasoning is rehearsed.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 1

作者/機構: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始連結 ↗

相關章節/時間戳: Sections 3.1-3.6 review scope for the block retrieval check

驗證版本與日期: OpenStax Calculus Volume 1 web edition (verified 2026-10-30)

選擇理由:

Optional drill source for extra derivative review during the consolidation block.

來源先修知識:

Derivative rules for powers and polynomials (Study Days 16-18).

安全回退(離線韌性):

The retrieval checklist is self-contained in the lesson.

候選來源比較與選擇分析 (3)
MIT OpenCourseWare 18.01SC Single Variable Calculus ↗ compared_selected_for_visual_practice [CC BY-NC-SA 4.0]

Strong exercises and transcripts, but the noncommercial share-alike terms and course navigation make OpenStax the primary stable text.

Paul's Online Math Notes: Calculus I ↗ compared_rejected_for_reuse [All Rights Reserved]

Useful reference, but rights and redistribution terms are less suitable for embedded recovery material.

SciPy Numerical Differentiation Documentation ↗ compared_selected_for_numerics [BSD-3-Clause]

A primary API reference for numerical derivative step-size behavior; it complements rather than replaces the hand derivation.

04 120 分鐘

單元複習評估:圖梯度、邊界情形與恢復計畫

獨立掌握檢查(不使用 AI 協助)。

先修條件

完成上一項活動;若受阻請使用列出的恢復連結。

學習目標

獨立計算小型計算圖的全部輸入梯度,處理一個不可微邊界,並給出把每個薄弱點映射到複習日的恢復計畫。

操作說明

閉卷、不用 AI。第 1 部分:L = (a*b)^2 + c,a = 1,b = 2,c = 3。前向:n1 = a*b = 2,n2 = n1^2 = 4,L = n2 + c = 7。手算反向的 dL/da、dL/db、dL/dc。第 2 部分:ReLU 節點 f(x) = max(0, x) 在 x = 0 處左斜率 0、右斜率 1。說明其導數是否存在、引擎通常採用什麼約定、以及為何下游梯度仍需小心。第 3 部分:寫一份恢復計畫,把每個遺漏結果映射到講授它的那天(Days 16-18 極限/導數、19 連鎖律、20 梯度)。

練習與預測記錄

提交:三個梯度及前向節點值、ReLU 邊界結論、你的恢復計畫。提交前先數值驗證第 1 部分。

獨立掌握標準

無幫助下:前向值 2、4、7 與梯度 8、4、1 經數值驗證;ReLU 結論區分「不存在」與「約定取 0」;恢復計畫把每個遺漏映射到具體日期。

權威來源資源與出處

linking MIT

micrograd: A tiny scalar-valued autograd engine

作者/機構: Andrej Karpathy | 原始連結 ↗

相關章節/時間戳: micrograd/engine.py: class Value (_backward closures and backward() topological sort); README 'Example usage'

驗證版本與日期: 2022 (verified 2026-10-30)

選擇理由:

Optional preview of the autograd engine that the independent graph computation imitates.

來源先修知識:

All of Study Days 19-21 activities 1-3.

安全回退(離線韌性):

The assessment is fully specified locally with a worked reference answer.

候選來源比較與選擇分析 (2)
PyTorch Autograd Internals ↗ compared_alternative [Modified BSD]

Normative production documentation, but micrograd's pure Python implementation provides far superior initial clarity.

3Blue1Brown: What is Backpropagation? ↗ compared_alternative [3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions]

High visual quality, pairs cleanly as optional supplementary visual reference.

linking CC BY-NC-SA 4.0 attribution noncommercial share-alike

OpenStax Calculus Volume 3

作者/機構: OpenStax, Rice University (Gilbert Strang, Edwin Herman, et al.) | 原始連結 ↗

相關章節/時間戳: Section 4.6: gradients exist only where partials exist; review scope for edge cases

驗證版本與日期: OpenStax Calculus Volume 3 web edition (verified 2026-10-30)

選擇理由:

Frames the ReLU kink edge case reviewed in the block assessment.

來源先修知識:

Partial derivatives and the multivariable chain rule.

安全回退(離線韌性):

The edge case is resolved locally with left and right slopes.

候選來源比較與選擇分析 (2)

Selected as the lecture-depth companion for partial derivatives; OpenStax Volume 3 remains the written primary reference.

Khan Academy: Multivariable Calculus ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong visual coverage of gradients, but the OpenStax text better matches the lesson's theorem-plus-hand-check structure.