← COMP5511 全部讲次
Q05

Midterm 自拟练习|E 聚类与神经网络

自拟练习 E 聚类与神经网络:英文题干,逐题折叠中文解析、英文参考答案与回查页码。

手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。

使用边界:2026-11-04 课堂期中复习,非官方材料;考试安排按讲师通知整理,正式要求以讲师通知和课堂公告为准。主体覆盖 L01–L07、Tutorial 1–5 与 Assignment 1;通知列出的课件只到 Lecture 7,L08 放在第 08 节作范围存疑附节。练习题均为自拟,不是往年真题或预测卷。

复习资料:范围与搜索 · 概率与逻辑 · 机器学习与聚类 · 神经网络与 L08 附节

先做题再看解析:A 搜索 · B 概率 · C 逻辑 · D 机器学习 · E 聚类与神经网络 · F 论文与 PyTorch

怎么做:先只看题面,用英文作答,写出公式和每一步,再展开解析核对。解析里的数值都用 python 复算过;每题末尾给回查出处,页码为 PDF 页序。

E 聚类与神经网络

E1 · K-means by hand

One-dimensional data: 1, 2, 3, 8, 9, 10. Run K-means with K = 2 and initial centres μ₁ = 1, μ₂ = 2, using squared distance.

(a) In each iteration, show which centre each point is assigned to and the new centres, until convergence. (b) Compute the final SSE.

E1 · 查看答案与解析

推理过程:

轮次 归给 μ₁ 归给 μ₂ 更新后的中心
1 1 2, 3, 8, 9, 10 μ₁ = 1,μ₂ = 32/5 = 6.4
2 1, 2, 3 8, 9, 10 μ₁ = 2,μ₂ = 9
3 1, 2, 3 8, 9, 10 没有点改变归属,停止

第 1 轮后 SSE 为 53.2,第 2 轮后降到 4。

答案:最终中心 2 和 9;SSE = (1 + 0 + 1) + (1 + 0 + 1) = 4。

English: K-means stops when no point changes its cluster; each step does not increase the SSE, so the algorithm must terminate.

易错点:中心是所属点的算术平均;停止条件是归属不再改变。

回查:L05 p.16–23。

E2 · Choosing K and the limits of K-means

(a) Why can we not choose K by picking the value with the smallest SSE? (b) Describe the elbow method. (c) Give one kind of data on which K-means fails even with the right K, and one way that may help.

E2 · 查看答案与解析

答案:

(a) SSE 随 K 单调不增,K 等于样本数时 SSE 为 0,按最小 SSE 选总会选最大的 K。

(b) 画 SSE 随 K 的曲线,取下降幅度突然变小的那个 K(肘点)。

(c) 两个同心圆环或两个月牙。K-means 的簇边界是直线拼成的,簇只能是凸的。可以换特征或换距离函数,例如把圆环从 (X, Y) 换到 (R, θ)。

English: Because SSE never increases with K, we use the elbow point; K-means produces convex clusters with linear boundaries, so it fails on concentric rings unless the features are changed.

易错点:肘部法在曲线没有明显拐点时要靠主观判断。

回查:L05 p.17、p.29–33。

E3 · Forward propagation

A network has inputs x₁ = 1, x₂ = 2, two sigmoid hidden units and one sigmoid output.

Hidden unit 1: a₁ = 0.5x₁ − 0.3x₂ + 0.1. Hidden unit 2: a₂ = 0.2x₁ + 0.4x₂ − 0.5. Output: b = 1.0z₁ − 0.8z₂ + 0.2, y = σ(b).

Compute a₁, a₂, z₁, z₂, b and y.

E3 · 查看答案与解析

推理过程:先加权求和,再过 sigmoid,逐层向前。

  • a₁ = 0.5 − 0.6 + 0.1 = 0,z₁ = σ(0) = 0.5
  • a₂ = 0.2 + 0.8 − 0.5 = 0.5,z₂ = σ(0.5) ≈ 0.6225
  • b = 0.5 − 0.8 × 0.6225 + 0.2 ≈ 0.2020
  • y = σ(0.2020) ≈ 0.5503

答案:y ≈ 0.5503。

English: In forward propagation each layer computes a weighted sum of its inputs plus a bias and then applies the activation function.

易错点:输出层的输入是 z₁、z₂,不是 a₁、a₂。

回查:L06 p.22–28。

E4 · Softmax and cross-entropy

A three-class network outputs scores b = (2, 1, 0). The true class is class 2 (the one with score 1).

(a) Compute the softmax probabilities. (b) Compute the cross-entropy loss with the natural logarithm.

E4 · 查看答案与解析

推理过程:

  • exp(2) ≈ 7.3891,exp(1) ≈ 2.7183,exp(0) = 1,和 ≈ 11.1073
  • 概率 ≈ 0.6652、0.2447、0.0900,和为 1
  • 真实标签是独热向量,交叉熵只剩真实类那一项:J = −log 0.2447 ≈ 1.4076

答案:(a) 约 0.6652、0.2447、0.0900;(b) 约 1.4076。

English: Softmax turns scores into positive probabilities that sum to one, and cross-entropy is the negative log-probability assigned to the true class.

易错点:交叉熵要带负号;课件几处原式漏了负号。

回查:L06 p.30、p.43。

E5 · One SGD step for logistic regression

Logistic regression y = σ(θᵀx) with x = (x₀, x₁, x₂) = (1, 2, 1), where x₀ = 1 is the bias input, θ = (0.1, 0.3, −0.2) and true label y* = 1. Use cross-entropy loss and learning rate η = 0.5.

(a) Compute θᵀx and y. (b) Compute the gradient dJ/dθⱼ for j = 0, 1, 2. (c) Give θ after one SGD step.

E5 · 查看答案与解析

推理过程:

(a) θᵀx = 0.1 + 0.6 − 0.2 = 0.5,y = σ(0.5) ≈ 0.6225。

(b) y − y* ≈ −0.3775,梯度 (y − y*)xⱼ ≈ −0.3775、−0.7551、−0.3775。

(c) θⱼ 减去 η 乘梯度:θ₀ ≈ 0.2888,θ₁ ≈ 0.6775,θ₂ ≈ −0.0112。

答案:新 θ ≈ (0.2888, 0.6775, −0.0112),预测往 y* = 1 的方向移动。

English: With sigmoid and cross-entropy the gradient is (y − y*)xⱼ, and SGD moves each parameter against its gradient.

易错点:梯度为负时减去它等于加上一个正数。

回查:L06 p.15、p.47。

E6 · CNN shapes and parameters

The input is 64×64×3.

(a) Layer 1: 16 filters of size 3×3, stride 1, padding 1. Give the output size and the number of parameters. (b) Layer 2: 2×2 max pooling with stride 2. Give the output size and the number of parameters. (c) Layer 3: filters of size 5×5 with stride 2 and no padding. Is this setting valid? Is there any padding P that makes it valid? (d) How many weights would a fully connected layer need to map the flattened input to 16 outputs?

E6 · 查看答案与解析

推理过程:

(a) (64 − 3 + 2)/1 + 1 = 64,输出 64×64×16;参数 (3·3·3)·16 + 16 = 448。

(b) (64 − 2)/2 + 1 = 32,输出 32×32×16;池化没有参数。

(c) (32 − 5)/2 + 1 = 14.5,不是整数,不合法。分子 27 + 2P 永远是奇数,任何 P 都除不尽;改成步长 1 才行,此时 (32 − 5)/1 + 1 = 28。

(d) 拉平后 12288 维,乘 16 个输出共 196608 个权重。

答案:64×64×16 与 448;32×32×16 与 0;不合法;196608。

English: The output width is (W − F + 2P)/S + 1 and must be an integer; a convolutional layer has (F·F·D₁)·K weights plus K biases, independent of the input width and height.

易错点:滤波器深度要等于输入深度 3;每个滤波器加 1 个偏置。

回查:L07 p.10、p.31–44。

E7 · RNN and LSTM

(a) A scalar LSTM cell has previous cell state c = 2, forget gate f = 0.9, input gate i = 0.5, candidate g = −0.4 and output gate o = 0.8. Compute the new c and h. (b) Why does a vanilla RNN suffer from vanishing or exploding gradients, and why does the LSTM cell state help? (c) Does an RNN use different weights at different time steps?

E7 · 查看答案与解析

推理过程:

(a) c = f·c + i·g = 0.9 × 2 + 0.5 × (−0.4) = 1.8 − 0.2 = 1.6;h = o·tanh(c) = 0.8 × tanh(1.6) ≈ 0.8 × 0.9217 ≈ 0.7373。

(b) 反向每退一个时间步乘一次 W_hhᵀ,最大奇异值大于 1 会爆炸、小于 1 会消失。LSTM 的 c 在反向只乘遗忘门 f,不乘 W,梯度能传得更远。

(c) 不会。每个时间步用同一个函数、同一组参数;总梯度是各时间步梯度之和。

答案:c = 1.6,h ≈ 0.7373;其余见上。

English: The same weights are shared across all time steps; repeated multiplication by W_hh causes vanishing or exploding gradients, while the LSTM cell state is updated additively and is only scaled by the forget gate.

易错点:梯度裁剪只治爆炸,不治消失。

回查:L07 p.58–67、p.77–86。

下一页 →
Q06 Midterm 自拟练习|F 论文与 PyTorch

个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。