不确定性估计Uncertainty Estimation
一个只给出答案的模型,机器人没法放心用:它还需要知道这个答案有多可信。不确定性有两种:偶然不确定性来自世界本身的随机(传感器噪声、打滑),再多数据也消不掉;认知不确定性来自模型没见过足够的数据,采到数据就会缩小。本节在浏览器里现场训练会预测自身噪声的网络、深度集成和 MC dropout,用可靠性图和温度缩放检查并修正“过度自信”,用共形预测给出有覆盖率保证的区间,并看这些估计怎样用于让机器人求助、发现陌生输入和决定下一步采什么数据。 A model that only gives answers is not one a robot can rely on: it also needs to know how far to trust each answer. Uncertainty comes in two kinds. Aleatoric uncertainty is randomness in the world itself (sensor noise, slip) and no amount of data removes it; epistemic uncertainty comes from the model not having seen enough data, and shrinks when you collect some. In this lesson you train, live in the browser, networks that predict their own noise, deep ensembles and MC dropout; check and repair overconfidence with reliability diagrams and temperature scaling; get intervals with a coverage guarantee from conformal prediction; and see how these estimates let a robot ask for help, notice unfamiliar inputs and decide what data to collect next.
1为什么机器人需要它Why robots need this
前面几章训练出来的网络都只回答一个数:这次抓取能成功的概率是 0.93,这个像素的深度是 1.52 m,这个动作之后关节会转到这里。机器人拿到这个数之后还得做决定:要不要执行这次抓取?这个深度值在卡尔曼滤波(4.8 节)里该给多大权重?是自己继续,还是停下来请人帮忙?这些决定需要的不只是“最可能的答案”,还有这个答案有多可能错。卡尔曼滤波里每个测量都必须带协方差,否则增益没法算;学出来的模型如果没有不确定性,就没法放进同一个框架里。
“不知道”有两种,处理方法完全不同。第一种来自世界本身:同一个距离,深度相机每次读数都在抖;同样的抓取姿态,物体有时滑、有时不滑。这叫偶然不确定性(aleatoric,源自拉丁语“骰子”),再多数据也消不掉,模型能做的只是把它的大小如实报告出来。第二种来自模型自己:数据没覆盖到的距离、没见过的物体,模型只能瞎猜。这叫认知不确定性(epistemic,源自希腊语“知识”),去那里采数据就能把它降下来。
机器人在乎这个区分,因为两种不确定性要求不同的动作。认知不确定性大:去采数据(主动学习),换个保守动作,或者请人帮忙。偶然不确定性大:采再多同样的数据也没用,该做的是换传感器、换策略,或在规划里留出余量。16.2 节已经看到,网络在训练范围外会自信地给出错误答案,集成的分歧只涨了一点。本节系统地讲怎样估计、检验和使用这两种不确定性。
The networks of the previous chapters each answer with a single number: this grasp succeeds with probability 0.93, this pixel is 1.52 m deep, after this action the joint will be here. The robot then still has to decide: execute the grasp or not? How much weight does that depth get in a Kalman filter (Lesson 4.8)? Carry on alone, or stop and ask a person? These decisions need more than "the most likely answer"; they need how likely that answer is to be wrong. In a Kalman filter every measurement must come with a covariance or the gain cannot be computed, and a learned model without uncertainty simply does not fit into that framework.
"Not knowing" comes in two kinds that are handled in completely different ways. The first comes from the world itself: at the same distance a depth camera's reading jitters from frame to frame; with the same grasp pose an object sometimes slips and sometimes does not. This is aleatoric uncertainty (from the Latin for "dice"). No amount of data removes it; the best a model can do is report its size honestly. The second comes from the model: at distances the data never covered, for objects it has never seen, the model can only guess. This is epistemic uncertainty (from the Greek for "knowledge"), and collecting data there brings it down.
Robots care about the distinction because the two call for different actions. Large epistemic uncertainty: collect data (active learning), fall back to a cautious action, or ask for help. Large aleatoric uncertainty: more of the same data will not help; change the sensor or the strategy, or leave a margin in the plan. Lesson 16.2 showed a network confidently wrong outside its training range while the disagreement of its ensemble grew only a little. This lesson is about how to estimate, check and use both kinds of uncertainty.
2直觉:总不确定性 = 偶然 + 认知Intuition: total uncertainty = aleatoric + epistemic
本节反复用到一个例子:一台廉价深度相机的读数有系统误差,误差大小随距离变化(距离 z 处的误差是一条带波动的曲线,单位 mm),而且读数噪声随距离增大。我们把标定板放在不同距离上,测出“读数减真实距离”,想学出这条误差曲线,用来修正以后的读数。
先用最简单、可以精确求解的模型:贝叶斯线性回归。把误差写成 25 个高斯小鼓包的加权和 \(y=\boldsymbol\phi(z)^\top\mathbf w+\varepsilon\),权重有高斯先验,噪声 \(\varepsilon\sim\mathcal N(0,\sigma^2)\)。这样权重的后验也是高斯的(4.4 节的条件化,4.6 节的 MAP),新距离处的预测方差可以写成两项之和:
One example runs through this lesson. A cheap depth camera has a systematic error that depends on distance (at distance z the error follows a wavy curve, in mm), and its reading noise grows with distance. We place a calibration board at various distances, measure "reading minus true distance", and want to learn the error curve so as to correct future readings.
Start with the simplest model that can be solved exactly: Bayesian linear regression. Write the error as a weighted sum of 25 Gaussian bumps, \(y=\boldsymbol\phi(z)^\top\mathbf w+\varepsilon\), with a Gaussian prior on the weights and noise \(\varepsilon\sim\mathcal N(0,\sigma^2)\). Then the posterior over the weights is Gaussian too (conditioning from Lesson 4.4, MAP from Lesson 4.6), and the predictive variance at a new distance splits into two terms:
第一项是偶然部分,即传感器噪声,与数据多少无关;第二项是认知部分:权重后验协方差 \(\Sigma_{\mathbf w}\) 投影到这个距离上的结果,只在数据覆盖的地方变小。拖动下图的测量次数和噪声,或者把一段距离留空不测,看两项各自怎么变。把鼠标放到公式的两项上,图里对应的带子和曲线会加粗。
The first term is the aleatoric part, the sensor noise, and does not depend on how much data you have; the second is the epistemic part, the posterior covariance of the weights \(\Sigma_{\mathbf w}\) projected onto this distance, and it shrinks only where data exist. Move the number of measurements and the noise in the figure below, or leave a range of distances unmeasured, and watch each term. Hover either term of the formula to thicken the matching band and curve.
- 探针放在数据范围内部(离边缘远一点,例如 0.8 m),把测量次数拉到 200 以上:认知 σ_epi 降到偶然 σ 的四分之一以下(σ = 2 mm 时,N = 10、50、200、400 分别约为 2.04、1.01、0.46、0.34 mm:大约按 \(1/\sqrt N\) 下降),而蓝色总带几乎只剩偶然的宽度。Put the probe inside the data range (away from its edges, say at 0.8 m) and push the number of measurements past 200: the epistemic σ_epi falls below a quarter of the aleatoric σ (at σ = 2 mm it is about 2.04, 1.01, 0.46 and 0.34 mm for N = 10, 50, 200 and 400, roughly like \(1/\sqrt N\)), and the blue total band is left with almost only the aleatoric width.
- 选“1.2–1.8 m 留空”,N ≥ 200,噪声 σ ≤ 4 mm,把探针放到空档中间(1.45–1.55 m):那里的认知 σ_epi 大于偶然 σ(σ = 2 mm、N = 200 时约 3.5 mm,不留空时同一处只有 0.37 mm)。别处再多的数据也帮不了这里。Select "gap at 1.2–1.8 m", N ≥ 200, noise σ ≤ 4 mm, and put the probe in the middle of the gap (1.45–1.55 m): the epistemic σ_epi there exceeds the aleatoric σ (about 3.5 mm at σ = 2 mm and N = 200, versus 0.37 mm at the same spot without the gap). No amount of data elsewhere helps here.
再看两端:数据只到 2.4 m,在 2.8 m 处(N = 200)认知标准差回升到 8.75 mm,往 3 m 走继续增大,模型在“告诉你它不知道”。这是贝叶斯模型最有用的性质。下一节换成神经网络:它们没有这样干净的后验,我们得用别的办法近似出同样的两项。
Look at the ends too: the data stop at 2.4 m, and at 2.8 m (N = 200) the epistemic std is back up to 8.75 mm and keeps growing towards 3 m; the model is telling you it does not know. This is the most useful property of a Bayesian model. The next section moves to neural networks, which have no such clean posterior, so we need other ways to approximate the same two terms.
问一个不确定性估计时,先问它是哪一种。偶然不确定性是数据本身的性质,是要“学出来”的输出(像均值一样);认知不确定性是“对模型自己的不确定”,它必须随数据增加而缩小,在没有数据的地方变大。一个在任何地方都给出同样宽度的区间,或者在没见过的输入上照样很窄的区间,都没有把认知不确定性估计出来。
When someone hands you an uncertainty estimate, first ask which kind it is. Aleatoric uncertainty is a property of the data, an output to be learned (like the mean); epistemic uncertainty is uncertainty about the model itself, and it must shrink as data accumulate and grow where there are none. An interval that is equally wide everywhere, or stays narrow on inputs never seen, has not estimated epistemic uncertainty.
3动手:让网络学会自己的噪声,再让一群网络互相争论Play: let a network learn its own noise, then let several argue
偶然部分:异方差回归。让网络输出两个数:均值 \(\mu_\theta(z)\) 和标准差 \(\sigma_\theta(z)\)(第二个输出经过 softplus 保证为正),训练时最小化高斯负对数似然(NLL),而不是 MSE:
The aleatoric part: heteroscedastic regression. Let the network output two numbers, a mean \(\mu_\theta(z)\) and a standard deviation \(\sigma_\theta(z)\) (the second passes through a softplus so it is positive), and train it by minimizing the Gaussian negative log-likelihood (NLL) instead of the MSE:
第二项是被 \(1/\sigma^2\) 加权的平方误差,第一项惩罚“把 σ 报得很大来逃避”。两者平衡时 \(\sigma_\theta^2(z)\) 等于该处残差平方的期望:网络自己学出“这里噪声有多大”(异方差,heteroscedastic,指噪声随输入变化;同方差则处处一样)。这就是 16.2 节“损失 = 负对数似然”的直接推广:MSE 对应固定 σ 的高斯,这里把 σ 也交给网络。
认知部分:深度集成与 MC dropout。训练 \(K\) 个结构相同、初值和小批量顺序不同的网络(深度集成,Lakshminarayanan 等 2017)。在数据多的地方,所有成员都被数据“按住”,预测几乎相同;在数据外,每个成员按自己的初值随意外推,彼此分歧就是认知不确定性的估计。MC dropout(Gal 与 Ghahramani 2016)只训练一个带 dropout 的网络,测试时不关掉 dropout,用 20 个随机掩码各预测一次,把它们当成 20 个成员。两种情况下都按全方差公式合并,第一项是偶然部分,第二项是认知部分:
The second term is the squared error weighted by \(1/\sigma^2\); the first penalizes "escaping by reporting a huge σ". They balance when \(\sigma_\theta^2(z)\) equals the expected squared residual there, so the network learns for itself how noisy each place is (heteroscedastic: the noise varies with the input; homoscedastic: the same everywhere). This is the direct extension of "losses are negative log-likelihoods" from Lesson 16.2: the MSE is a Gaussian with fixed σ, and here σ is handed to the network too.
The epistemic part: deep ensembles and MC dropout. Train \(K\) networks with the same architecture but different initializations and minibatch orders (a deep ensemble, Lakshminarayanan et al. 2017). Where data are plentiful every member is pinned down by them and they predict nearly the same thing; outside the data each member extrapolates according to its own initialization, and their disagreement is the estimate of epistemic uncertainty. MC dropout (Gal and Ghahramani 2016) trains a single network with dropout and does not switch dropout off at test time: 20 random masks give 20 predictions, treated as 20 members. Either way, combine them with the law of total variance; the first term is the aleatoric part, the second the epistemic part:
- 保持默认(深度集成、K = 5、高斯 NLL),按“训练”跑完 1500 步:学到的偶然 σ 随距离上升,2.2 m 处是 0.5 m 处的 3 倍以上(4.78 mm 对 1.14 mm;真值 6.31 对 0.80)。90% 区间在近处和远处的覆盖率分别约 90% 和 78%。Keep the defaults (deep ensemble, K = 5, Gaussian NLL) and press "Train" for the full 1500 steps: the learned aleatoric σ rises with distance and is more than 3 times larger at 2.2 m than at 0.5 m (4.78 mm versus 1.14 mm; truth 6.31 versus 0.80). The 90% interval covers about 90% near and 78% far.
- 把损失换成“MSE + 常数 σ”再训练 1500 步:只有一个 σ(3.30 mm,训练残差的均方根),近处的 90% 区间覆盖了 99.8%(太宽),远处只有 62.1%(太窄)。总体平均下来“差不多”,可每个地方都不对。Switch the loss to "MSE + constant σ" and train 1500 steps: there is a single σ (3.30 mm, the RMS training residual); the 90% interval covers 99.8% near (too wide) and only 62.1% far (too narrow). On average it looks "about right", yet it is wrong everywhere.
- 方法选“MC dropout”,分别在 p = 0.05 和 p = 0.3 下训练满 1500 步(不要加点):数据范围内的平均认知 σ_epi 从约 0.99 mm 涨到约 1.74 mm。数据完全一样,变的只是你选的超参数。Select "MC dropout" and train the full 1500 steps once at p = 0.05 and once at p = 0.3 (do not add points): the mean epistemic σ_epi inside the data range grows from about 0.99 mm to about 1.74 mm. The data are identical; only a hyperparameter you chose has changed.
(1) 空档里认知不确定性占上风:1.5 m 处 σ_epi 约 4.70 mm,大于学到的偶然 σ(3.52 mm),而那里的预测误差约 −6 mm,大致落在 ±2σ_tot 之内。点几下空档补测量,紫色带很快收窄。(2) 学到的 σ 也只在有数据的地方可信:σ 头也是一个网络,在空档和外推区它同样在猜,近处它还把均值没拟合好的那部分误差算成了“噪声”(0.5 m 处 1.14 对真值 0.80)。(3) 远处的外推没人报警:2.9 m 处集成均值错了约 −35 mm,总标准差却只有约 3.9 mm,相差 9 倍;把 K 加到 8 也只到约 6.6 mm。5 个 ReLU 网络都沿着最后一段数据的斜率直线外推,“意见一致”不等于“正确”。(4) K = 1 时 σ_epi 处处为 0:单个网络无论多么好地学会了噪声,都不知道自己什么时候在外推。
(1) In the gap the epistemic part dominates: at 1.5 m σ_epi is about 4.70 mm, larger than the learned aleatoric σ (3.52 mm), while the prediction error there is about −6 mm, roughly inside ±2σ_tot. Click a few measurements into the gap and the purple band closes quickly. (2) The learned σ is trustworthy only where there are data: the σ head is a network too, guessing in the gap and beyond the data, and near the camera it books the part of the error the mean failed to fit as "noise" (1.14 at 0.5 m versus 0.80 true). (3) Far extrapolation raises no alarm: at 2.9 m the ensemble mean is off by about −35 mm while the total standard deviation is only about 3.9 mm, nine times too small; raising K to 8 only gets it to about 6.6 mm. All five ReLU networks extrapolate straight along the slope of the last stretch of data; "they agree" does not mean "they are right". (4) With K = 1, σ_epi is 0 everywhere: a single network, however well it has learned the noise, cannot tell when it is extrapolating.
4另外两个视角:校准与共形预测Two more views: calibration and conformal prediction
校准:说 80% 的时候,真的有 80% 吗?Calibration: when it says 80%, is it right 80% of the time?
分类器输出的概率只有在校准的时候才能当概率用:在所有它说“成功概率 0.8”的抓取里,应当恰好约 80% 成功。检验办法是可靠性图:把测试样本按预测概率分成 10 个区间,每个区间里比较平均预测概率和实际成功率;点都在对角线上就是校准的。偏离的大小用期望校准误差概括:
A classifier's output probabilities can be used as probabilities only if they are calibrated: of all the grasps it calls "success probability 0.8", about 80% should actually succeed. The check is a reliability diagram: sort the test samples into 10 bins by predicted probability and compare, in each bin, the mean predicted probability with the observed success rate; points on the diagonal mean calibrated. The size of the deviation is summarized by the expected calibration error:
\(\overline p_b\) 和 \(\overline y_b\) 是第 \(b\) 个区间里的平均预测概率和实际成功率,\(n_b\) 是区间里的样本数。右边是最简单的修正,温度缩放(Guo 等 2017):网络照旧,只把 logit \(z\) 除以一个标量 \(T\)。\(T>1\) 把概率往 0.5 拉,\(T<1\) 往两端推。\(T\) 在一个留出的验证集上通过最小化 NLL 来拟合,只有一个参数,几乎不会过拟合,而且不改变任何样本的预测类别。
下图是一个抓取成功率分类器:输入是夹爪相对物体中心的横向偏差和接近角误差(都归一化到 [−1, 1]),真实的成功概率是一个平滑函数(中心附近约 95%,往外下降),标签按这个概率随机抽取,所以就算知道真实概率,平均准确率也只有约 82.5%(在本页的 3000 次测试抓取上恰好是 83.5%):剩下的是偶然不确定性。300 次训练抓取,一个 [2, 16, 16, 1] 的 ReLU 网络,全批量 Adam,学习率 0.01。看训练越久,网络怎样变得越来越过度自信。
\(\overline p_b\) and \(\overline y_b\) are the mean predicted probability and the observed success rate in bin \(b\), and \(n_b\) is the number of samples in it. On the right is the simplest repair, temperature scaling (Guo et al. 2017): keep the network, just divide the logit \(z\) by a scalar \(T\). \(T>1\) pulls probabilities towards 0.5, \(T<1\) pushes them to the ends. \(T\) is fitted by minimizing the NLL on a held-out validation set; with one parameter it hardly overfits, and it changes no sample's predicted class.
The figure below is a grasp-success classifier. Its inputs are the gripper's lateral offset from the object centre and its approach-angle error (both normalized to [−1, 1]). The true success probability is a smooth function (about 95% near the centre, falling off outwards) and labels are drawn at random with that probability, so even knowing the true probability gives only about 82.5% accuracy on average (83.5% on this page's 3000 test grasps): the rest is aleatoric uncertainty. 300 training grasps, a [2, 16, 16, 1] ReLU network, full-batch Adam, learning rate 0.01. Watch the network grow more and more overconfident the longer it trains.
- 按“训练”,保持 T = 1,训练到 900 步以上:ECE 超过 0.09,平均置信度比准确率高出 8 个百分点以上(900 步时 88.8% 对 77.3%)。对比第 100 步时 ECE 只有约 0.02:网络在把训练标签里的随机性“背下来”。Press "Train", keep T = 1 and go past 900 steps: ECE exceeds 0.09 and the mean confidence exceeds the accuracy by more than 8 points (88.8% versus 77.3% at step 900). Compare an ECE of only about 0.02 at step 100: the network is memorizing the randomness in the training labels.
- 训练 900 步以上后按“在验证集上拟合 T”(或自己把 T 往上拉,直到 ECE 降到 0.06 以下):ECE 降到 0.06 以下、不到 T = 1 时的六成,而准确率一点没变(1500 步时 T ≈ 3.09,ECE 从 0.139 降到 0.056)。After 900 or more steps press "Fit T on validation" (or drag T up yourself until ECE is below 0.06): ECE drops below 0.06 and below 60% of its value at T = 1, while the accuracy does not change at all (at step 1500, T ≈ 3.09 and ECE goes from 0.139 to 0.056).
注意准确率在训练中先升后降(第 100 步 82.6%,第 1500 步 76.9%),NLL 从 0.40 涨到 0.95,这就是 16.2 节的过拟合,只是这里它主要表现为过度自信。温度缩放修好了置信度,修不好准确率,也修不好地图上那些弯弯扭扭的错误边界:它是一种“事后校准”,不是更好的模型。而且它只在与验证集同分布的数据上有效,分布一偏移,校准就会重新变坏(Ovadia 等 2019 的大规模实验)。
Note that the accuracy first rises and then falls during training (82.6% at step 100, 76.9% at step 1500) and the NLL climbs from 0.40 to 0.95: this is the overfitting of Lesson 16.2, showing up here mainly as overconfidence. Temperature scaling repairs the confidence but not the accuracy, nor the wiggly wrong boundary on the map: it is post-hoc calibration, not a better model. And it holds only on data distributed like the validation set; under distribution shift calibration degrades again (the large-scale study of Ovadia et al. 2019).
共形预测:不信模型,只信排序Conformal prediction: trust no model, only ranks
前面所有的区间都依赖模型假设(高斯噪声、网络学对了 σ)。共形预测换了个思路:不管模型多差,拿一组模型没见过的校准数据 \((z_i,y_i)_{i=1}^n\),算每个点的“不合格分数”,例如绝对残差 \(s_i=|y_i-\hat y(z_i)|\),取其中第 \(k=\lceil (n+1)(1-\alpha)\rceil\) 小的分数作为阈值 \(\hl{qhat}{\hat q}\),预测区间就是 \(\hat y(z)\pm\hat q\)。只要新数据和校准数据可交换(例如独立同分布),就有
Every interval so far relied on model assumptions (Gaussian noise, a correctly learned σ). Conformal prediction takes another route: however bad the model, take a set of calibration data \((z_i,y_i)_{i=1}^n\) the model has not seen, compute a "nonconformity score" for each, for example the absolute residual \(s_i=|y_i-\hat y(z_i)|\), and take the \(k\)-th smallest score, \(k=\lceil (n+1)(1-\alpha)\rceil\), as the threshold \(\hl{qhat}{\hat q}\); the prediction interval is \(\hat y(z)\pm\hat q\). As long as the new data and the calibration data are exchangeable (for example i.i.d.),
(上界要求分数没有并列。)理由只是排序:新点的分数和 \(n\) 个校准分数可交换,它落在 \(n+1\) 个位置中任意一个的可能性相同,落在前 \(k\) 个以内的概率至少是 \(k/(n+1)\ge1-\alpha\)。没有用到任何关于模型或噪声分布的假设。下图里的“模型”故意选了一个错的:贝叶斯线性回归假设处处同样的噪声,估计出 \(\sigma_{\mathrm m}=3.39\) mm,可真实噪声从 0.6 mm 涨到 7.4 mm。
(The upper bound requires no ties among the scores.) The reason is nothing but ranking: the new point's score and the \(n\) calibration scores are exchangeable, so it is equally likely to land in any of the \(n+1\) positions, and the probability that it is among the first \(k\) is at least \(k/(n+1)\ge1-\alpha\). No assumption about the model or the noise distribution is used. The "model" in the figure below is deliberately wrong: a Bayesian linear regression that assumes the same noise everywhere and estimates \(\sigma_{\mathrm m}=3.39\) mm, whereas the true noise grows from 0.6 mm to 7.4 mm.
- 把 α 设成 0.02(要 98% 的区间),n ≥ 100,绝对分数:模型自己的高斯区间 ±2.33σ_m 只覆盖了 93.5%,而 200 组校准数据上共形区间的平均覆盖率在 98% 附近(约 98.1%)。Set α to 0.02 (asking for a 98% interval), n ≥ 100, absolute score: the model's own Gaussian interval ±2.33σ_m covers only 93.5%, while the conformal interval's mean coverage over 200 calibration sets is close to 98% (about 98.1%).
- α = 0.1,n ≥ 200:绝对分数时近处覆盖 100%、远处只有约 66%(总体仍约 90%);换成“归一化分数”后近处和远处都在 90% ± 6 个百分点以内(n = 200 时 86.7% 和 91.7%),平均宽度还变窄了(11.8 → 10.8 mm)。α = 0.1, n ≥ 200: with the absolute score the near region is covered 100% and the far one only about 66% (overall still about 90%); switch to the "normalized score" and both near and far are within 90% ± 6 points (86.7% and 91.7% at n = 200), with a narrower mean width as well (11.8 → 10.8 mm).
- 绝对分数、α ≥ 0.1,把测试数据“偏移到 2.4–3.0 m”(n ≥ 10):校准数据里没有这么远的距离,覆盖率掉到 60% 以下(n = 200 时 40.8%)。可交换性一被破坏,保证就没了。With the absolute score and α ≥ 0.1, "shift the test data to 2.4–3.0 m" (n ≥ 10): the calibration data contain no such distances and coverage falls below 60% (40.8% at n = 200). Once exchangeability is broken, so is the guarantee.
三点观察。(1) 保证是对“校准数据和测试点一起随机”而言的平均:某一组校准数据可能偏低或偏高(右下的直方图:n = 50 时 5%–95% 分位约为 81.5%–96.5%,n = 500 时收窄到 85.5%–94.5%),平均值才稳稳落在 1 − α 上。(2) 保证是边缘的(对所有距离平均),不是条件的(对每个距离):绝对分数在噪声小的地方太宽、噪声大的地方太窄,总体却刚好 90%。好的分数函数(这里除以 u(z),或者用分位数回归)让区间随难度伸缩,条件覆盖率更接近目标,但仍没有逐点保证。(3) α 很小、n 又少时,\(k=\lceil(n+1)(1-\alpha)\rceil\) 可能超过 \(n\),此时 q̂ = ∞:数据太少,诚实的答案就是“什么都可能”。
Three observations. (1) The guarantee is an average over the random draw of calibration data and test point together: one particular calibration set may come out low or high (the lower-right histogram: the 5–95% range is about 81.5–96.5% at n = 50, narrowing to 85.5–94.5% at n = 500), and only the average sits firmly at 1 − α. (2) The guarantee is marginal (averaged over all distances), not conditional (at each distance): the absolute score is too wide where the noise is small and too narrow where it is large, yet exactly 90% overall. A good score function (here, dividing by u(z); or quantile regression) makes the interval stretch with the difficulty and brings the conditional coverage closer to the target, but still with no pointwise guarantee. (3) When α is small and n is small, \(k=\lceil(n+1)(1-\alpha)\rceil\) can exceed \(n\) and then q̂ = ∞: with that little data the honest answer is "anything is possible".
5再看数学The math
预测分布与全方差分解The predictive distribution and the variance decomposition
贝叶斯的说法是:参数 \(\theta\) 本身不确定,有后验 \(p(\theta\mid\mathcal D)\);对新输入 \(x\) 的预测要对它积分:
In Bayesian terms the parameters \(\theta\) are themselves uncertain, with posterior \(p(\theta\mid\mathcal D)\), and a prediction at a new input \(x\) integrates over it:
右式是全方差公式(4.3 节的期望与方差):总方差 = 噪声方差的平均(偶然)+ 均值的方差(认知),期望和方差都对后验取。集成和 MC dropout 都是用 \(K\) 个样本 \(\theta_k\) 近似这个后验,于是得到 FIG 2 用的公式。数据越多,后验越集中,第二项趋于 0;第一项则趋于真实的噪声方差。
The right-hand side is the law of total variance (expectation and variance from Lesson 4.3): total variance = the mean of the noise variance (aleatoric) + the variance of the mean (epistemic), both taken over the posterior. Ensembles and MC dropout approximate the posterior with \(K\) samples \(\theta_k\), which gives the formula used in FIG 2. With more data the posterior concentrates and the second term goes to 0, while the first tends to the true noise variance.
贝叶斯线性回归(FIG 1、FIG 6)Bayesian linear regression (FIG 1, FIG 6)
特征矩阵 \(\Phi\)(第 \(i\) 行是 \(\boldsymbol\phi(z_i)^\top\)),先验 \(\mathbf w\sim\mathcal N(\mathbf 0,\Sigma_0)\),噪声方差 \(\sigma_i^2\) 可以逐点不同,记 \(\Lambda=\operatorname{diag}(1/\sigma_i^2)\)。后验是高斯的:
Feature matrix \(\Phi\) (row \(i\) is \(\boldsymbol\phi(z_i)^\top\)), prior \(\mathbf w\sim\mathcal N(\mathbf 0,\Sigma_0)\), noise variances \(\sigma_i^2\) allowed to differ per point, \(\Lambda=\operatorname{diag}(1/\sigma_i^2)\). The posterior is Gaussian:
\(\mathbf m\) 就是岭回归(4.6 节的 MAP)。\(\Sigma_{\mathbf w}^{-1}\) 是“信息”:每个测量把 \(\boldsymbol\phi(z_i)\boldsymbol\phi(z_i)^\top/\sigma_i^2\) 加进去,所以在一个地方测 \(N\) 次,那里的认知方差大约按 \(\sigma^2/N\) 下降(FIG 1 的 \(1/\sqrt N\));噪声大的测量贡献的信息少(FIG 6 里远处的板“不值钱”)。注意 \(\sigma^2_{\mathrm{epi}}\) 不依赖 \(\mathbf y\):认知不确定性只取决于在哪里测过、测得多准,而不是测到了什么。本页用 25 个宽 0.2 m 的高斯鼓包加一个常数项,鼓包权重的先验标准差为 6 mm,常数项为 10 mm;数值上用 Cholesky 分解,\(\sigma^2_{\mathrm{epi}}=\|L^{-1}\boldsymbol\phi\|^2\)。
\(\mathbf m\) is ridge regression (the MAP of Lesson 4.6). \(\Sigma_{\mathbf w}^{-1}\) is the "information": each measurement adds \(\boldsymbol\phi(z_i)\boldsymbol\phi(z_i)^\top/\sigma_i^2\), so measuring \(N\) times at one place makes the epistemic variance there fall roughly like \(\sigma^2/N\) (the \(1/\sqrt N\) of FIG 1), and a noisy measurement contributes little information (the "cheap" far boards of FIG 6). Note that \(\sigma^2_{\mathrm{epi}}\) does not depend on \(\mathbf y\): epistemic uncertainty depends only on where you measured and how precisely, not on what you measured. This page uses 25 Gaussian bumps of width 0.2 m plus a constant, with prior standard deviations of 6 mm on the bump weights and 10 mm on the constant; numerically it uses a Cholesky factor, \(\sigma^2_{\mathrm{epi}}=\|L^{-1}\boldsymbol\phi\|^2\).
高斯 NLL 的梯度Gradients of the Gaussian NLL
单个样本的损失 \(\ell=\log\sigma+\frac{r^2}{2\sigma^2}\),\(r=y-\mu\)。对两个输出求导:
Per-sample loss \(\ell=\log\sigma+\frac{r^2}{2\sigma^2}\) with \(r=y-\mu\). Differentiating with respect to both outputs:
第一式说明:均值的梯度被 \(1/\sigma^2\) 加权,噪声大的点“拉力”小,这是逐点加权最小二乘,与卡尔曼滤波按协方差加权是同一个道理。它也是 NLL 的一个坑:网络可以把某些难拟合的区域的 σ 报大,从而几乎不再学那里的均值(Seitzer 等 2022 提出的 β-NLL 用 \(\sigma^{2\beta}\) 重新加权来缓解)。第二式说明 σ² 学的是残差平方的条件期望:如果均值本身拟合得不好,系统误差也会被当成“噪声”(FIG 2 里近处 σ 偏大)。本页的 \(\sigma_{\min}\) 取 0.2 mm,防止除以零。
The first expression says the gradient on the mean is weighted by \(1/\sigma^2\): noisy points pull less. This is pointwise weighted least squares, the same idea as weighting by covariance in a Kalman filter. It is also a trap of the NLL: the network can report a large σ for regions that are hard to fit and then hardly learn the mean there (β-NLL, proposed by Seitzer et al. 2022, reweights by \(\sigma^{2\beta}\) to mitigate this). The second says σ² learns the conditional expectation of the squared residual: if the mean itself fits poorly, systematic error is booked as "noise" too (the inflated near-range σ of FIG 2). On this page \(\sigma_{\min}\) is 0.2 mm, to avoid dividing by zero.
分类:熵的分解Classification: decomposing the entropy
分类器的集成给出 \(K\) 个概率 \(p_k\),平均 \(\bar p\)。预测熵(4.11 节)同样分成两部分:
An ensemble of classifiers gives \(K\) probabilities \(p_k\) with mean \(\bar p\). The predictive entropy (Lesson 4.11) splits in the same way:
左边是总不确定性,右边第一项(各成员熵的平均)是偶然部分,第二项互信息是认知部分。互信息 \(I\) 是“如果知道了真参数,能对 \(y\) 多知道多少”:成员都说 0.5 时总熵最大,但互信息为 0,这是纯偶然(这个抓取本来就看运气);成员一个说 0.05、一个说 0.95 时,平均也是 0.5,互信息却很大,这是认知的(模型没见过)。主动学习的 BALD(Houlsby 等 2011)就是挑互信息最大的样本去标注。
The left side is the total uncertainty; on the right the first term (the members' mean entropy) is the aleatoric part and the second, the mutual information, the epistemic part. The mutual information \(I\) is "how much more we would know about \(y\) if we knew the true parameters". If all members say 0.5 the total entropy is maximal but the mutual information is 0: pure aleatoric (this grasp is simply a matter of luck). If one says 0.05 and another 0.95 the mean is still 0.5, but the mutual information is large: epistemic (the model has not seen this). BALD (Houlsby et al. 2011) in active learning labels exactly the samples with the largest mutual information.
校准与温度缩放Calibration and temperature scaling
校准的定义:\(\mathbb P(Y=1\mid\hat p(X)=p)=p\) 对所有 \(p\) 成立。ECE 用分箱近似它(分箱数会影响数值,结果要连同分箱方式一起报告)。温度缩放求 \(T^\ast=\arg\min_T\sum_{i\in\mathcal D_{\mathrm{val}}}\ell_{\mathrm{BCE}}\big(z_i/T,\,y_i\big)\),这是一维凸问题(对 \(1/T\) 是凸的),本页用黄金分割搜索。因为 sigmoid 单调,\(z/T\) 与 \(z\) 同号,所以预测类别和准确率都不变;多分类时 softmax\((\mathbf z/T)\) 的最大分量位置也不变。NLL 和 Brier 分数这类严格正常评分规则只在预测分布等于真实分布时取到最优,所以既奖励准确也奖励校准,这也是深度集成用 NLL 训练的理由。
The definition of calibration: \(\mathbb P(Y=1\mid\hat p(X)=p)=p\) for every \(p\). ECE approximates it with bins (the number of bins changes the value, so report it with the binning). Temperature scaling solves \(T^\ast=\arg\min_T\sum_{i\in\mathcal D_{\mathrm{val}}}\ell_{\mathrm{BCE}}\big(z_i/T,\,y_i\big)\), a one-dimensional convex problem (convex in \(1/T\)), solved here by golden-section search. Because the sigmoid is monotone, \(z/T\) has the same sign as \(z\), so the predicted class and the accuracy do not change; with many classes the position of the largest entry of softmax\((\mathbf z/T)\) does not change either. Strictly proper scoring rules such as the NLL and the Brier score are optimal only when the predicted distribution equals the true one, so they reward both accuracy and calibration, which is also why deep ensembles are trained with the NLL.
共形预测的推导Deriving conformal prediction
设分数 \(s_1,\dots,s_n,s_{n+1}\)(最后一个是测试点)可交换,并假设没有并列。则 \(s_{n+1}\) 在这 \(n+1\) 个数中的排名在 \(\{1,\dots,n+1\}\) 上均匀分布。记 \(s_{(k)}\) 为校准分数中第 \(k\) 小的:
Let the scores \(s_1,\dots,s_n,s_{n+1}\) (the last one belongs to the test point) be exchangeable, with no ties. Then the rank of \(s_{n+1}\) among the \(n+1\) numbers is uniform on \(\{1,\dots,n+1\}\). Write \(s_{(k)}\) for the \(k\)-th smallest calibration score:
集合 \(C(x)=\{y:s(x,y)\le\hl{qhat}{\hat q}\}\) 就是预测区间(或分类时的预测集合)。分数函数可以任选:绝对残差、除以某个尺度 u(x) 的归一化残差、分位数回归的上下界之差(CQR)、分类时 \(1-\hat p_y\)。选得好,集合更小、更贴合每个输入的难度,但覆盖率保证与选择无关。代价是要留出一份不参与训练的校准数据(分割共形),并且保证只在可交换时成立:时间序列、闭环控制、分布偏移都会破坏它,需要加权或在线的变体。
The set \(C(x)=\{y:s(x,y)\le\hl{qhat}{\hat q}\}\) is the prediction interval (or, for classification, the prediction set). Any score function will do: the absolute residual, the residual normalized by a scale u(x), the spread of quantile-regression bounds (CQR), or \(1-\hat p_y\) for classification. A good choice gives smaller sets that track each input's difficulty, but the coverage guarantee does not depend on the choice. The price is a held-out calibration set that is not used for training (split conformal), and the guarantee holds only under exchangeability: time series, closed-loop control and distribution shift all break it and need weighted or online variants.
主动学习的采集函数(FIG 6)Acquisition functions for active learning (FIG 6)
在候选位置 \(z\) 中选下一次测量。FIG 6 比较三种规则:随机;\(\hl{acq}{\arg\max_z\,\sigma^2_{\mathrm{epi}}(z)+\sigma^2(z)}\)(总方差);\(\hl{acq}{\arg\max_z\,\sigma^2_{\mathrm{epi}}(z)}\)(认知方差)。对高斯模型,一次测量带来的信息增益是 \(\tfrac12\log\big(1+\sigma^2_{\mathrm{epi}}(z)/\sigma^2(z)\big)\),它同样只关心认知部分,并且会因噪声大而打折扣。总方差规则把偶然方差算了进去,会一次次去噪声最大的地方,而那里的噪声正是采多少次都消不掉的。
Choose the next measurement among candidate locations \(z\). FIG 6 compares three rules: random; \(\hl{acq}{\arg\max_z\,\sigma^2_{\mathrm{epi}}(z)+\sigma^2(z)}\) (total variance); \(\hl{acq}{\arg\max_z\,\sigma^2_{\mathrm{epi}}(z)}\) (epistemic variance). For a Gaussian model the information a measurement brings is \(\tfrac12\log\big(1+\sigma^2_{\mathrm{epi}}(z)/\sigma^2(z)\big)\); it too cares only about the epistemic part, discounted where the noise is large. The total-variance rule counts the aleatoric variance as well and keeps going to wherever the noise is largest, which is exactly the noise no amount of measuring removes.
6机器人中的它:知道自己什么时候不知道In robotics: knowing when you don't know
求助与陌生输入检测Asking for help and detecting unfamiliar inputs
一个最直接的用法:机器人在不确定时停下来求助(或者换一个保守动作)。问题是用哪个数当“不确定”。下图训练了一个抓取分类器的 5 成员集成,训练抓取都在单位圆内(输入是两个归一化的抓取参数)。把琥珀圈(一个新物体的抓取参数)拖到各处,比较三种分数:单个网络的置信度 \(\max(p,1-p)\)(Hendrycks 与 Gimpel 2017 的基线),集成的互信息 \(\hl{mi}{I}\)(认知),以及到最近训练样本的距离(一种最朴素的密度估计)。
The most direct use: when uncertain, the robot stops and asks for help (or switches to a cautious action). The question is which number counts as "uncertain". The figure below trains a 5-member ensemble of grasp classifiers whose training grasps all lie inside the unit disk (the inputs are two normalized grasp parameters). Drag the amber ring (the grasp parameters of a new object) around and compare three scores: a single network's confidence \(\max(p,1-p)\) (the baseline of Hendrycks and Gimpel 2017), the ensemble's mutual information \(\hl{mi}{I}\) (epistemic), and the distance to the nearest training sample (the plainest density estimate).
- 训练完 600 步后找两个地方:(a) 一处互信息 ≥ 0.1 nats 的地方(沿着成功/失败边界往圆外延伸,例如 (1.75, −3.0) 附近约 0.28);(b) 一处离训练数据 ≥ 1.5、单个网络置信度 ≥ 99%、互信息却 < 0.01 的地方(例如 (3.5, 0))。在 (b) 处只有距离分数报警。After the 600 training steps find two places: (a) one with mutual information ≥ 0.1 nats (follow the success/failure boundary out of the disk; near (1.75, −3.0) it is about 0.28); (b) one at distance ≥ 1.5 from the training data where the single net is ≥ 99% confident and yet the mutual information is < 0.01 (for example (3.5, 0)). At (b) only the distance score raises the alarm.
这张图值得多看一会儿。单个网络的置信度在圆外几乎处处接近 100%:ReLU 网络离数据越远,logit 越像一个线性函数,绝对值越来越大(Hein 等 2019 证明了这在 ReLU 网络里几乎不可避免)。集成的互信息只在“边界延长线”附近变大:那里成员们对边界往哪边弯意见不一;在别的方向上,5 个网络都学到了“越往右越成功、越往左越失败”,一起自信地外推,互信息几乎为 0。圆内边界附近预测熵很大(最大可到 \(\log 2\approx0.69\) nats),但互信息很小:这是偶然的,这类抓取本来就是一半一半,请人帮忙也没用。所以实际系统常把几种信号组合起来:集成或 dropout 的分歧、特征空间里的距离或密度,再加上任务层面的检查(比如抓取后检测是否真的抓住了)。
This figure rewards a longer look. The single network's confidence is close to 100% almost everywhere outside the disk: the farther a ReLU network gets from the data, the more its logit behaves like a linear function whose magnitude keeps growing (Hein et al. 2019 showed this is almost unavoidable for ReLU networks). The ensemble's mutual information grows only near the "extension of the boundary", where the members disagree about which way the boundary bends; in other directions all 5 networks learned "further right succeeds, further left fails" and extrapolate confidently together, with mutual information close to 0. Near the boundary inside the disk the predictive entropy is large (up to \(\log 2\approx0.69\) nats) but the mutual information is small: that is aleatoric, such grasps really are fifty-fifty, and asking a person will not help. So real systems often combine several signals: ensemble or dropout disagreement, distance or density in feature space, plus checks at the task level (such as verifying after a grasp that the object is really held).
主动学习:下一块标定板放哪里Active learning: where should the next calibration board go?
回到深度相机。每次摆一块标定板都要人工时间,我们想用尽量少的测量把整个 0–3 m 的误差曲线学好。现在假设噪声模型 σ(z) 已经知道(例如用 FIG 2 学出来),模型是 FIG 1 的贝叶斯线性回归,但按每个距离的噪声加权。一开始只有 0.6、1.0、1.4、1.8 m 四个测量,之后每一步按某个规则从 0–3 m(步长 2 cm)里选下一个距离。
Back to the depth camera. Every board placement costs human time, and we want to learn the whole 0–3 m error curve with as few measurements as possible. Assume the noise model σ(z) is now known (learned as in FIG 2, say) and the model is FIG 1's Bayesian linear regression, weighted by the noise at each distance. It starts with only four measurements at 0.6, 1.0, 1.4 and 1.8 m; at each step a rule picks the next distance from 0–3 m (in 2 cm steps).
- 三种规则都各自放到 24 次测量:最大总方差几乎每次都把板放在 3.00 m(20 块里 19 块),平均认知 σ 停在 5.66 mm;随机为 3.91 mm;最大认知方差为 2.80 mm,RMSE 也最低(1.84 mm,随机 2.72,总方差 4.21)。Run each of the three rules up to 24 measurements: max total variance puts the board at 3.00 m almost every time (19 of 20 boards) and its mean epistemic σ stalls at 5.66 mm; random reaches 3.91 mm; max epistemic variance reaches 2.80 mm and the lowest RMSE as well (1.84 mm, versus 2.72 random and 4.21 total variance).
总方差规则的失败很有代表性:3 m 处的噪声(11.3 mm)比任何地方都大,总方差永远最大,规则一遍遍把板放在那里,可每次测量带来的信息很少,别处的认知不确定性也一直降不下来。认知方差规则先把没测过的两端(0 m 附近和 2–3 m)补上,然后在远处多放几块,因为远处噪声大,每块板“值”得少,要多测几次才能把那里的认知方差压到和别处一样。随机规则不算差,但浪费在已经测得很准的地方。单次运行的 RMSE 受测量噪声影响会起伏;对 40 个随机种子平均,24 次测量时认知规则 2.15 mm,随机 2.53 mm,总方差 3.14 mm,排序不变。
The failure of the total-variance rule is typical: the noise at 3 m (11.3 mm) is larger than anywhere else, so the total variance is always largest there and the rule keeps putting the board there; each measurement brings little information and the epistemic uncertainty elsewhere never comes down. The epistemic rule first fills the unmeasured ends (near 0 m and 2–3 m), then places a few more boards far away, because there the noise is large, each board is "worth" less, and more measurements are needed to push the epistemic variance down to the level elsewhere. Random is not bad but wastes boards where the curve is already well measured. The RMSE of a single run fluctuates with the measurement noise; averaged over 40 random seeds, at 24 measurements the epistemic rule gets 2.15 mm, random 2.53 mm and total variance 3.14 mm, the same ranking.
Model-based RL:PETS(Chua 等,NeurIPS 2018)用“概率集成”学动力学:每个成员像 FIG 2 一样输出均值和方差(偶然),成员之间的分歧给出认知部分,规划时让轨迹样本在成员之间传播(24.2 节);MBPO 也用这样的集成,并且只做短的模型展开,因为误差会随展开步数累积(24.1 节)。 探索:Pathak 等(ICML 2019)把动力学模型集成的分歧当作内在奖励,让机器人去模型最没把握的地方。 安全的模仿学习与求助:EnsembleDAgger(Menda 等,IROS 2019)在策略集成分歧大时把控制交还给专家;ThriftyDAgger(Hoque 等,CoRL 2021)结合“新奇度”(集成分歧)和“风险”决定什么时候请人接管(22.1 节)。 语言规划器求助:KnowNo(Ren 等,CoRL 2023)对大语言模型给出的候选计划做共形预测,预测集合里不止一个选项时才向人提问,从而把求助次数和成功率之间的权衡做成有统计保证的形式。 感知:Kendall 与 Gal(NeurIPS 2017)在单目深度估计和语义分割里同时估计异方差(偶然)和 MC dropout(认知)不确定性;输出自身协方差的学习型测量模型可以直接接进卡尔曼滤波(例如 BackpropKF,Haarnoja 等 2016)。 安全探索:用高斯过程估计不确定性的安全贝叶斯优化,只在“有很大把握安全”的参数里试验,曾用于四旋翼控制器的调参(Berkenkamp 等,ICRA 2016)。 仿真到现实:域随机化把训练分布撑宽,让真实世界落在“有数据”的区域里(23.2 节)。
Model-based RL: PETS (Chua et al., NeurIPS 2018) learns dynamics with a "probabilistic ensemble": each member outputs a mean and a variance as in FIG 2 (aleatoric), the disagreement among members gives the epistemic part, and planning propagates trajectory samples through the members (Lesson 24.2); MBPO uses such an ensemble too and keeps model rollouts short because errors compound with the rollout length (Lesson 24.1). Exploration: Pathak et al. (ICML 2019) use the disagreement of an ensemble of dynamics models as an intrinsic reward that sends the robot where the model is least sure. Safe imitation and asking for help: EnsembleDAgger (Menda et al., IROS 2019) hands control back to the expert when a policy ensemble disagrees; ThriftyDAgger (Hoque et al., CoRL 2021) combines "novelty" (ensemble disagreement) and "risk" to decide when to ask a person to take over (Lesson 22.1). Language planners that ask for help: KnowNo (Ren et al., CoRL 2023) applies conformal prediction to the candidate plans of a large language model and asks a person only when the prediction set holds more than one option, turning the trade-off between help requests and success into one with a statistical guarantee. Perception: Kendall and Gal (NeurIPS 2017) estimate heteroscedastic (aleatoric) and MC-dropout (epistemic) uncertainty together for monocular depth estimation and semantic segmentation; learned measurement models that output their own covariance can be plugged straight into a Kalman filter (BackpropKF, Haarnoja et al. 2016, for example). Safe exploration: safe Bayesian optimization with Gaussian-process uncertainty tries only parameters that are safe with high confidence, and has been used to tune quadrotor controllers (Berkenkamp et al., ICRA 2016). Sim-to-real: domain randomization widens the training distribution so that the real world falls inside a region that has data (Lesson 23.2).
7常见误区Common pitfalls
FIG 3:训练到第 1500 步,网络平均说 90.8% 有把握,实际只对了 76.9%。现代网络普遍过度自信(Guo 等 2017),越大、训练越久越明显。用概率阈值做决定之前(“成功率低于 0.8 就求助”),先在留出数据上画可靠性图、算 ECE,必要时做温度缩放。校准集不能是训练集,也不能是拿来选超参数的同一份数据。
FIG 3: at step 1500 the network claims 90.8% confidence on average and is right 76.9% of the time. Modern networks are commonly overconfident (Guo et al. 2017), more so the larger they are and the longer they train. Before making decisions on a probability threshold ("ask for help below 0.8 success"), draw a reliability diagram and compute the ECE on held-out data, and temperature-scale if needed. The calibration set must not be the training set, nor the same data used to pick hyperparameters.
集成的分歧只是认知不确定性的一个下界式的近似:成员共享同样的结构、同样的数据,也就共享同样的外推偏好。FIG 2 在 2.9 m 处错了 35 mm,总标准差只有 3.9 mm;FIG 5 里大片圆外区域互信息接近 0。对安全攸关的决定,要同时检查输入是否离训练数据太远(特征空间的距离或密度),并且最好的办法仍是到那里采数据(16.2 节)。随机先验函数(Osband 等 2018)等方法能增加成员在数据外的多样性,但也不能保证。
An ensemble's disagreement is an approximation of epistemic uncertainty that tends to underestimate it: the members share the same architecture and the same data, and so the same preferences for extrapolation. FIG 2 is 35 mm off at 2.9 m while its total standard deviation is 3.9 mm; in FIG 5 large regions outside the disk have mutual information near 0. For safety-critical decisions also check whether the input is too far from the training data (distance or density in feature space), and the best remedy is still to collect data there (Lesson 16.2). Methods such as randomized prior functions (Osband et al. 2018) increase the members' diversity away from the data, but guarantee nothing either.
σ 头也是网络:在没有数据的地方它同样在猜,均值拟合不好的地方它把系统误差算成噪声,训练久了它还会跟着均值一起过拟合,把 σ 越学越小(FIG 2 从 1500 步练到 3000 步,远处覆盖率从 78.3% 降到 76.3%)。NLL 训练还可能让网络在难拟合的区域报大 σ、放弃学均值。办法:用验证集 NLL 早停,必要时用 β-NLL,并像 FIG 2 那样在留出数据上检查区间的覆盖率,最好分区域检查。
The σ head is a network too: where there are no data it guesses, where the mean fits poorly it books systematic error as noise, and with long training it overfits along with the mean and learns ever smaller σ (training FIG 2 from 1500 to 3000 steps lowers the far coverage from 78.3% to 76.3%). NLL training can also let the network report a large σ in hard regions and give up learning the mean there. Remedies: early-stop on validation NLL, use β-NLL if needed, and check interval coverage on held-out data as FIG 2 does, preferably region by region.
共形预测保证的是对校准数据和测试点一起随机的边缘覆盖率。FIG 4 的绝对分数总体刚好约 90%,近处却 100%、远处约 66%;一组具体的校准数据也可能偏离(n = 50 时 5%–95% 约 81.5%–96.5%)。测试数据一旦来自别的分布(FIG 4 的“偏移”,n = 200 时 40.8%),或者是闭环控制里相互依赖的时间序列,可交换性就不成立,保证随之失效。
Conformal prediction guarantees marginal coverage over the random draw of calibration data and test point together. FIG 4's absolute score is about 90% overall, yet 100% near and about 66% far; one particular calibration set may also miss (5–95% range about 81.5–96.5% at n = 50). Once the test data come from another distribution (FIG 4's "shift", 40.8% at n = 200), or form a dependent time series inside a closed loop, exchangeability fails and the guarantee goes with it.
主动学习和探索要追认知不确定性:按总不确定性采样会被噪声吸走(FIG 6 里 20 块板有 19 块放在 3.00 m);在强化学习探索里,这就是“噪声电视”问题:一个永远不可预测的随机源会一直吸引好奇心驱动的智能体。反过来,求助也应主要看认知部分:FIG 5 圆内边界附近熵很大、互信息很小,这类抓取请人也只是一半一半。规划里留安全余量时,两种都要算进去。
Active learning and exploration should chase epistemic uncertainty: sampling by total uncertainty gets swallowed by the noise (19 of 20 boards at 3.00 m in FIG 6); in RL exploration this is the "noisy TV" problem, where a source of irreducible randomness keeps attracting a curiosity-driven agent. Conversely, asking for help should look mainly at the epistemic part: near FIG 5's boundary inside the disk the entropy is large and the mutual information small, and a person would also find such grasps fifty-fifty. When leaving a safety margin in planning, count both.
8小练习Check yourself
9延伸阅读Further reading
- A. Der Kiureghian & O. Ditlevsen, Aleatory or Epistemic? Does It Matter?, Structural Safety, 2009 — 两种不确定性的区分从哪里来、为什么重要where the distinction between the two kinds comes from and why it matters
- C. M. Bishop, Pattern Recognition and Machine Learning, Springer, 2006, Ch. 3; C. E. Rasmussen & C. K. I. Williams, Gaussian Processes for Machine Learning, MIT Press, 2006 — 贝叶斯线性回归与高斯过程的预测方差Bayesian linear regression and the predictive variance of Gaussian processes
- D. A. Nix & A. S. Weigend, Estimating the Mean and Variance of the Target Probability Distribution, IEEE International Conference on Neural Networks, 1994 — 输出均值和方差的网络,用高斯 NLL 训练networks that output a mean and a variance, trained with the Gaussian NLL
- B. Lakshminarayanan, A. Pritzel & C. Blundell, Simple and Scalable Predictive Uncertainty Estimation using Deep Ensembles, NeurIPS 2017 — 深度集成deep ensembles
- Y. Gal & Z. Ghahramani, Dropout as a Bayesian Approximation: Representing Model Uncertainty in Deep Learning, ICML 2016 — MC dropoutMC dropout
- A. Kendall & Y. Gal, What Uncertainties Do We Need in Bayesian Deep Learning for Computer Vision?, NeurIPS 2017 — 在深度估计和分割中同时建模偶然与认知不确定性modelling aleatoric and epistemic uncertainty together in depth estimation and segmentation
- C. Guo, G. Pleiss, Y. Sun & K. Q. Weinberger, On Calibration of Modern Neural Networks, ICML 2017 — 现代网络的过度自信、可靠性图与温度缩放the overconfidence of modern networks, reliability diagrams and temperature scaling
- Y. Ovadia et al., Can You Trust Your Model's Uncertainty? Evaluating Predictive Uncertainty Under Dataset Shift, NeurIPS 2019 — 分布偏移下各种方法的校准如何退化how the calibration of various methods degrades under dataset shift
- V. Vovk, A. Gammerman & G. Shafer, Algorithmic Learning in a Random World, Springer, 2005; A. N. Angelopoulos & S. Bates, A Gentle Introduction to Conformal Prediction and Distribution-Free Uncertainty Quantification, arXiv, 2021 — 共形预测的经典著作与入门教程the classic book and a hands-on tutorial on conformal prediction
- D. Hendrycks & K. Gimpel, A Baseline for Detecting Misclassified and Out-of-Distribution Examples in Neural Networks, ICLR 2017; M. Hein, M. Andriushchenko & J. Bitterwolf, Why ReLU Networks Yield High-Confidence Predictions Far Away from the Training Data and How to Mitigate the Problem, CVPR 2019 — 用置信度检测陌生输入,以及它为什么会失败detecting unfamiliar inputs by confidence, and why it fails
- N. Houlsby, F. Huszár, Z. Ghahramani & M. Lengyel, Bayesian Active Learning for Classification and Preference Learning, arXiv, 2011; B. Settles, Active Learning Literature Survey, University of Wisconsin–Madison, 2009 — BALD 与主动学习综述BALD and a survey of active learning
- M. Seitzer, A. Tavakoli, D. Antic & G. Martius, On the Pitfalls of Heteroscedastic Uncertainty Estimation with Probabilistic Neural Networks, ICLR 2022 — β-NLLβ-NLL
- K. Chua, R. Calandra, R. McAllister & S. Levine, Deep Reinforcement Learning in a Handful of Trials using Probabilistic Dynamics Models, NeurIPS 2018 — PETS:概率集成用于 model-based RLPETS: probabilistic ensembles for model-based RL
- A. Z. Ren et al., Robots That Ask For Help: Uncertainty Alignment for Large Language Model Planners, CoRL 2023 — KnowNo:用共形预测决定何时求助KnowNo: conformal prediction to decide when to ask for help