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.