Part I · 第 4 章 概率 · 4.4Part I · Ch. 4 Probability · 4.4

高斯分布The Gaussian Distribution

机器人学里最常见的分布,是那条钟形曲线。它不是随便挑的:许多小误差叠加会得到它,它又有三个神奇的"封闭性":线性变换之后还是高斯,切一刀(条件化)还是高斯,两个相乘还是高斯。卡尔曼滤波的全部数学,就是反复用这几条性质。这一节把它从一维讲到多维,并且用眼睛把条件化与乘积看明白。 The most common distribution in robotics is the bell curve. It is not an arbitrary pick: it emerges when many small errors pile up, and it has three magical closure properties: push it through a linear map and it stays Gaussian, slice it (condition) and it stays Gaussian, multiply two and it stays Gaussian. The entire mathematics of the Kalman filter is the repeated use of these properties. This lesson goes from 1D to many dimensions and lets you see conditioning and products with your own eyes.

约 30 分钟~30 min 前置:4.3 期望、方差与协方差 · 1.6 逆 · 1.11 特征值Prereqs: 4.3 Expectation & Covariance · 1.6 Inverse · 1.11 Eigenvalues 5 个交互5 interactives

    1为什么机器人需要它Why robots need this

    想象要用一个分布来描述"机器人在哪"。直方图要存很多格子,粒子要存很多点,而高斯分布只需要两个量:均值和协方差。三维位姿加上速度,也不过是一个向量加一个小矩阵。这让它成为状态估计里最"便宜"的信念表示。

    便宜之外,它还有三条"封闭性",它们是卡尔曼滤波能精确运算的原因:

    • 线性变换封闭:高斯过一个线性映射 \(A\mathbf x + \mathbf b\) 还是高斯(4.5 节:预测步);
    • 条件化封闭:已知一部分变量的取值,其余变量的分布还是高斯(本节 FIG 4);
    • 乘积封闭:两个高斯相乘,再归一化,还是高斯(本节 FIG 5:更新步,融合两个传感器)。

    再加上"中心极限定理":许多独立的小误差叠加,总是趋向高斯,所以传感器噪声常常真的近似高斯。这并不是巧合,也不是数学上的便利而已。

    Suppose you want a distribution to describe "where the robot is". A histogram needs many cells, particles need many points, but a Gaussian needs only two things: a mean and a covariance. A 3D pose plus velocity is still just a vector and a small matrix. That makes it the cheapest belief representation in state estimation.

    Besides being cheap it has three closure properties, which is why the Kalman filter can compute exactly:

    • Closed under linear maps: a Gaussian through \(A\mathbf x + \mathbf b\) is Gaussian (Lesson 4.5: the predict step);
    • Closed under conditioning: fix some variables and the rest are still Gaussian (FIG 4 here);
    • Closed under products: multiply two Gaussians and normalize, you get a Gaussian (FIG 5: the update step, fusing two sensors).

    Add the central limit theorem: many independent small errors, added up, tend toward a Gaussian, so sensor noise really is often close to Gaussian. This is neither a coincidence nor mere mathematical convenience.

    2直觉:一条由 μ 和 σ 决定的钟形曲线Intuition: a bell shaped by μ and σ

    一维高斯 \(\mathcal N(\mu, \sigma^2)\) 只有两个旋钮:均值 \(\mu\) 决定钟的位置,标准差 \(\sigma\) 决定它有多胖。因为总面积恒为 1,钟变胖就必须变矮,变瘦就必须变高。

    它最值得记住的性质是"68–95–99.7 规则":落在 \(\mu \pm \sigma\) 内的概率约 68%,\(\mu \pm 2\sigma\) 内约 95%,\(\mu \pm 3\sigma\) 内约 99.7%。所以"\(\pm 3\sigma\) 之外"几乎不会发生,一个读数偏离这么远,十有八九是出了故障或遇到了离群点。拖动图中的两个手柄,再拖动带宽 \(k\)。

    A 1D Gaussian \(\mathcal N(\mu, \sigma^2)\) has just two knobs: the mean \(\mu\) sets where the bell sits, the standard deviation \(\sigma\) sets how fat it is. The total area is always 1, so a fatter bell must be lower and a thinner one taller.

    Its most memorable property is the "68–95–99.7 rule": about 68% of the probability lies within \(\mu \pm \sigma\), about 95% within \(\mu \pm 2\sigma\), about 99.7% within \(\mu \pm 3\sigma\). So "beyond \(\pm 3\sigma\)" almost never happens, and a reading that far off is most likely a fault or an outlier. Drag the two handles, then the half-width \(k\).

    FIG 1一维高斯与 68–95–99.7The 1D Gaussian and 68–95–99.7
    拖动底部圆点改变 \(\mu\),拖动曲线腰部的圆点改变 \(\sigma\)。黄色阴影是 \(\mu \pm k\sigma\) 内的面积;下方的紫点是 300 个抽样,落在带内的点用实心显示,带外的为空心。 Drag the dot at the base to change \(\mu\), the dot on the flank to change \(\sigma\). The amber shading is the area within \(\mu \pm k\sigma\); the purple dots below are 300 samples, solid inside the band and hollow outside.
    试一试Try this
    • 把 \(\sigma\) 压到 0.5 以下,看峰值涨到约 0.8:面积不变,所以瘦了就要高。Squeeze \(\sigma\) below 0.5 and the peak rises to about 0.8: the area is fixed, so thin means tall.
    • 令 \(k = 1\)、\(2\)、\(3\):面积依次是 68.3%、95.4%、99.7%,实心点的比例也跟着变。Set \(k = 1\), \(2\), \(3\): the area is 68.3%, 95.4%, 99.7%, and the fraction of solid dots follows.
    • 找到使面积恰为 95% 的 \(k\)(约 1.96):这就是 "95% 置信区间 = 均值 ± 1.96σ" 的来历。Find the \(k\) that gives exactly 95% (about 1.96): the origin of "95% confidence interval = mean ± 1.96σ".

    为什么到处都是高斯:中心极限定理Why Gaussians are everywhere: the central limit theorem

    取很多个独立的随机变量相加,不管每个单独长什么样(只要方差有限),它们的和(标准化之后)的分布,会越来越像高斯。传感器的总噪声,往往是电路热噪声、量化误差、微小震动……几十个小来源叠加的结果,于是常常近似高斯。下面选一个"完全不像高斯"的来源,看它怎样被"加"成钟形。

    Add up many independent random variables and, whatever each one looks like (as long as the variance is finite), the distribution of the standardized sum becomes more and more Gaussian. A sensor's total noise is typically the pile-up of dozens of small sources (thermal noise, quantization, tiny vibrations...), hence often close to Gaussian. Pick a source that looks nothing like a Gaussian and watch it get "added" into a bell.

    FIG 2中心极限定理:把 k 个变量加起来Central limit theorem: adding up k variables
    青色柱子是 4000 次实验中"\(k\) 个独立变量之和(减去均值、除以 \(\sqrt{k}\,\sigma\))"的直方图,黄色曲线是标准高斯。"最大差距"是经验分布函数与高斯 CDF 的最大差(Kolmogorov 距离),越小越像。"硬币"之和只能取间隔 \(2/\sqrt{k}\) 的离散值,所以每个取值画一根柱,柱高 = 该取值的概率 ÷ 间隔(这样才能和密度曲线比较)。它的经验分布函数是台阶,"最大差距"因此不会低于最高那级台阶的一半。小图是单个变量自己的分布。 Cyan bars are the histogram, over 4000 experiments, of "the sum of \(k\) independent variables (minus the mean, divided by \(\sqrt{k}\,\sigma\))"; the amber curve is the standard Gaussian. "Max gap" is the largest difference between the empirical distribution function and the Gaussian CDF (the Kolmogorov distance): smaller means more alike. The coin sum only takes values \(2/\sqrt{k}\) apart, so each value gets one bar of height probability ÷ spacing (comparable with the density curve), and its empirical distribution function is a staircase, so its max gap cannot fall below half the tallest step. The inset shows a single variable's own distribution.
    试一试Try this
    • 选"硬币"(只取 ±1,两个尖峰):\(k = 1\) 时是两根针,把 \(k\) 加到 10 以上,针的顶端连起来就贴着钟形曲线。Pick "coin" (only ±1, two spikes): at \(k = 1\) it is two needles; push \(k\) to 10 or more and the needle tips line up along the bell curve.
    • 选"指数"(明显偏斜):把 \(k\) 加到 12 以上,偏斜才大体消失。偏斜得越厉害的来源,需要的 \(k\) 越大。Pick "exponential" (strongly skewed): raise \(k\) to 12 or more before the skew mostly vanishes. The more skewed the source, the larger the \(k\) needed.

    3动手玩:二维高斯与马氏距离Play: the 2D Gaussian and Mahalanobis distance

    二维(以及更高维)高斯的"等高线"是同心椭圆,椭圆的形状正是协方差矩阵(4.3 节)。密度只依赖于一个量:到均值的马氏距离 (Mahalanobis distance)

    \(d_M(\mathbf p) = \sqrt{(\mathbf p - \boldsymbol\mu)^\top \Sigma^{-1} (\mathbf p - \boldsymbol\mu)}\)

    它是"按各方向的标准差来量的距离":沿着不确定性大的方向,同样的欧氏距离算"近";沿着不确定性小的方向,算"远"。把 \(\Sigma\) 拿掉,它就是普通的欧氏距离。一个点是否"反常",要看马氏距离,而不是欧氏距离。

    拖动图中的均值、两个主轴把手,再拖动那个测试点 \(\mathbf p\):对比欧氏距离与马氏距离。

    The "contours" of a 2D (or higher-dimensional) Gaussian are concentric ellipses, and their shape is exactly the covariance matrix (Lesson 4.3). The density depends on a single quantity: the Mahalanobis distance to the mean,

    \(d_M(\mathbf p) = \sqrt{(\mathbf p - \boldsymbol\mu)^\top \Sigma^{-1} (\mathbf p - \boldsymbol\mu)}\)

    It is "distance measured in standard deviations of each direction": along a direction of large uncertainty the same Euclidean distance counts as "near", along a direction of small uncertainty as "far". Remove \(\Sigma\) and it is the ordinary Euclidean distance. Whether a point is "unusual" depends on its Mahalanobis, not Euclidean, distance.

    Drag the mean, the two principal-axis handles and the test point \(\mathbf p\), and compare the Euclidean and Mahalanobis distances.

    FIG 3椭圆等高线与马氏距离Elliptical contours and Mahalanobis distance
    500 个样本;黄色椭圆是 \(d_M = 1, 2, 3\);两个黄色把手在 1σ 椭圆的轴端,圆心也可拖。紫色测试点 \(\mathbf p\) 与均值之间的虚线表示欧氏距离,穿过 \(\mathbf p\) 的紫色椭圆是它所在的等高线。右侧表格:落在各等高线内的样本比例,与理论值 \(1 - e^{-r^2/2}\) 对比。 500 samples; the amber ellipses are \(d_M = 1, 2, 3\); the two amber handles sit at the axis tips of the 1σ ellipse, and the center can be dragged too. The dashed line from the mean to the purple test point \(\mathbf p\) shows the Euclidean distance; the purple ellipse through \(\mathbf p\) is the contour it lies on. The table on the right compares the fraction of samples inside each contour with the theory \(1 - e^{-r^2/2}\).
    试一试Try this
    • 找一个点:欧氏距离 ≥ 1.8,马氏距离却 ≤ 1(沿着长轴方向走)。Find a point with Euclidean distance ≥ 1.8 but Mahalanobis distance ≤ 1 (walk along the long axis).
    • 再找一个点:欧氏距离 ≤ 1,马氏距离却 ≥ 2(沿着短轴方向)。Now a point with Euclidean distance ≤ 1 but Mahalanobis distance ≥ 2 (along the short axis).
    2σ 椭圆不是 95%The 2σ ellipse is not 95%

    看右侧表格:二维里 \(d_M \le 1\) 的概率只有 39.3%,\(d_M \le 2\) 是 86.5%,要到 \(d_M \le 3\) 才是 98.9%。想要 95% 的椭圆,半径是 \(r = \sqrt{5.99} \approx 2.45\)。原因是维度越高,概率"外溢"得越多(\(d_M^2\) 服从自由度为 2 的卡方分布,它的 CDF 是 \(1 - e^{-r^2/2}\))。

    Look at the table: in 2D the probability of \(d_M \le 1\) is only 39.3%, \(d_M \le 2\) is 86.5%, and \(d_M \le 3\) only reaches 98.9%. A 95% ellipse needs radius \(r = \sqrt{5.99} \approx 2.45\). The reason is that probability "spills outward" more in higher dimensions (\(d_M^2\) follows a chi-square distribution with 2 degrees of freedom, whose CDF is \(1 - e^{-r^2/2}\)).

    4第二个视角:边缘化与条件化A second view: marginalizing and conditioning

    对一个联合高斯 \(p(x, y)\),有两种"降维":

    • 边缘化:忘掉 \(y\),只看 \(x\)。几何上是把点云投影到 \(x\) 轴;结果还是高斯,均值与方差直接取原来的那一项:\(x \sim \mathcal N(\mu_x, \sigma_x^2)\),与 \(\rho\) 无关。
    • 条件化:已知 \(x = x_0\),问 \(y\) 的分布。几何上是在 \(x = x_0\) 处切一刀,看这条细缝里点的分布;结果还是高斯,但均值会沿着相关性移动,方差会变小。

    条件化的方差比边缘分布小,而且不依赖于 \(x_0\) 的具体取值,只取决于相关性有多强:\(\sigma_{y|x}^2 = \sigma_y^2(1 - \rho^2)\)。这正是 4.8 节"只测位置,速度也变准"的原因:测量就是条件化。

    For a joint Gaussian \(p(x, y)\) there are two kinds of "dimension reduction":

    • Marginalizing: forget \(y\) and look only at \(x\). Geometrically it projects the cloud onto the \(x\) axis; the result is Gaussian and its mean and variance are simply the original entries: \(x \sim \mathcal N(\mu_x, \sigma_x^2)\), whatever \(\rho\) is.
    • Conditioning: given \(x = x_0\), what is the distribution of \(y\)? Geometrically it cuts a slice at \(x = x_0\) and looks at the points in that thin slit; the result is Gaussian, but its mean moves along the correlation and its variance shrinks.

    The conditional variance is smaller than the marginal, and does not depend on the value of \(x_0\), only on how strong the correlation is: \(\sigma_{y|x}^2 = \sigma_y^2(1 - \rho^2)\). This is exactly why in Lesson 4.8 "measure position only and velocity improves too": a measurement is conditioning.

    FIG 4投影(边缘)与切片(条件)Projection (marginal) and slice (conditional)
    3000 个样本。上方和右侧的青色曲线是边缘分布 \(p(x)\)、\(p(y)\)(点云的投影)。拖动底部的黄色圆点设置 \(x_0\):竖线右边的黄色曲线是条件分布 \(p(y \mid x = x_0)\),青色细柱是竖线两侧窄带内真实样本的直方图,用来验证曲线。 3000 samples. The cyan curves at the top and right are the marginals \(p(x)\), \(p(y)\) (projections of the cloud). Drag the amber dot at the bottom to set \(x_0\): the amber curve beside the line is the conditional \(p(y \mid x = x_0)\), and the thin cyan bars are a histogram of the real samples in a narrow band around the line, verifying the curve.
    试一试Try this
    • 令 \(\rho \ge 0.8\):条件分布的宽度缩到边缘分布的 60% 以下。相关越强,知道 \(x\) 越能帮你猜 \(y\)。Set \(\rho \ge 0.8\): the conditional width drops below 60% of the marginal. The stronger the correlation, the more knowing \(x\) helps you guess \(y\).
    • 保持 \(\rho \ne 0\),把 \(x_0\) 拖到一侧,使条件均值偏离 0 超过 1:条件均值沿着"回归线"移动。With \(\rho \ne 0\), drag \(x_0\) aside until the conditional mean is more than 1 away from 0: it moves along the "regression line".
    • 令 \(\rho = 0\):条件分布与边缘分布完全重合,知道 \(x\) 对 \(y\) 毫无帮助(独立)。Set \(\rho = 0\): the conditional coincides exactly with the marginal; knowing \(x\) tells you nothing about \(y\) (independence).

    5再看数学The math

    提示:悬停带底色的符号,FIG 3、FIG 4、FIG 5 里对应的几何会高亮。Tip: hover the shaded symbols and the matching geometry in FIG 3, FIG 4 and FIG 5 lights up.

    密度The density

    $$ \mathcal N(x;\,\mu, \sigma^2) = \frac{1}{\sqrt{2\pi}\,\sigma}\exp\!\Big(-\frac{(x-\mu)^2}{2\sigma^2}\Big) $$ $$ \mathcal N(\mathbf x;\,\boldsymbol\mu, \Sigma) = \frac{1}{(2\pi)^{n/2}\,|\Sigma|^{1/2}}\exp\!\Big(-\tfrac12\,\hl{dM}{(\mathbf x-\boldsymbol\mu)^\top \Sigma^{-1} (\mathbf x-\boldsymbol\mu)}\Big) $$

    指数里那一项就是马氏距离的平方 \(d_M^2\)。等高线 \(d_M = r\) 是椭圆,主轴沿 \(\Sigma\) 的特征向量(1.11),半轴长 \(r\sqrt{\lambda_i}\)。\(n\) 维时 \(d_M^2\) 服从自由度为 \(n\) 的卡方分布;\(n = 2\) 时 \(P(d_M \le r) = 1 - e^{-r^2/2}\)。前面的系数只是让总积分为 1,\(|\Sigma|\) 越大(椭圆越"大"),峰越低。

    The exponent is the squared Mahalanobis distance \(d_M^2\). The contours \(d_M = r\) are ellipses with principal axes along the eigenvectors of \(\Sigma\) (1.11) and semi-axes \(r\sqrt{\lambda_i}\). In \(n\) dimensions \(d_M^2\) follows a chi-square distribution with \(n\) degrees of freedom; for \(n = 2\), \(P(d_M \le r) = 1 - e^{-r^2/2}\). The prefactor only makes the integral 1: the larger \(|\Sigma|\) (the "bigger" the ellipse), the lower the peak.

    三条封闭性The three closure properties

    把向量分成两块 \(\mathbf x = (\mathbf a, \mathbf b)\),均值与协方差也分块:

    Split the vector into two blocks \(\mathbf x = (\mathbf a, \mathbf b)\) with matching blocks in the mean and covariance:

    $$ \begin{bmatrix}\mathbf a\\ \mathbf b\end{bmatrix} \sim \mathcal N\!\left(\begin{bmatrix}\boldsymbol\mu_a\\ \boldsymbol\mu_b\end{bmatrix},\; \begin{bmatrix}\Sigma_{aa} & \Sigma_{ab}\\ \Sigma_{ba} & \Sigma_{bb}\end{bmatrix}\right) $$ $$ \text{(1)}\;\; A\mathbf x + \mathbf c \sim \mathcal N(A\boldsymbol\mu + \mathbf c,\; A\Sigma A^\top) \qquad\text{(2)}\;\; \hl{marg}{\mathbf a \sim \mathcal N(\boldsymbol\mu_a,\, \Sigma_{aa})} $$ $$ \text{(3)}\;\; \hl{cond}{\mathbf a \mid \mathbf b \sim \mathcal N\big(\boldsymbol\mu_a + \Sigma_{ab}\Sigma_{bb}^{-1}(\mathbf b - \boldsymbol\mu_b),\;\; \Sigma_{aa} - \Sigma_{ab}\Sigma_{bb}^{-1}\Sigma_{ba}\big)} $$

    (1) 在 4.5 节推导。(2) 边缘化:直接取子块,丢掉另一半(FIG 4 的投影)。(3) 条件化:均值沿 \(\Sigma_{ab}\Sigma_{bb}^{-1}\)("回归系数")移动,协方差减去一项半正定矩阵,所以只会变小,而且与 \(\mathbf b\) 的具体取值无关。二维情形下,\(\Sigma_{ab}\Sigma_{bb}^{-1} = \rho\sigma_y/\sigma_x\),方差为 \(\sigma_y^2 - \rho^2\sigma_y^2\),正是 FIG 4 的公式。

    (1) is derived in Lesson 4.5. (2) Marginalizing: just take the sub-block and drop the other half (the projection in FIG 4). (3) Conditioning: the mean moves along \(\Sigma_{ab}\Sigma_{bb}^{-1}\) (the "regression coefficient") and the covariance loses a positive semi-definite term, so it can only shrink, independent of the value of \(\mathbf b\). In 2D, \(\Sigma_{ab}\Sigma_{bb}^{-1} = \rho\sigma_y/\sigma_x\) and the variance is \(\sigma_y^2 - \rho^2\sigma_y^2\), exactly FIG 4's formula.

    (4) 乘积:两个关于同一个 \(\mathbf x\) 的高斯"信息"(比如两个传感器各自给出的估计)相乘,再归一化:

    (4) Products: two Gaussian "pieces of information" about the same \(\mathbf x\) (say two sensors' separate estimates), multiplied and normalized:

    $$ \mathcal N(\mathbf x; \boldsymbol\mu_1, \Sigma_1)\;\mathcal N(\mathbf x; \boldsymbol\mu_2, \Sigma_2) \;\propto\; \mathcal N(\mathbf x; \boldsymbol\mu, \Sigma) $$ $$ \hl{prod}{\Sigma^{-1} = \Sigma_1^{-1} + \Sigma_2^{-1}}, \qquad \hl{prod}{\boldsymbol\mu = \Sigma\big(\Sigma_1^{-1}\boldsymbol\mu_1 + \Sigma_2^{-1}\boldsymbol\mu_2\big)} $$

    "精度(协方差的逆)相加,均值是按精度加权的平均"。一维时就是 4.8 节「再看数学」里的公式。多维时精度是矩阵:每个方向分别按自己的精度加权,所以一个传感器擅长的方向,由它说了算(FIG 5)。把这个结果换一种写法,就是卡尔曼增益 \(K = \Sigma_1(\Sigma_1 + \Sigma_2)^{-1}\):\(\boldsymbol\mu = \boldsymbol\mu_1 + K(\boldsymbol\mu_2 - \boldsymbol\mu_1)\),\(\Sigma = (I - K)\Sigma_1\)。

    "Precisions (inverse covariances) add, and the mean is the precision-weighted average." In 1D these are the formulas of the math section of Lesson 4.8. In many dimensions the precision is a matrix, so each direction is weighted by its own precision, and whichever sensor is good in a direction has the say there (FIG 5). Rewritten, this is the Kalman gain \(K = \Sigma_1(\Sigma_1 + \Sigma_2)^{-1}\): \(\boldsymbol\mu = \boldsymbol\mu_1 + K(\boldsymbol\mu_2 - \boldsymbol\mu_1)\), \(\Sigma = (I - K)\Sigma_1\).

    6机器人中的它:把两个传感器的估计融合起来In robotics: fusing two sensors' estimates

    一台机器人在一条长走廊里。激光扫描匹配很准地知道它离两侧墙有多远,却完全不知道自己沿走廊走到了哪里(沿走廊方向毫无特征):它的不确定性椭圆是一条沿走廊的长细条。Wi-Fi/GPS 定位在各个方向都差不多,只是粗糙,是一个大圆饼。两者的乘积,也就是融合之后的信念,会是什么样?

    答案是:垂直走廊的方向由激光说了算,沿走廊的方向由 Wi-Fi 说了算,结果是一个小得多的椭圆:垂直走廊方向和激光一样窄,沿走廊方向比 Wi-Fi 还紧,面积比任何一个传感器的都小。拖动两个椭圆,并试试"垂直的两个长条"预设。右侧给出了两个估计的分歧程度(马氏距离的平方 \(z^2\))和它的 p 值:如果两个传感器差得太远,这个 p 值会很小,说明至少有一个传感器出了问题,这正是卡尔曼滤波里"门限 (gating)"检验的原理。

    A robot is in a long corridor. Laser scan matching knows precisely how far it is from the two walls but has no idea how far along the corridor it is (no features along the corridor): its uncertainty ellipse is a long thin sliver along the corridor. Wi-Fi/GPS positioning is similar in every direction, just coarse: a big round disc. What does their product, the fused belief, look like?

    The answer: across the corridor the laser has the say, along the corridor Wi-Fi does, and the result is a much smaller ellipse: as thin as the laser across the corridor, tighter than Wi-Fi along it, and smaller in area than either sensor's. Drag the two ellipses, and try the "two perpendicular slivers" preset. The sidebar shows how much the two estimates disagree (the squared Mahalanobis distance \(z^2\)) and its p-value: if the two sensors are too far apart this p-value is tiny, signalling that at least one is faulty. This is the principle of "gating" in Kalman filters.

    FIG 5两个高斯相乘:二维传感器融合Multiplying two Gaussians: 2D sensor fusion
    青色与紫色椭圆是两个传感器各自的 2σ 估计,每个都有三个把手(中心、两个轴端)。黄色是它们的乘积,也就是融合结果。黄色椭圆总是落在两者"重叠"的区域里,并且比两者都小。 The cyan and purple ellipses are the two sensors' own 2σ estimates, each with three handles (center and two axis tips). Amber is their product, the fused result. It always lands in the region where the two "overlap" and is smaller than both.
    试一试Try this
    • 点"垂直的两个长条":每个传感器只在一个方向准,融合后的椭圆面积不到任一者的 25%。Press "two perpendicular slivers": each sensor is accurate in only one direction, and the fused ellipse has under 25% of either one's area.
    • 把两个中心拖开,直到 p 值低于 5%:两个传感器在"吵架",此时融合出来的东西不可信。Drag the two centers apart until the p-value drops below 5%: the sensors are "arguing" and the fused result cannot be trusted.
    真实系统里In real systems

    "一个传感器擅长的方向由它说了算",在 SLAM 和多传感器标定里无处不在:激光约束垂直方向、视觉约束朝向、GPS 约束全局位置,把它们的信息(精度)矩阵相加,就得到每个方向都有约束的完整估计。这种"信息相加"的写法叫信息滤波器 / 因子图(6.9 节)。

    "Whichever sensor is good in a direction has the say" is everywhere in SLAM and multi-sensor calibration: the laser constrains the perpendicular direction, vision the orientation, GPS the global position, and adding their information (precision) matrices gives a full estimate constrained in every direction. This "add the information" formulation is the information filter / factor graph (Lesson 6.9).

    7常见误区Common pitfalls

    误区 1:多维里还是"±2σ 约 95%"Pitfall 1: "±2σ is about 95%" in many dimensions too

    一维里是对的,二维 2σ 椭圆只有 86.5%,三维只有 73.9%。要做"95% 置信椭圆",半径要按卡方分布查(二维约 2.45σ,三维约 2.80σ)。判断一个读数是否"合群"(gating)时,这个差别会决定你丢掉多少好数据。

    True in 1D, but the 2σ ellipse holds only 86.5% in 2D and 73.9% in 3D. A "95% confidence ellipse" needs a radius from the chi-square distribution (about 2.45σ in 2D, 2.80σ in 3D). When gating readings, this difference decides how many good measurements you throw away.

    误区 2:噪声一定是高斯的Pitfall 2: noise is always Gaussian

    高斯的尾巴很轻:偏离 \(5\sigma\) 的概率只有 \(6\times 10^{-7}\)。真实传感器却会有离群点(多路径、玻璃反射、误匹配),尾巴远比高斯重。直接把它们当高斯处理,一个离群点就能把估计拉走很远。对策:先做 gating 把离群点挡在外面,或使用鲁棒核函数 (Huber、Cauchy),或混合模型(4.1 节的光束模型)。多峰的信念(两扇一样的门)也无法用一个高斯表示。

    A Gaussian's tails are very light: the probability beyond \(5\sigma\) is about \(6\times 10^{-7}\). Real sensors produce outliers (multipath, glass reflections, false matches) with much heavier tails. Treat them as Gaussian and one outlier can drag the estimate far away. Remedies: gate outliers out first, use robust kernels (Huber, Cauchy), or mixture models (the beam model of Lesson 4.1). A multimodal belief (two identical doors) cannot be represented by one Gaussian either.

    误区 3:协方差矩阵随便写Pitfall 3: writing the covariance matrix carelessly

    \(\Sigma\) 必须对称、半正定;要做马氏距离或乘积,还需要它可逆(正定)。手写协方差时,非对角元素不能超过 \(\sqrt{\sigma_x^2\sigma_y^2}\)(即 \(|\rho| \le 1\))。数值误差会慢慢破坏对称性和正定性,实际代码里常对 \(\Sigma\) 做 \((\Sigma+\Sigma^\top)/2\) 对称化,或加一点很小的对角项。

    \(\Sigma\) must be symmetric and positive semi-definite; for Mahalanobis distances or products it must also be invertible (positive definite). When writing one by hand an off-diagonal entry cannot exceed \(\sqrt{\sigma_x^2\sigma_y^2}\) (\(|\rho| \le 1\)). Round-off slowly destroys symmetry and definiteness, so real code often symmetrizes \(\Sigma\) as \((\Sigma+\Sigma^\top)/2\) or adds a tiny diagonal term.

    误区 4:随便把两个高斯相乘Pitfall 4: multiplying any two Gaussians

    乘积公式的前提和 4.2 节一样:两份信息来自独立的来源。如果两个估计共用了同一批数据(比如两个滤波器都用了同一个里程计),直接相乘会重复计票,得到过度自信的结果。这种情形要用"协方差交叉 (covariance intersection)"之类保守的融合。

    The product formula needs the same premise as Lesson 4.2: the two pieces of information come from independent sources. If the two estimates share data (say both filters used the same odometry), multiplying them double counts and gives an overconfident result. Such cases call for conservative fusion such as "covariance intersection".

    误区 5:角度也当高斯Pitfall 5: treating angles as Gaussian

    朝向角 \(\theta\) 住在一个圆上,179° 和 −179° 其实只差 2°,普通高斯会把它们看成差 358°。小范围内把角度当高斯是个好近似;大不确定性或三维旋转要用李群上的扰动(第 5 章)。

    A heading \(\theta\) lives on a circle: 179° and −179° are only 2° apart, but an ordinary Gaussian sees them 358° apart. Treating angles as Gaussian is a fine approximation locally; for large uncertainty or 3D rotations use perturbations on Lie groups (Chapter 5).

    8小练习Check yourself

    1. 一个读数服从 \(\mathcal N(10, 0.2^2)\)(单位 m)。它落在 \([9.6, 10.4]\) 内的概率约为?1. A reading is \(\mathcal N(10, 0.2^2)\) (meters). What is the probability it falls in \([9.6, 10.4]\)?
    \(\sigma = 0.2\),区间是 \(\mu \pm 2\sigma\),约 95.4%。\(\sigma = 0.2\) and the interval is \(\mu \pm 2\sigma\): about 95.4%.
    2. 二维高斯里,落在 \(d_M \le 2\) 的椭圆内的概率是?2. For a 2D Gaussian, what is the probability of landing inside the \(d_M \le 2\) ellipse?
    \(1 - e^{-r^2/2} = 1 - e^{-2} \approx 0.865\)。一维的 95.4% 在二维要到 \(r \approx 2.45\) 才达到 95%。\(1 - e^{-r^2/2} = 1 - e^{-2} \approx 0.865\). The 1D 95.4% is reached in 2D only at \(r \approx 2.45\) for 95%.
    3. \(\Sigma = \begin{bmatrix}4 & 2\\ 2 & 3\end{bmatrix}\)(先 \(x\) 后 \(y\)),\(\boldsymbol\mu = \mathbf 0\)。已知 \(x = 2\) 时,\(y\) 的条件均值和条件方差是?3. \(\Sigma = \begin{bmatrix}4 & 2\\ 2 & 3\end{bmatrix}\) (\(x\) first, then \(y\)), \(\boldsymbol\mu = \mathbf 0\). Given \(x = 2\), what are the conditional mean and variance of \(y\)?
    \(\Sigma_{yx}\Sigma_{xx}^{-1} = 2/4 = 0.5\),条件均值 \(= 0.5 \times 2 = 1\);条件方差 \(= 3 - 2\cdot 2/4 = 3 - 1 = 2\)。方差比边缘方差 3 小,与 \(x = 2\) 的具体值无关。\(\Sigma_{yx}\Sigma_{xx}^{-1} = 2/4 = 0.5\), so the conditional mean is \(0.5 \times 2 = 1\); the conditional variance is \(3 - 2\cdot 2/4 = 3 - 1 = 2\). It is smaller than the marginal 3 and independent of the particular value \(x = 2\).
    4. 两个无偏估计,协方差分别为 \(\Sigma_1 = \mathrm{diag}(1, 4)\)、\(\Sigma_2 = \mathrm{diag}(4, 1)\)。融合(相乘)后的协方差是?4. Two unbiased estimates have covariances \(\Sigma_1 = \mathrm{diag}(1, 4)\) and \(\Sigma_2 = \mathrm{diag}(4, 1)\). What is the fused (product) covariance?
    精度相加:\(\Sigma^{-1} = \mathrm{diag}(1, 0.25) + \mathrm{diag}(0.25, 1) = \mathrm{diag}(1.25, 1.25)\),所以 \(\Sigma = \mathrm{diag}(0.8, 0.8)\),比任一输入都小,且每个方向都比两者中较好的那个还准。Precisions add: \(\Sigma^{-1} = \mathrm{diag}(1, 0.25) + \mathrm{diag}(0.25, 1) = \mathrm{diag}(1.25, 1.25)\), so \(\Sigma = \mathrm{diag}(0.8, 0.8)\): smaller than both inputs, and in every direction better than even the better of the two.
    5. \(\Sigma = \mathrm{diag}(4, 1)\),均值在原点。点 \(\mathbf p = (2, 0)\) 与点 \(\mathbf q = (0, 1.5)\),哪个相对于这个高斯更"反常"?5. \(\Sigma = \mathrm{diag}(4, 1)\) with mean at the origin. Which of \(\mathbf p = (2, 0)\) and \(\mathbf q = (0, 1.5)\) is more "unusual" for this Gaussian?
    \(d_M(\mathbf p)^2 = 2^2/4 = 1\),\(d_M(\mathbf q)^2 = 1.5^2/1 = 2.25\)。\(x\) 方向的标准差是 2,偏 2 才只有 1σ;\(y\) 方向的标准差是 1,偏 1.5 就是 1.5σ。\(d_M(\mathbf p)^2 = 2^2/4 = 1\), \(d_M(\mathbf q)^2 = 1.5^2/1 = 2.25\). The \(x\) direction has std 2, so being off by 2 is only 1σ; the \(y\) direction has std 1, so 1.5 off is 1.5σ.

    9延伸阅读Further reading

    • C. M. Bishop, Pattern Recognition and Machine Learning, Springer, 2006, Sec. 2.3 — 多元高斯的几何、条件与边缘分布、乘积,本节公式在这里有完整推导Geometry of the multivariate Gaussian, conditionals, marginals and products: full derivations of this lesson's formulas
    • S. Thrun, W. Burgard & D. Fox, Probabilistic Robotics, MIT Press, 2005, Sec. 3.2 — 高斯信念与矩参数化 / 规范参数化Gaussian beliefs and the moments / canonical parameterizations
    • T. D. Barfoot, State Estimation for Robotics, Cambridge University Press, 2017, Sec. 2.2 — 高斯概率密度、联合/条件/边缘、乘积与归一化Gaussian PDFs, joint / conditional / marginal, products and normalization
    • 3Blue1Brown, But what is the Central Limit Theorem? (video) — 用动画解释为什么叠加会得到钟形An animated explanation of why adding things gives a bell
    • R. Labbe, Kalman and Bayesian Filters in Python, Ch. 4 — 高斯分布与它们的乘积,配可运行代码Gaussians and their products with runnable code