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

贝叶斯滤波The Bayes Filter

机器人看不到自己的真实状态,只能一边动、一边看。贝叶斯滤波 (Bayes filter) 用一个概率分布表示"我可能在哪",然后反复做两件事:预测(动作把分布挪开、抹宽)和更新(传感器读数乘上去、再归一化)。卡尔曼滤波、粒子滤波,都只是这套递推在不同"信念表示"下的具体实现。 A robot cannot see its true state; it can only move and look, move and look. The Bayes filter keeps a probability distribution for "where I might be" and repeats two steps: predict (an action shifts and smears the distribution) and update (multiply by the sensor reading, then normalize). The Kalman filter and the particle filter are just this recursion implemented with different ways of representing the belief.

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

    一台机器人被放进一条很长的走廊,走廊里有几扇门,它手里有一张写着门位置的地图,但不知道自己在哪一格。它能做的只有两件事:向前或向后走(走得不一定准:轮子打滑,可能少走或多走一格),以及看一眼(传感器说"我面前是扇门",但这个传感器也会看错)。

    怎么办?如果只相信一次读数,一次错误就毁掉一切。如果只相信里程计,误差会无限累积。更好的办法是:别急着下结论,把每个位置的可信程度都记下来,每走一步、每看一眼就把这份"可信程度表"更新一遍。这张表就是信念 (belief),更新它的规则就是贝叶斯滤波。

    它是整个状态估计的母体。4.8 节的卡尔曼滤波是它在"高斯、线性"假设下的精确闭式解,4.10 节的粒子滤波是它用一堆随机样本做的近似,SLAM、视觉里程计、机器人定位里的"滤波"类方法,都建立在这同一条递推上。

    A robot is placed in a long corridor with several doors. It has a map saying where the doors are, but it does not know which cell it is in. It can only do two things: move forward or backward (imperfectly: wheels slip and it may undershoot or overshoot by a cell) and look (the sensor says "I'm facing a door", but this sensor can be wrong too).

    What to do? Trusting a single reading lets one mistake ruin everything. Trusting only odometry lets errors accumulate without bound. A better way: do not jump to a conclusion; write down how plausible every position is, and update this "plausibility table" after every move and every look. That table is the belief, and the rule that updates it is the Bayes filter.

    It is the parent of all state estimation. The Kalman filter of Lesson 4.8 is its exact closed form under "Gaussian, linear" assumptions; the particle filter of Lesson 4.10 approximates it with a cloud of random samples; the filtering methods in SLAM, visual odometry and robot localization all sit on this one recursion.

    2直觉:一排柱子,先挪动、再相乘Intuition: a row of bars, first shift, then multiply

    把走廊切成 20 格,给每格一根柱子,柱子的高度就是"我在这一格的概率"。开始时一无所知:20 根柱子一样高(均匀分布)。

    • 预测 (predict):机器人下令"向右走一格"。每根柱子里的概率大部分挪到右边一格,一小部分留在原地(少走),一小部分跑到右边两格(多走)。整个柱状图向右平移,同时被抹平:不确定性变大了。
    • 更新 (update):传感器说"看到一扇门"。对每个格子问:如果我在这里,看到门的可能性有多大?在门前这个数大(比如 0.8),在墙前这个数小(0.2)。把每根柱子乘以自己的数,再让所有柱子的总和重新等于 1(归一化)。门前的柱子长高,墙前的柱子变矮:不确定性变小了。

    下面是这套规则的实验台。注意走廊里有几处"长得一模一样"的局部(比如"门·墙·门"出现了两次):一次读数分不清我在哪一处,信念于是出现多个峰。只有多走几步、多看几眼,才能排除。

    Cut the corridor into 20 cells and give each cell a bar whose height is "the probability that I am in this cell". At the start we know nothing: 20 equal bars (a uniform distribution).

    • Predict: the robot is told to "move one cell right". Most of each bar's probability slides one cell to the right, a little stays put (undershoot), a little jumps two cells (overshoot). The whole histogram shifts right and gets smeared: uncertainty grows.
    • Update: the sensor says "I see a door". For each cell ask: if I were here, how likely is it that I'd see a door? That number is large in front of a door (say 0.8) and small in front of a wall (0.2). Multiply every bar by its number, then rescale so that all bars sum to 1 again (normalize). Bars in front of doors grow, bars in front of walls shrink: uncertainty drops.

    Below is the test bench. Notice that the corridor has places that "look identical" (the pattern "door·wall·door" appears twice). One reading cannot tell which one I am at, so the belief gets several peaks. Only by moving and looking more can the extra peaks be ruled out.

    FIG 1走廊里的直方图滤波器A histogram filter in a corridor
    上方是走廊:蓝色方块是门,圆点机器人是真实位置(滤波器不知道,可以拖动它来"绑架"机器人)。下方柱子是信念:青色 = 刚预测完,黄色 = 刚更新完,灰色轮廓 = 上一步的信念。紫色小条是上一次读数给每格的似然 p(z | x)。按"左移 / 右移"做预测,按"感知"做更新。 The top strip is the corridor: blue blocks are doors and the dot is the robot's true position (which the filter does not know; drag it to "kidnap" the robot). The bars below are the belief: cyan = just predicted, amber = just updated, grey outline = the previous belief. The small purple bars are the likelihood p(z | x) that the last reading assigned to each cell. Press "Left / Right" to predict and "Sense" to update.
    试一试Try this
    • 歧义:重置后点一次"感知":信念出现好几个一样高、相距 5 格以上的峰(读到"门"时最明显:5 扇门各一个)。一次读数分不清是哪一处。Ambiguity: after a reset press "Sense" once: the belief gets several equally tall peaks at least 5 cells apart (clearest on a "door" reading: one per door). One reading cannot tell which place it is.
    • 定位成功:通过移动和感知,让真实位置那一格的概率超过 0.9。需要几步?Localize: by moving and sensing, get the probability of the true cell above 0.9. How many steps did it take?
    • 绑架机器人:定位成功后把机器人拖到 5 格以外,然后连续"感知"。滤波器多久才醒悟?(提示:它可能永远不会。)Kidnap the robot: after localizing, drag it 5+ cells away and keep pressing "Sense". How long before the filter wakes up? (Hint: it may never.)
    核心洞见Key insight

    动作让你更糊涂,观测让你更清楚。预测把分布抹开(在开阔处熵增加;例外是边界:撞到尽头的墙会把概率堆在一起,见 FIG 3),更新把它压尖(平均而言熵减少)。滤波器的工作就是在这两股力量之间保持诚实:既不假装知道得比实际多,也不把已经知道的东西忘掉。注意"归一化"不是装饰:没有它,相乘之后柱子的总和就不再是 1,也就不再是概率。

    Actions make you more confused, observations make you less. Predict smears the distribution (entropy goes up in open space; the exception is a boundary: driving into the end wall piles the mass up, see FIG 3); update sharpens it (entropy goes down, on average). The filter's job is to stay honest between these two forces: never pretend to know more than it does, never forget what it already knows. Normalization is not decoration: without it the bars no longer sum to 1 after the multiplication, so they stop being probabilities.

    3动手玩:同一条递推,三种信念表示Play: one recursion, three ways to represent the belief

    走廊是离散的,所以我们可以用 20 根柱子精确地做。如果位置是连续的(比如 0 到 12 米的一维轨道)呢?同一条递推可以用三种方式实现:

    • 细网格(直方图):把轨道切成 240 个小格,当作很多根很细的柱子。这是"几乎精确"的参照答案。
    • 一个高斯:只记均值和方差。当运动和测量都是线性高斯时,这就是卡尔曼滤波 (4.8),并且和网格的结果完全一致。
    • 一堆粒子:撒 400 个随机样本,预测时每个样本自己走一步(带噪声),更新时按似然重新抽样 (4.10)。

    用 GPS 式的传感器(读数 = 位置 + 高斯噪声)时,三者几乎重合。把传感器换成"门探测器"(只在门附近报"门"),似然是多峰的,高斯就无能为力了。

    The corridor was discrete, so 20 bars did the job exactly. What if position is continuous (say a 1-D track from 0 to 12 m)? The same recursion can be implemented in three ways:

    • A fine grid (histogram): cut the track into 240 small cells, like many thin bars. This is the "nearly exact" reference answer.
    • A single Gaussian: keep only mean and variance. When motion and measurement are linear-Gaussian this is the Kalman filter (4.8), and it agrees with the grid exactly.
    • A bag of particles: scatter 400 random samples; on predict each sample takes its own noisy step, on update the samples are redrawn in proportion to the likelihood (4.10).

    With a GPS-like sensor (reading = position + Gaussian noise) the three nearly coincide. Switch to a "door detector" (reports "door" only near doors) and the likelihood has several peaks, where a single Gaussian is helpless.

    FIG 2三种信念表示:网格、高斯、粒子Three belief representations: grid, Gaussian, particles
    黄色填充 = 细网格上的精确信念;青色曲线 = 高斯(GPS 模式下是真正的卡尔曼滤波,门模式下是"均值与方差相同的最佳单个高斯");紫色折线与刻度 = 400 个粒子的直方图;灰色虚线 = 真实位置。每次"右移 / 左移"走 1.5 m(噪声 0.35 m),"感知"做一次测量。 Amber fill = the exact belief on the fine grid; cyan curve = the Gaussian (a genuine Kalman filter in GPS mode; in door mode, "the best single Gaussian with the same mean and variance"); purple line and ticks = the histogram of 400 particles; dashed grey = the true position. Each "Right / Left" moves 1.5 m (noise 0.35 m); "Sense" takes one measurement.
    试一试Try this
    • GPS 模式下交替移动与感知至少 3 次:看右边读数,卡尔曼高斯与网格的总变差距离应小于 0.02。卡尔曼滤波就是贝叶斯滤波。In GPS mode alternate move and sense at least 3 times: the readout should show a total-variation distance below 0.02 between the Kalman Gaussian and the grid. The Kalman filter is the Bayes filter.
    • 切到门探测器,点「感知」直到读到「门」(读到「墙」就重置再试):精确信念有三个峰,最佳单个高斯却把质量堆在两扇门之间的空地上(两者的总变差距离大于 0.3)。Switch to the door detector and press Sense until it reads “door” (on “wall”, reset and retry): the exact belief has three peaks, while the best single Gaussian piles its mass in the empty space between doors (total-variation distance above 0.3).

    4再看数学The math

    提示:悬停下面公式中带底色的符号,FIG 1 中对应的部分会高亮(预测后的信念 \(\mathrm{bel}^-\)、更新后的信念 \(\mathrm{bel}\)、似然条、运动模型的转移概率);FIG 2 中精确信念对应 \(\mathrm{bel}\)。Tip: hover the shaded symbols below and the matching part of FIG 1 lights up (the predicted belief \(\mathrm{bel}^-\), the updated belief \(\mathrm{bel}\), the likelihood strip, the motion model's transition probabilities); in FIG 2 the exact belief lights up for \(\mathrm{bel}\).

    信念与两条假设The belief and two assumptions

    记 \(x_k\) 为 \(k\) 时刻的状态,\(u_k\) 为控制,\(z_k\) 为测量。信念是"已知到目前为止所有控制和测量时,状态的分布",更新前的那一版(只用到 \(k-1\) 时刻的测量)记作 \(\mathrm{bel}^-\):

    Let \(x_k\) be the state at time \(k\), \(u_k\) the control and \(z_k\) the measurement. The belief is "the distribution of the state given everything so far"; the version before the update (using measurements only up to \(k-1\)) is written \(\mathrm{bel}^-\):

    $$ \mathrm{bel}(x_k) = p(x_k \mid z_{1:k},\,u_{1:k}),\qquad \mathrm{bel}^-(x_k) = p(x_k \mid z_{1:k-1},\,u_{1:k}). $$

    递推能成立,靠的是马尔可夫假设:状态是"完备"的,即只要知道当前状态,过去就不再提供额外信息。

    The recursion works thanks to the Markov assumption: the state is "complete", i.e. once the current state is known the past adds no further information.

    $$ p(x_k \mid x_{0:k-1},\,z_{1:k-1},\,u_{1:k}) = \hl{motion}{p(x_k \mid x_{k-1},\,u_k)},\qquad p(z_k \mid x_{0:k},\,z_{1:k-1},\,u_{1:k}) = \hl{sensor}{p(z_k \mid x_k)}. $$

    两个因子分别叫运动模型和传感器模型 (观测模型)。它们是你在做滤波之前要从物理和标定中得到的全部输入。

    The two factors are the motion model and the sensor (observation) model. They are all the inputs you must supply from physics and calibration before filtering.

    递推:预测与更新The recursion: predict and update

    预测用全概率公式:下一个状态可以从任何一个旧状态来,按"旧状态有多可信 × 转移概率"加权求和。更新用贝叶斯公式(4.2 节):后验 ∝ 似然 × 先验。

    Predict uses the law of total probability: the next state can come from any old state, weighted by "how plausible the old state was × the transition probability". Update uses Bayes' rule (Lesson 4.2): posterior ∝ likelihood × prior.

    $$ \hl{prior}{\mathrm{bel}^-(x_k)} = \int \hl{motion}{p(x_k \mid x_{k-1},\,u_k)}\;\hl{post}{\mathrm{bel}(x_{k-1})}\;dx_{k-1} \qquad\text{(predict)} $$ $$ \hl{post}{\mathrm{bel}(x_k)} = \eta\;\hl{sensor}{p(z_k \mid x_k)}\;\hl{prior}{\mathrm{bel}^-(x_k)}, \qquad \eta = \frac{1}{p(z_k\mid z_{1:k-1},u_{1:k})} \qquad\text{(update)} $$

    \(\eta\) 只是让总和为 1 的归一化常数,它还有一个含义:这个读数在滤波器看来有多"意外"(\(\eta\) 越大,读数越出乎意料)。在连续状态下积分,在离散状态下就是求和。

    \(\eta\) is just the normalizing constant that makes the total 1, but it has a second meaning: how surprising this reading was to the filter (a larger \(\eta\) means a more unexpected reading). Over continuous states it is an integral; over discrete states it is a sum.

    离散情形就是矩阵乘法The discrete case is matrix multiplication

    把信念写成列向量 \(\mathbf b\)(\(N\) 个格子)。转移矩阵 \(T\) 的第 \((j,i)\) 项是"从格 \(i\) 走到格 \(j\) 的概率",每一列的和为 1。设 \(\boldsymbol\ell\) 的第 \(j\) 项是 \(p(z_k\mid x_k = j)\)。于是

    Write the belief as a column vector \(\mathbf b\) of \(N\) cells. In the transition matrix \(T\), entry \((j,i)\) is "the probability of going from cell \(i\) to cell \(j\)", and every column sums to 1. Let entry \(j\) of \(\boldsymbol\ell\) be \(p(z_k\mid x_k = j)\). Then

    $$ \mathbf b^- = T\,\mathbf b,\qquad \mathbf b^{\text{new}} = \frac{\operatorname{diag}(\boldsymbol\ell)\,\mathbf b^-}{\mathbf 1^\top \operatorname{diag}(\boldsymbol\ell)\,\mathbf b^-}. $$

    预测是一次矩阵乘(1.4 节:把"分布"当向量,让转移矩阵作用在上面),更新是逐元素相乘再归一化。FIG 1 里右移一格的 \(T\) 近似为:对角线上方一条 0.8 的带,两侧各有一条 0.1 的带,边界处被墙截断后把超出去的概率累加到最后一格。

    Predict is one matrix multiplication (Lesson 1.4: treat the distribution as a vector and let the transition matrix act on it); update is an element-wise product followed by normalization. In FIG 1, \(T\) for "move right one cell" is roughly a band of 0.8 on the shifted diagonal with bands of 0.1 on either side, and mass that would leave the corridor piles up in the last cell.

    算一遍:三个格子Worked example: three cells

    先验 \(\mathbf b^-=(0.5,\,0.3,\,0.2)\),读数的似然 \(\boldsymbol\ell=(0.9,\,0.1,\,0.5)\)。逐项相乘得 \((0.45,\,0.03,\,0.10)\),总和 \(0.58\),所以 \(\eta = 1/0.58\),后验 \(=(0.776,\,0.052,\,0.172)\)。第 1 格从 0.5 涨到 0.78,第 2 格从 0.3 跌到 0.05:读数"投票"支持了第 1 格。

    Prior \(\mathbf b^-=(0.5,\,0.3,\,0.2)\), likelihood \(\boldsymbol\ell=(0.9,\,0.1,\,0.5)\). Multiplying element by element gives \((0.45,\,0.03,\,0.10)\) with sum \(0.58\), so \(\eta = 1/0.58\) and the posterior is \((0.776,\,0.052,\,0.172)\). Cell 1 rises from 0.5 to 0.78, cell 2 drops from 0.3 to 0.05: the reading "voted" for cell 1.

    一个骨架,三个肌肉One skeleton, three bodies

    信念表示Belief representation预测Predict更新Update代价与限制Cost and limits
    直方图 / 网格 (本节)Histogram / grid (this lesson)卷积或矩阵乘 \(T\mathbf b\)convolution or matrix product \(T\mathbf b\)逐格相乘,归一化per-cell product, normalize任意形状的信念;格子数随维度指数增长any belief shape; cells grow exponentially with dimension
    高斯 (4.8 卡尔曼 / EKF)Gaussian (4.8 Kalman / EKF)\(F P F^\top + Q\)\(K = P^-H^\top S^{-1}\)极快、极省;只能表示单峰,需要线性(或线性化)very fast and compact; unimodal only, needs (local) linearity
    粒子 (4.10)Particles (4.10)每个粒子按运动模型采样sample each particle from the motion model按似然加权,重采样weight by likelihood, resample任意形状;精度随粒子数增长,维度高时需要大量粒子any shape; accuracy grows with the particle count, many needed in high dimensions

    5机器人中的它:下一步该往哪走?In robotics: where should I go next?

    有了信念,机器人就能做一件聪明的事:挑一个能最大程度消除歧义的动作,而不是漫无目的地走。这叫主动定位 (active localization)。

    怎么评估一个动作好不好?对每个候选动作"走 k 格再看一眼",机器人可以在脑中推演:先用预测步算出走完后的信念,再对两种可能的读数(门 / 墙)分别算出更新后的熵,按各自出现的概率加权,得到期望的后验熵。熵下降得越多(信息增益,4.11 节会详细讲熵),这个动作越值得做。

    FIG 3 里机器人刚在歧义的走廊里看到一扇门。柱子代表每个动作的信息增益(单位:比特);点一根柱子选择动作,按"执行"真正走一步并感知。

    With a belief in hand the robot can do something clever: pick the action that best resolves the ambiguity instead of wandering. This is called active localization.

    How to rate an action? For each candidate "move k cells, then look once", the robot can rehearse in its head: use the predict step to get the belief after the move, then for each of the two possible readings (door / wall) compute the entropy after the update, and weight them by how likely each reading is. The result is the expected posterior entropy. The more the entropy drops (the information gain; entropy is the topic of Lesson 4.11), the more the action is worth.

    In FIG 3 the robot has just seen a door in the ambiguous corridor. Each bar is the information gain of one action, in bits; click a bar to choose an action, press "Execute" to really move and sense.

    FIG 3主动定位:按期望信息增益选动作Active localization: choose by expected information gain
    上半部分:走廊、当前信念(黄)与真实位置(点)。下半部分:每个"移动 k 格"(k 为负表示向左)的期望信息增益 \(H(\mathrm{bel}) - \mathbb E_z[H(\mathrm{bel}\mid z)]\),单位比特;绿色是最优动作,紫色边框是你选中的动作。传感器正确率 0.9,运动准确率 0.9。注意朝走廊尽头的墙开过去往往信息量最大:墙会把机器人拦住,位置反而变得确定。 Top: the corridor, the current belief (amber) and the true position (dot). Bottom: the expected information gain \(H(\mathrm{bel}) - \mathbb E_z[H(\mathrm{bel}\mid z)]\), in bits, of each "move k cells" (negative k means left); green is the best action, a purple outline marks your selection. Sensor accuracy 0.9, motion accuracy 0.9. Driving toward the end wall is often the most informative move: the wall stops the robot, so its position becomes certain.
    试一试Try this
    • 只用"执行最优动作",让真实位置的概率超过 0.9。一般要几步?再重置,改成总选"原地不动 (k = 0)",比较一下。Using only "Execute best", get the true cell's probability above 0.9. How many steps does it usually take? Then reset and always pick "stay (k = 0)" instead, and compare.
    真实系统里In real systems

    室内的 AMCL(自适应蒙特卡洛定位,ROS 导航栈里的标准定位器)本质上就是一个跑在二维地图上的贝叶斯滤波:状态是 \((x,y,\theta)\),运动模型来自里程计,观测模型来自激光对地图的匹配。主动定位和"信息增益驱动的探索"是它的延伸:下一个观测点选在最能消除歧义(或最能揭开未知区域)的地方。仓库里的 AGV 靠门、货架这类重复结构,常常遇到本节演示的"感知混淆 (perceptual aliasing)"。

    Indoor AMCL (adaptive Monte Carlo localization, the standard localizer in the ROS navigation stack) is at heart a Bayes filter over a 2D map: the state is \((x,y,\theta)\), the motion model comes from odometry, the observation model from matching lasers against the map. Active localization and "information-gain-driven exploration" extend it: pick the next viewpoint where it best resolves ambiguity (or best reveals unknown areas). Warehouse AGVs surrounded by repeated structure such as doors and shelves meet exactly the "perceptual aliasing" demonstrated here.

    6常见误区Common pitfalls

    误区 1:把概率写成 0Pitfall 1: writing a probability as exactly 0

    贝叶斯更新是乘法:0 乘什么都是 0,而且永远救不回来。如果某格的信念被压成 0,哪怕机器人其实就在那里,后面再多的读数也无法让它复活。FIG 1 里"绑架"机器人就是这个现象:旧信念几乎把真实位置排除了。工程上的办法是给每格留一点底噪(比如运动模型里加一点点均匀的概率,传感器似然不低于 0.01),也就是"永远不要说永远不"。

    Bayes' update is a multiplication: 0 times anything is 0, and it can never be revived. If a cell's belief is crushed to 0, no later reading can bring it back even if the robot really is there. Kidnapping the robot in FIG 1 shows this: the old belief all but ruled out the true position. The engineering fix is a small floor for every cell (a little uniform mass in the motion model, sensor likelihoods never below ~0.01): "never say never".

    误区 2:过早取最大值Pitfall 2: taking the argmax too early

    信念有两个同样高的峰时,"取概率最大的格子"只是随机挑一个,一半概率是错的。只在信念已经集中(比如最大值超过 0.9,或熵很低)时才把它当成"位置估计",否则要把整个分布交给下游(规划器可以选择先观察再行动)。

    When the belief has two equally tall peaks, "take the most probable cell" just flips a coin, and half of the time it is wrong. Only treat the belief as a "position estimate" once it has concentrated (say the maximum exceeds 0.9, or the entropy is low); otherwise hand the whole distribution downstream (a planner can decide to observe before acting).

    误区 3:状态不完备,却假装马尔可夫Pitfall 3: a state that is not complete, treated as Markov

    递推依赖"知道当前状态就够了"。如果漏掉了一个会持续影响读数的量(比如陀螺仪的零偏、地图里移动的行人),连续的读数就不再相互独立,滤波器会把同一份信息数了好几次,越来越过度自信。解决办法是把这个量也放进状态里(如 4.8 节的"状态扩维")。

    The recursion relies on "the current state is enough". If you leave out a quantity that keeps influencing the readings (a gyroscope bias, a walking pedestrian on the map), successive readings stop being independent and the filter counts the same information several times, growing overconfident. The cure is to put that quantity into the state (state augmentation, as in Lesson 4.8).

    误区 4:忘了维度灾难Pitfall 4: forgetting the curse of dimensionality

    20 格的走廊没问题。可是平面位姿 \((x,y,\theta)\),每个方向 100 格就是 \(10^6\) 格以上,每次预测还要对每格做卷积;三维位姿加速度就更不用说了。网格滤波只适合低维问题,维度高了就要换成高斯(4.8)或粒子(4.10)。

    A 20-cell corridor is easy. But a planar pose \((x,y,\theta)\) with 100 bins per axis is over \(10^6\) cells, and each predict needs a convolution per cell; a 3D pose with velocities is out of the question. Grid filters suit low-dimensional problems only; in higher dimensions switch to Gaussians (4.8) or particles (4.10).

    误区 5:数值下溢Pitfall 5: numerical underflow

    似然往往是很小的数,连乘几百次就会下溢成 0(然后触发误区 1)。实践里要么每次更新都归一化,要么在对数域里做加法,归一化时用 log-sum-exp 技巧。

    Likelihoods are often tiny, and hundreds of multiplications underflow to 0 (which triggers Pitfall 1). In practice normalize at every update, or work in the log domain with additions and use the log-sum-exp trick when normalizing.

    7小练习Check yourself

    1. 贝叶斯滤波的两步对信念的熵(不确定性)分别有什么影响?1. How do the two steps of the Bayes filter affect the belief's entropy (uncertainty)?
    运动带噪声,预测相当于把分布与噪声核卷积,在开阔处总是更宽(边界例外:墙会把越界的概率堆在最后一格,FIG 3 正是利用这一点);观测带来信息,更新平均而言让分布更尖。"平均"二字不能省:遇到一个极出乎意料的读数,单次更新也可能让熵上升。Motion is noisy, so predict convolves the distribution with a noise kernel and, in open space, always widens it (boundaries are the exception: a wall piles the overflowing mass into the last cell, which FIG 3 exploits); observations carry information, so update sharpens it on average. "On average" matters: after a very surprising reading a single update can even raise the entropy.
    2. 先验 \((0.5,\,0.3,\,0.2)\),似然 \((0.9,\,0.1,\,0.5)\),归一化后的后验是?2. Prior \((0.5,\,0.3,\,0.2)\), likelihood \((0.9,\,0.1,\,0.5)\). What is the normalized posterior?
    逐项相乘得 (0.45, 0.03, 0.10),这还不是概率(总和 0.58)。除以 0.58 才是后验:(0.776, 0.052, 0.172)。第一个选项忘了归一化。The element-wise product is (0.45, 0.03, 0.10), which is not yet a distribution (sum 0.58). Dividing by 0.58 gives the posterior (0.776, 0.052, 0.172). The first option forgot to normalize.
    3. 机器人的信念在真实位置那一格是 0(它被"绑架"到了那里)。继续做贝叶斯滤波,会怎样?3. The robot's belief is exactly 0 at its true cell (it was "kidnapped" there). What happens if it keeps running the Bayes filter?
    更新是乘法,0 × 任何数 = 0,归一化也救不回来。预测步骤只会把邻居的一点概率抹过来,如果邻居也接近 0,就几乎没有。所以真实系统要给信念设置下限,或者主动注入随机假设(4.10 节的做法)。The update is a product, 0 × anything = 0, and normalization cannot revive it. The predict step only smears some mass over from neighbours, and if they are also near 0 there is almost none. Real systems therefore put a floor under the belief or inject random hypotheses (the approach in Lesson 4.10).
    4. 为什么对 \((x,y,\theta)\) 三维位姿,通常不用 FIG 1 那样的网格滤波,而用卡尔曼或粒子滤波?4. Why is the grid filter of FIG 1 usually not used for a 3D pose \((x,y,\theta)\), with Kalman or particle filters preferred?
    网格滤波对任意形状的信念、任意噪声都成立,而且能表示多峰,缺点只有一个:维度灾难。每个方向 100 格,三维就是 \(10^6\) 格。The grid filter works for any belief shape and any noise, and handles multimodal beliefs; its one weakness is the curse of dimensionality. With 100 bins per axis, three dimensions already mean \(10^6\) cells.

    8延伸阅读Further reading

    • S. Thrun, W. Burgard & D. Fox, Probabilistic Robotics, MIT Press, 2005, Ch. 2 & 4 — 贝叶斯滤波的推导与离散(直方图)滤波;第 7 章讲马尔可夫定位derivation of the Bayes filter and the discrete (histogram) filter; Ch. 7 covers Markov localization
    • T. D. Barfoot, State Estimation for Robotics, Cambridge University Press, 2017, Ch. 4 — 非线性、非高斯估计:贝叶斯滤波作为统一框架nonlinear non-Gaussian estimation, with the Bayes filter as the unifying framework
    • D. Fox, W. Burgard & S. Thrun, "Markov Localization for Mobile Robots in Dynamic Environments", Journal of Artificial Intelligence Research, 1999 — 本节走廊例子的原型:机器人定位上的网格贝叶斯滤波the ancestor of this lesson's corridor example: grid-based Bayes filtering for robot localization
    • S. Russell & P. Norvig, Artificial Intelligence: A Modern Approach, the chapter on probabilistic reasoning over time — 滤波、预测、平滑的统一视角filtering, prediction and smoothing from a unified viewpoint
    • R. Labbe, Kalman and Bayesian Filters in Python — 免费交互式教材,第 2 章用"走廊里的狗"讲离散贝叶斯滤波a free interactive book; its early chapters introduce the discrete Bayes filter with a dog in a hallway