30 / 90

第 30 天:優化——梯度下降及其失敗模式

在凸碗形函數上手推梯度下降更新,構造發散與慢爬反例,解釋鞍點,並練習不虛構成功的失敗分析。本日收束數學模組。

數學與演算法基礎 480 分鐘有效學習(8 小時專注學習)
01 120 分鐘

凸碗形函數上的梯度下降機制

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

前置要求

完成第 29 天評估;掌握數學模組中的單變數微分(冪法則)。

學習目標

推導梯度下降更新 x ← x − η·2x = x(1 − 2η),並由因子 (1 − 2η) 預測整條優化軌跡。

操作指引

這裡的優化指迭代地降低損失。在 f(x) = x² 上梯度為 2x,每步把 x 乘以 (1 − 2η)。從 x₀ = 4、η = 0.1 出發,因子為 0.8:x₁ = 3.2、x₂ = 2.56、x₃ = 2.048,一般地 x_k = 4·0.8^k。先手工推演,再用短 Python 迴圈確認。注意 η = 0.5 時因子為 0——在這個純二次函數上一步收斂。

自主實作與記錄

對 f(x) = x²、x₀ = 4:(a) 寫出 x_k 的閉式;(b) 計算 η = 0.1 時的 x₁、x₂、x₃ 與 x₁₀;(c) 對 f(x) = (a/2)x²,因子為 (1 − ηa)——推導穩定條件 |1 − ηa| < 1 及其蘊含的學習率上界。

獨立掌握標準

閉式推導正確,四個迭代值全部正確,並陳述 η < 2/a 條件及 a = 2 的特例。

權威來源資源與權利證明

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

作者 / 機構: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | 原始出處連結 ↗

對應章節 / 時間戳: Chapter Optimization Algorithms: Gradient Descent

驗證版本與日期: Current online edition (Verified: 2026-10-30)

入選理由:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

來源前置條件:

Linear algebra, calculus, and probability at the Days 19-28 level.

安全回退方案(離線彈性):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

對比候選資源與選型分析 (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Gradient Descent, How Neural Networks Learn

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Neural networks chapter 2: the gradient and the descent update

驗證版本與日期: Neural networks series chapter 2, 2017 (Verified: 2026-10-30)

入選理由:

Visual intuition connecting the gradient vector to steepest descent; complements d2l.ai's worked equations for the optimization day.

來源前置條件:

High-school functions and slope intuition.

安全回退方案(離線彈性):

The lesson contains complete derivations and numerical traces; the video is optional visual intuition.

對比候選資源與選型分析 (2)
Convex Optimization (Boyd and Vandenberghe) ↗ compared_alternative [Cambridge University Press; free PDF for individual use]

A detailed optimization text, kept as an advanced alternative; its scope exceeds a single study day.

Deep Learning chapter 8 (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Rigorous discussion of saddle points and plateaus in high-dimensional optimization; kept as a linking-only alternative.

02 120 分鐘

不穩定的步長:發散與慢爬

獨立掌握檢查(無 AI 輔助)。

前置要求

完成活動 30-01;不使用 AI 輔助。

學習目標

在同一函數上構造三種優化失敗形態——發散振盪、凍結振盪與慢爬——並按因子 (1 − 2η) 對任意 η 分類。

操作指引

在優化中,因子 (1 − 2η) 決定一切:|因子| < 1 收斂;因子 = −1 永遠振盪;|因子| > 1 帶交替符號發散;小的正因子收斂慢到沒有意義。在 f(x) = x²、x₀ = 4 上計算每種形態,並誠實記錄軌跡——這些是真實失敗模式,不是異常。

自主實作與記錄

在 f(x) = x²、x₀ = 4 上分類並追蹤:(a) η = 1.2 → x₁、x₂、x₃ 與 |x₁₀|;(b) η = 1.0 → 第 1 步之後的軌跡;(c) η = 0.01 → x₁₀,以及為什麼這個『能跑』的學習率仍是實際失敗;(d) 為每種形態命名。

獨立掌握標準

三條軌跡全部正確,每種形態連同其因子命名,並解釋為什麼『損失下降』是必要而非充分條件。

權威來源資源與權利證明

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

作者 / 機構: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | 原始出處連結 ↗

對應章節 / 時間戳: Chapter Optimization Algorithms: Gradient Descent; learning-rate selection

驗證版本與日期: Current online edition (Verified: 2026-10-30)

入選理由:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

來源前置條件:

Linear algebra, calculus, and probability at the Days 19-28 level.

安全回退方案(離線彈性):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

對比候選資源與選型分析 (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Gradient Descent, How Neural Networks Learn

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Neural networks chapter 2: step size intuition

驗證版本與日期: Neural networks series chapter 2, 2017 (Verified: 2026-10-30)

入選理由:

Visual intuition connecting the gradient vector to steepest descent; complements d2l.ai's worked equations for the optimization day.

來源前置條件:

High-school functions and slope intuition.

安全回退方案(離線彈性):

The lesson contains complete derivations and numerical traces; the video is optional visual intuition.

對比候選資源與選型分析 (2)
Convex Optimization (Boyd and Vandenberghe) ↗ compared_alternative [Cambridge University Press; free PDF for individual use]

A detailed optimization text, kept as an advanced alternative; its scope exceeds a single study day.

Deep Learning chapter 8 (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Rigorous discussion of saddle points and plateaus in high-dimensional optimization; kept as a linking-only alternative.

03 120 分鐘

鞍點與誠實的失敗分析

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

前置要求

完成活動 30-02;求助前先預測。

學習目標

用 f(x,y) = x² − y² 解釋為什麼梯度為零不是極小值,並練習在不虛構成功的前提下報告優化失敗。

操作指引

在鞍點處梯度為 0,但該點不是極小值:對 f(x,y) = x² − y²,原點在 x 方向是極小、在 y 方向是極大。梯度下降按 x ← x(1−2η) 更新,但 y ← y(1+2η):精確算術中 y = 0 保持為 0,所以從 (0.5, 0) 出發會收斂到 (0,0)——一個鞍點——而微小的 y₀ = 0.001 會緩慢逃出(y₁₀ ≈ 0.006,到 k = 20 時 f 已為負)。失敗分析規則:報告觀察到的軌跡、診斷出的原因與修復——永遠不要把失敗粉飾成成功。

自主實作與記錄

(a) 驗證 ∇f = (2x, −2y) 在 (0,0) 處為零,且對任意 ε ≠ 0 有 f(0, ε) = −ε² < 0。(b) 從 (0.5, 0) 以 η = 0.1 出發,10 步後梯度下降到達哪裡?該點是極小值嗎?(c) 訓練日誌顯示損失 2.0 → 2.6 → 3.5 → 4.9 → 6.8:寫誠實的失敗分析條目——原因假設、修復、複查。

獨立掌握標準

用 −ε² 論證驗證鞍點,被困軌跡計算正確,失敗條目記錄原因、修復與複查且不虛構改進。

權威來源資源與權利證明

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

作者 / 機構: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | 原始出處連結 ↗

對應章節 / 時間戳: Chapter Optimization Algorithms: Optimization and Deep Learning (local minima, saddle points)

驗證版本與日期: Current online edition (Verified: 2026-10-30)

入選理由:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

來源前置條件:

Linear algebra, calculus, and probability at the Days 19-28 level.

安全回退方案(離線彈性):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

對比候選資源與選型分析 (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Gradient Descent, How Neural Networks Learn

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Neural networks chapter 2: valleys, plateaus, and saddle intuition

驗證版本與日期: Neural networks series chapter 2, 2017 (Verified: 2026-10-30)

入選理由:

Visual intuition connecting the gradient vector to steepest descent; complements d2l.ai's worked equations for the optimization day.

來源前置條件:

High-school functions and slope intuition.

安全回退方案(離線彈性):

The lesson contains complete derivations and numerical traces; the video is optional visual intuition.

對比候選資源與選型分析 (2)
Convex Optimization (Boyd and Vandenberghe) ↗ compared_alternative [Cambridge University Press; free PDF for individual use]

A detailed optimization text, kept as an advanced alternative; its scope exceeds a single study day.

Deep Learning chapter 8 (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Rigorous discussion of saddle points and plateaus in high-dimensional optimization; kept as a linking-only alternative.

04 120 分鐘

考核:預測、分類並診斷優化行為

獨立掌握檢查(無 AI 輔助)。

前置要求

完成活動 30-01 至 30-03;獨立閉卷。

學習目標

在無輔助下把優化機制遷移到新的二次函數,對一個學習率分類,並診斷給定的失敗。

操作指引

在 g(x) = 2x² 上梯度為 4x,故 x ← x(1 − 4η)。先預測再分類:x₀ = 2、η = 0.3 時因子為 −0.2——收斂、振盪還是發散?計算 x₁、x₂、x₃。給出 g 的穩定上界。最後診斷損失軌跡 2.0 → 2.6 → 3.5 → 4.9 並寫出糾正條目。

自主實作與記錄

g(x) = 2x²、x₀ = 2、η = 0.3:(a) x_k 的閉式;(b) x₁、x₂、x₃ 及所屬形態;(c) η 的穩定上界;(d) 診斷損失軌跡 2.0 → 2.6 → 3.5 → 4.9 並寫出一行糾正措施。

獨立掌握標準

閉式、三個迭代值、形態與上界全部無輔助正確,診斷指出原因與糾正措施——以誠實的失敗分析收束數學模組。

權威來源資源與權利證明

linking CC BY-SA 4.0 (book text) / modified MIT (sample code) share-alike

Dive into Deep Learning (d2l.ai)

作者 / 機構: Aston Zhang, Zachary C. Lipton, Mu Li, Alexander J. Smola | 原始出處連結 ↗

對應章節 / 時間戳: Chapter Optimization Algorithms: Gradient Descent; Optimization and Deep Learning

驗證版本與日期: Current online edition (Verified: 2026-10-30)

入選理由:

Primary open reference tying evaluation discipline (model selection, underfitting, overfitting) and optimization algorithms (gradient descent, minibatch) to the rest of the curriculum.

來源前置條件:

Linear algebra, calculus, and probability at the Days 19-28 level.

安全回退方案(離線彈性):

All required formulas and worked numbers are reproduced as original explanations; the book is further reading.

對比候選資源與選型分析 (2)
Deep Learning (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Detailed treatment of optimization difficulties (chapter 8) including saddle points and plateaus; all-rights-reserved text kept as a linking-only alternative.

fast.ai: Practical Deep Learning for Coders ↗ compared_alternative [Course site copyright / Apache-2.0 (fastai code)]

Strong practitioner framing, but organized around the fastai library and video lessons rather than self-contained mathematics.

linking 3Blue1Brown copyright (all rights reserved); site FAQ permits only short clips under stated conditions No video, audio, transcript or frame redistribution permitted

Gradient Descent, How Neural Networks Learn

作者 / 機構: Grant Sanderson (3Blue1Brown) | 原始出處連結 ↗

對應章節 / 時間戳: Neural networks chapter 2: the gradient and the descent update

驗證版本與日期: Neural networks series chapter 2, 2017 (Verified: 2026-10-30)

入選理由:

Visual intuition connecting the gradient vector to steepest descent; complements d2l.ai's worked equations for the optimization day.

來源前置條件:

High-school functions and slope intuition.

安全回退方案(離線彈性):

The lesson contains complete derivations and numerical traces; the video is optional visual intuition.

對比候選資源與選型分析 (2)
Convex Optimization (Boyd and Vandenberghe) ↗ compared_alternative [Cambridge University Press; free PDF for individual use]

A detailed optimization text, kept as an advanced alternative; its scope exceeds a single study day.

Deep Learning chapter 8 (Goodfellow, Bengio, Courville) ↗ compared_alternative [MIT Press; free HTML for reading, all rights reserved]

Rigorous discussion of saddle points and plateaus in high-dimensional optimization; kept as a linking-only alternative.