26 / 90

第 26 天:随机变量、期望、采样与最大似然

定义离散随机变量与分布,手算期望与方差,用固定种子的抽样构建经验分布,并推导包含零计数失效在内的最大似然估计。

数学与算法基础 480 分钟(8 小时专注学习)
01 120 分钟

随机变量与概率分布

仅在记录预测与观察证据后才允许辅助。

前置要求

完成第 25 天(概率基础);如遇阻塞,使用所列恢复链接(第 21 天)。

学习目标

把离散随机变量定义为从结果到数的函数,验证概率分布表,并把它与词元上的类别分布联系起来。

操作指引

随机变量 $X$ 把样本空间的每个结果映射为一个数;其分布列出满足 $\sum_x P(X=x)=1$ 的 $P(X=x)$。公平骰的 $X$ 是 $\{1,\dots,6\}$ 上的均匀分布。必做:计算骰子的 $E[X]$,再验证取值 $\{0,1,2,3\}$ 上的词元型分布 $p=[0.5,0.25,0.125,0.125]$。

自主演练与记录

(a) 求公平骰的 $E[X]$,并解释非整数期望为何不与结果矛盾。(b) 对 $\{0,1,2,3\}$ 上的 $p=[0.5,0.25,0.125,0.125]$,验证 $\sum p = 1$ 并求 $P(X\ge 2)$。(c) 把 $p$ 解释为四个词元类型上的类别分布:哪个是最可能的词元?

独立掌握标准

验证归一化 $\sum p = 1$、算出 $P(X\ge2)=0.25$,并能把期望解释为区别于任何单一结果的平均。

权威源资源与权利证明

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

Introductory Statistics 2e

作者 / 机构: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出处链接 ↗

对应章节 / 时间戳: Chapter 4: Discrete Random Variables (probability distribution functions)

验证版本与日期: 2e web edition (Verified: 2026-10-30)

入选理由:

Open textbook treatment of discrete random variables and distribution tables.

来源前置条件:

High-school algebra; Day 25 probability foundations

安全回退方案(离线弹性):

All required definitions, tables, and worked answers are reproduced locally in this lesson.

对比候选资源与选型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 机构: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出处链接 ↗

对应章节 / 时间戳: Section 2.4-2.5: Random variables, distributions, expectation

验证版本与日期: 2020 public course notes (Verified: 2026-10-30)

入选理由:

ML-oriented definition of random variables bridging to categorical token distributions.

来源前置条件:

Multivariate calculus notation exposure

安全回退方案(离线弹性):

Self-contained definitions and derivations in activity instructions and offline guide.

对比候选资源与选型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.

02 120 分钟

期望、方差与分布表计算练习

独立掌握检查(无 AI 辅助)。

前置要求

完成上一项活动;如遇阻塞,使用所列恢复链接。

学习目标

在无辅助下对离散分布计算 $E[X]$、$E[X^2]$、$\mathrm{Var}(X)=E[X^2]-E[X]^2$ 与标准差。

操作指引

先逐行算分布表再合并。必做:下面的四型分布、一颗公平骰和一个 Bernoulli(0.25) 变量。计算前先记录预测值,能取精确分数处保留分数。

自主演练与记录

对 $\{0,1,2,3\}$ 上的 $p=[0.5,0.25,0.125,0.125]$,求 $E[X]$、$E[X^2]$、$\mathrm{Var}(X)$、$\sigma_X$。再求公平骰($E[X^2]=91/6$)与 $\mathrm{Bernoulli}(0.25)$ 的 $\mathrm{Var}$。

独立掌握标准

所有数值与独立算出的参考分数/小数一致;方差以平方单位报告,$\sigma$ 以原单位报告。

权威源资源与权利证明

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

Introductory Statistics 2e

作者 / 机构: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出处链接 ↗

对应章节 / 时间戳: Chapter 4: Discrete Random Variables (mean, expected value, standard deviation)

验证版本与日期: 2e web edition (Verified: 2026-10-30)

入选理由:

Step-by-step open examples of expected value and variance from distribution tables.

来源前置条件:

High-school algebra; Day 25 probability foundations

安全回退方案(离线弹性):

All required definitions, tables, and worked answers are reproduced locally in this lesson.

对比候选资源与选型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 机构: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出处链接 ↗

对应章节 / 时间戳: Section 2.5-2.6: Expectation, variance, common discrete distributions

验证版本与日期: 2020 public course notes (Verified: 2026-10-30)

入选理由:

Concise reference for Var(X)=E[X^2]-E[X]^2 and Bernoulli variance used in ML derivations.

来源前置条件:

Multivariate calculus notation exposure

安全回退方案(离线弹性):

Self-contained definitions and derivations in activity instructions and offline guide.

对比候选资源与选型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.

03 120 分钟

采样、经验分布与最大似然

仅在记录预测与观察证据后才允许辅助。

前置要求

完成上一项活动;如遇阻塞,使用所列恢复链接。

学习目标

用固定种子的抽样构建经验分布,用标准误 $\sigma/\sqrt n$ 与真分布比较,并推导伯努利与一元文法模型的最大似然估计,包括零计数失效。

操作指引

运行:python3 -c "import random, collections; random.seed(26); s=[random.randint(1,6) for _ in range(100)]; print(round(sum(s)/100,4), collections.Counter(s))". 骰子样本均值的标准误为 $\sigma/\sqrt n \approx 1.7078/10 \approx 0.1708$。60 次抛掷 36 次正面的硬币似然为 $p^{36}(1-p)^{24}$,在 $\hat p = 36/60$ 处最大。一元文法的 MLE 为 $\hat p(w) = \mathrm{count}(w)/N$。

自主演练与记录

(a) 报告定种子样本均值,并给出一个偏离 $1/6$ 的经验频率。(b) 令对数似然导数为零,推导 60 次抛掷中 36 次正面的 $\hat p$。(c) 在语料 "the cat sat on the mat the cat ran"($N=9$,六种已见类型)中给出 'the' 与 'dog' 的一元文法 MLE。若模型给留出词元赋 0,会坏在哪里?

独立掌握标准

如实报告定种子数值(均值 $3.47$、3 点偏少),由对数似然推出 $\hat p = 0.6$,并能解释零计数失效与加 1 平滑的对策。

权威源资源与权利证明

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

Introductory Statistics 2e

作者 / 机构: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出处链接 ↗

对应章节 / 时间戳: Chapter 1: Sampling and Data (sampling, variation); Chapter 4 (estimating parameters)

验证版本与日期: 2e web edition (Verified: 2026-10-30)

入选理由:

Open coverage of sampling variability and estimation that motivates the MLE and standard-error work here.

来源前置条件:

High-school algebra; Day 25 probability foundations

安全回退方案(离线弹性):

All required definitions, simulations, and worked answers are reproduced locally in this lesson.

对比候选资源与选型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking PSF License Version 2

Python 3 random: Generate pseudo-random numbers

作者 / 机构: Python Software Foundation | 原始出处链接 ↗

对应章节 / 时间戳: random.seed, random.randint, random.sample, random.choices

验证版本与日期: Python 3.12 documentation (Verified: 2026-10-30)

入选理由:

Normative reference for the seeded draws used to build empirical distributions.

来源前置条件:

Basic Python syntax

安全回退方案(离线弹性):

Use the installed interpreter's help(random) and the included deterministic commands.

对比候选资源与选型分析 (2)
NumPy random Generator documentation ↗ compared_deferred [BSD 3-Clause]

Faster vectorized sampling but adds a third-party dependency before the tensor track; deferred to the models-and-training days.

Python secrets module documentation ↗ compared_rejected_for_days_25_27 [PSF License Version 2]

Cryptographically secure randomness is unnecessary for reproducible statistical pedagogy and obscures the seed-based determinism the exercises require.

04 120 分钟

独立掌握检查:估计与采样

独立掌握检查(无 AI 辅助)。

前置要求

完成上一项活动;如遇阻塞,使用所列恢复链接。

学习目标

独立求解未见过的估计题,并说明每个结果背后的统计假设。

操作指引

本检查期间不使用 AI 与参考资料,只做四则运算。先记录预测,解出全部四题,再复盘并对错题走恢复链接。 保留首次无协助尝试且不做改动;此后的错题复盘和任何协助式补救是单独阶段,遗漏的概念须通过一次答案事先不展示的新同等无协助检查,才算已补救。 第二次检查(仅在补救之后;无协助、无提示):(a) 对 $\{0,1,2,3\}$ 上的 $p=[0.2,0.3,0.4,0.1]$ 求 $E[X]$ 与 $\mathrm{Var}(X)$。(b) 求 $P(\text{掷 3 次至少一个 6})$。(c) 15 次抛掷 9 次正面:给出 $\hat p$ 及其近似标准误差。(d) 用一句话解释有限样本比例为何不必等于真 $p$。本卡片不给出第二次检查的答案:按与掌握标准相同的标准评分(数值正确,写明 i.i.d. 与有限样本假设),并只在做完后用另一种方法(直接计算 $\mathrm{Var}=E[(X-E[X])^2]$,或枚举全部 $6^3$ 种结果)核对。(a) 出错用 day-26-act-01(分布表的有效性)和 day-26-act-02(期望、方差)补救,(b) 用 day-25-act-02(独立性)和 day-25-act-01(计数),(c)-(d) 用 day-26-act-03(抽样、标准误差、最大似然)。

自主演练与记录

(a) 对 $\{0,1,2,3\}$ 上的 $p=[0.1,0.2,0.4,0.3]$ 求 $E[X]$ 与 $\mathrm{Var}(X)$。(b) 求 $P(\text{掷 4 次至少一个 6})$。(c) 20 次抛掷 14 次正面:给出 $\hat p$,并举一个真 $p$ 仍可能不同的理由。(d) 用一句话解释有限样本均值为何不必等于 $E[X]$。

独立掌握标准

独立数值与 $1.9$、$0.89$、$0.5177$、$0.7$ 一致;陈述 i.i.d. 与有限样本假设;错题接入恢复链接,且每个遗漏概念须经一次新的同等无协助检查才算补救。

权威源资源与权利证明

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

Introductory Statistics 2e

作者 / 机构: OpenStax, Rice University (Barbara Illowsky, Susan Dean) | 原始出处链接 ↗

对应章节 / 时间戳: Chapters 1 and 4 review: sampling, distributions, expectation, variance

验证版本与日期: 2e web edition (Verified: 2026-10-30)

入选理由:

Open review coverage aligned with this day's assessment scope.

来源前置条件:

High-school algebra; Day 25 probability foundations

安全回退方案(离线弹性):

The assessment is self-contained with original items and worked reference answers.

对比候选资源与选型分析 (3)
MIT OCW 6.041 Probabilistic Systems Analysis ↗ compared_deferred [CC BY-NC-SA 4.0]

Rigorous but paced for a full graduate semester; exceeds the depth needed for Days 25-27 training-objective foundations.

Khan Academy Statistics and Probability ↗ compared_alternative [CC BY-NC-SA 3.0]

Accessible video-first coverage; noncommercial/share-alike terms and video pacing make it a supplementary rather than primary link.

Harvard Stat 110 Introduction to Probability (Blitzstein & Hwang) ↗ compared_alternative [CRC Press copyright (book); free lecture videos]

Strong intuition-building course; the printed textbook is paywalled, so it complements rather than replaces the openly licensed OpenStax text.

linking Stanford copyright; public course notes No text extraction or redistribution permitted

CS229 Review of Probability Theory

作者 / 机构: Stanford CS229 course staff (Arian Maleki, Tom Do) | 原始出处链接 ↗

对应章节 / 时间戳: Sections 2.4-3: random variables, expectation, variance, maximum likelihood

验证版本与日期: 2020 public course notes (Verified: 2026-10-30)

入选理由:

Reference for estimation and MLE concepts this assessment checks without assistance.

来源前置条件:

Multivariate calculus notation exposure

安全回退方案(离线弹性):

The assessment is self-contained with original items and worked reference answers.

对比候选资源与选型分析 (2)
OpenStax Introductory Statistics 2e ↗ compared_alternative [CC BY-NC-SA 4.0]

Co-selected: provides the gentler beginner narrative; CS229 provides the ML-oriented notation bridge.

MIT OCW 18.05 Introduction to Probability and Statistics ↗ compared_alternative [CC BY-NC-SA 4.0]

Strong full-course treatment with noncommercial/share-alike terms; heavier than the compact CS229 reference for this three-day block.