Probability for Robotics · Theory · M3
M3-T4 — Recursive Bayesian Updating
Today’s posterior is tomorrow’s prior. In log odds, each reading simply adds a fixed amount of evidence.
A robot does not receive its readings in a batch. They arrive one at a time, and it must act after each. This lesson shows how to fold in one reading at a time without ever going back to the old data, why the order of independent readings does not matter, and why a change of variable to odds and log odds turns the whole update into an addition. That addition is the occupancy grid update, the fault-detection test and the weight of evidence used throughout robotics.
Learning objectives
After this lesson, you should be able to:
- Update a belief recursively, using each posterior as the prior for the next reading, and show that this equals a batch update.
- Convert between probability, odds and log odds, and compute the evidence of a reading as a likelihood ratio.
- Derive the odds and log-odds forms of the update and use them to track a belief over a sequence of readings.
- Explain why the belief must be clamped, and recognise the bugs of re-applying the prior and of treating a changing state as static.
The intuition
Recall the marker detector of the last lesson: it fires with probability 0.8 when the marker is in view and 0.1 when it is not, and the marker is in view on 5% of the corridor frames. One detection raised the belief from 0.05 to 0.30. What should happen on the next frame?
The robot does not start from scratch. After the first frame its belief is 0.30, and that is now its prior for the second frame: what it believed before seeing the new reading. It applies Bayes' rule again, with 0.30 as the prior. If the second frame also fires, the belief becomes 0.77. A miss then lowers it to 0.43; two more detections raise it to 0.86 and 0.98. This is recursive Bayesian updating: the posterior of one step is the prior of the next, so the robot only has to remember its current belief, not the whole history of readings.
The two panels show the same belief, and the right-hand one is simpler. A detection always adds the same amount of evidence, whatever the robot already believes, and a miss always subtracts a smaller fixed amount. The left-hand curve moves by 0.25 on the first detection and by only 0.12 on the last, because probabilities get crowded near 1; in log odds the steps are all equal. A practical consequence follows: to update a belief, a robot can just add a number to a stored value, with no division or normalization.
Odds and log odds
Betting people use odds: 1 to 19 against means a probability of 0.05. The odds of a probability are , and the log odds (also called the logit) are their natural logarithm. The mapping is one to one, and it stretches the unit interval onto the whole number line: probability 0.5 is log odds 0, probabilities near 1 are large positive numbers, and probabilities near 0 are large negative numbers.
Why does the update become an addition? Bayes' rule says posterior ∝ prior × likelihood. Taking odds divides out the common normalizer, and taking logarithms turns the multiplication into a sum. The evidence a reading carries is its likelihood ratio, the probability of the reading if the hypothesis is true divided by its probability if it is false: 0.8 / 0.1 = 8 for a detection, 0.2 / 0.9 = 0.22 for a miss. In log units, +2.08 and −1.50.
In log odds a belief is a running total. Every independent reading adds its own weight of evidence, positive for evidence in favour, negative against, and the order in which they arrive does not matter.
Definitions
- Belief
- The robot’s probability for each state after the readings : .
- Odds
- : how many times more likely the hypothesis is than its opposite.
- Log odds
- (also logit). Probability is recovered by (the logistic function).
- Likelihood ratio
- : the factor by which a reading multiplies the odds.
- Weight of evidence
- : the amount a reading adds to the log odds.
- Static state
- A state that does not change while the readings arrive. The updates of this lesson assume it; module 6 adds the prediction step for a state that moves.
Derivation: the recursion, the odds form and the log-odds sum
The recursion
Bayes’ rule with all the earlier readings carried along as background knowledge: the “prior” is now what we believed after those readings.
The assumption. Given the state, the new reading does not depend on the old ones: conditional independence of the readings (the last lesson). For a static state this is the sensor model.
Name the old posterior . The denominator does not depend on and is found by normalizing.
Unroll the recursion. It gives the batch formula of the last lesson, so processing readings one at a time loses nothing.
For a static state, the order of independent readings is irrelevant.
Odds and log odds
Write the recursion for and for its complement and divide one by the other.
The normalizer is the same in both and cancels. No normalization is needed in this form.
The logarithm turns the product into a sum: the log-odds update.
Unroll: the final log odds are the prior log odds plus the total weight of evidence, with no dependence on the order of the readings.
Converting back: the logistic function.
Why a stored log odds must be bounded
The log-odds sum has no ceiling: ten detections give , a probability within of 1. Evidence is only worth as much as the assumptions under it. If the marker then leaves the view, each miss subtracts only 1.50, and the belief needs twelve misses to fall below ½. A cap limits how far the belief can run ahead of the assumptions, and bounds the number of contrary readings needed to change its mind to .
Evidence adds in log odds. The belief is the prior plus the sum of the weights of evidence of all the readings, in any order. A cap on the sum is what keeps a belief able to change.
A worked example
Rover drives down the corridor looking for the dock marker. The prior probability that the marker is in view is 0.05 (log odds −2.944), the detector has and , and the five frames give: detect, detect, miss, detect, detect.
- Weights of evidence. A detection: . A miss: .
- Frame by frame. Log odds: −2.944 → −0.865 → 1.214 → −0.290 → 1.790 → 3.869. Probabilities: 0.05 → 0.296 → 0.771 → 0.428 → 0.857 → 0.980. Entropy of the belief, a measure of how undecided it is, rises while the belief is near ½ (0.985 bits after the miss) and falls to 0.144 bits at the end.
- Check the first step against the last lesson: 0.05 → 0.296 is the same posterior computed there with Bayes’ rule directly.
- Batch equals recursive. The batch posterior odds are prior odds times the product of all five likelihood ratios: , so . Processing the five frames in the reverse order also gives 0.9796.
- Clamping. After ten detections in a row, an uncapped belief needs 12 consecutive misses to drop below ½ if the marker disappears. A belief capped at log odds ±3 (probability 0.953) needs only 2.
import math
from robotprob import logit, inv_logit, entropy
d, f = 0.8, 0.1
lr_detect = math.log(d / f) # weight of evidence of a detection, in nats
lr_miss = math.log((1 - d) / (1 - f)) # weight of evidence of a non-detection
print('evidence per detection =', round(lr_detect, 4), ' per miss =', round(lr_miss, 4))
seq = ['detect', 'detect', 'miss', 'detect', 'detect']
l = logit(0.05) # prior log odds
print('start: log odds', round(l, 3), ' p =', round(inv_logit(l), 4), ' entropy =', round(entropy([0.05, 0.95]), 3), 'bits')
for i, s in enumerate(seq, 1):
l += lr_detect if s == 'detect' else lr_miss # the whole update is an addition
p = inv_logit(l)
print(i, s.ljust(6), 'log odds', round(l, 3), ' p =', round(p, 4), ' entropy =', round(entropy([p, 1 - p]), 3), 'bits')
l2 = logit(0.05)
for s in reversed(seq): # the same readings in the opposite order
l2 += lr_detect if s == 'detect' else lr_miss
print('same final belief in any order:', abs(l - l2) < 1e-12)
batch = 0.05 / 0.95 * (d / f) ** 4 * ((1 - d) / (1 - f)) # batch posterior odds
print('batch posterior =', round(batch / (1 + batch), 4))
def misses_to_forget(l_max): # ten detections, then the marker disappears
l = logit(0.05)
for _ in range(10):
l = min(l + lr_detect, l_max)
k = 0
while inv_logit(l) >= 0.5:
l = max(l + lr_miss, -l_max)
k += 1
return k
print('misses needed to doubt the marker after 10 detections: no clamp', misses_to_forget(1e9), ' clamp at 3:', misses_to_forget(3.0))evidence per detection = 2.0794 per miss = -1.5041 start: log odds -2.944 p = 0.05 entropy = 0.286 bits 1 detect log odds -0.865 p = 0.2963 entropy = 0.877 bits 2 detect log odds 1.214 p = 0.7711 entropy = 0.776 bits 3 miss log odds -0.29 p = 0.4281 entropy = 0.985 bits 4 detect log odds 1.79 p = 0.8569 entropy = 0.592 bits 5 detect log odds 3.869 p = 0.9796 entropy = 0.144 bits same final belief in any order: True batch posterior = 0.9796 misses needed to doubt the marker after 10 detections: no clamp 12 clamp at 3: 2
logit and inv_logit convert between probability and log odds; entropy measures the uncertainty of a belief in bits.In robotics
The occupancy grid is this lesson, once per cell
Each cell of an occupancy grid map holds a log odds value, initially 0 (probability ½). A range beam that ends in a cell adds a positive weight of evidence; a beam that passes through adds a negative one; the values are capped. Mapping a whole room is millions of additions of the kind above, and the map can be stored as small integers. M10-T1: Occupancy Grids and the Binary Bayes Filter derives the update from this lesson; the SLAM course shows the practical version in Occupancy Grid Mapping.
Sequential tests for faults and detections
Instead of a fixed k-of-n vote (M2-T1: Discrete Random Variables and Probability Mass Functions), a detector can keep a running log odds and declare “marker found” when it crosses an upper threshold, and “not there” when it falls below a lower one. This is the sequential probability ratio test: it reaches the same error rates with fewer readings on average, and it is how many fault monitors work (Sensor fault detection and isolation).
Fusion of several detectors
Two independent detectors can be fused by adding their weights of evidence. A camera that says “person” with a likelihood ratio of 20 and a thermal sensor with a ratio of 5 give a total ratio of 100, which turns a prior of 1 in 1000 into about 9%. Writing evidence in log units makes it easy to audit which sensor drove a decision.
When the state changes, add a prediction step
Everything above assumes the marker's presence is fixed while the readings arrive. If a door can open or close between frames, the old belief is partly out of date and must be softened before each update, otherwise it becomes more and more stubborn. That softening is the prediction step of the Bayes filter (M6-T1: The Bayes Filter). A cap on the log odds is a crude, always-available version of it.
Common implementation bugs
- The prior applied at every step:
bel = prior * likelihoodinside the loop instead ofbel = bel * likelihood. The prior is counted once per reading. - Probabilities multiplied without normalizing, until they underflow to zero. Work in log odds or log probabilities, or normalize every step.
- No cap, so the belief can never change its mind after a long run of the same reading.
Common misconceptions
“Each reading should move the probability by about the same amount.”
Each independent reading adds the same evidence, and that equals the same step in log odds. In probability the step shrinks as the belief approaches 0 or 1 (+0.25 for the first detection, +0.12 for the last). Do not tune a filter by looking at how many percentage points a reading moves the belief.
“Later readings should count more than earlier ones.”
For a static state they count exactly the same, and the order does not matter. They count more only if the state may have changed, which is a different model (the filter with a prediction step) and needs a motion model, not a heuristic.
“Re-using the prior at every step keeps the belief anchored.”
It counts the prior once per reading. With a prior of 0.05, every update multiplies the odds by 8 × 0.0526 = 0.42 instead of 8, so detections make the belief fall. The prior enters exactly once, at the start.
“A belief of 0.9999 is better than one of 0.99.”
Only if the independence assumptions are true. A belief that grows from repeated, correlated or copied readings is overconfident, and it takes as long to unlearn as it took to learn. Cap the log odds so that a handful of contrary readings can still change the robot’s mind.
Key takeaways
- Update one reading at a time: the posterior of one step is the prior of the next, bel_t ∝ P(zt | x) bel_{t−1}. For independent readings of a static state this equals the batch update, in any order.
- In odds form, posterior odds = likelihood ratio × prior odds; in log odds the update is an addition of the weight of evidence ln LR.
- A detection with d = 0.8, f = 0.1 is worth +2.08 and a miss −1.50. The probability moves by different amounts each time; the log odds move by the same.
- Cap the log odds so that a long run of one reading cannot make the belief impossible to change; this is how occupancy grids are stored.
- The prior enters once. A moving state needs a prediction step (module 6) that softens the belief between readings.
References and further reading
Each source is marked free or paid. Free to read does not mean free to reuse: the course resources page lists every source with its licence.
- C. Stachniss, “Bayes Filter” (video lecture) , the recursive update with a prediction step. Free to watch.
- J. Tsitsiklis and P. Jaillet, MIT RES.6-012 Introduction to Probability , lectures 14 to 17 (Bayesian inference). Free videos and notes, licence CC BY-NC-SA 4.0.
- S. Thrun, W. Burgard and D. Fox, Probabilistic Robotics, MIT Press, 2005, section 4.2 (the binary Bayes filter, with its log-odds form). Paid book.
- A. Wald, “Sequential Tests of Statistical Hypotheses”, Annals of Mathematical Statistics 16 (2), 1945 , the sequential probability ratio test. Paid journal article.
- C. Piech, Probability for Computer Scientists (Stanford CS109 course reader) , part 1 (updating beliefs). Free to read online.
Knowledge check
Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.
Question 1
A belief starts at probability 0.2. A detector fires; its likelihood ratio for a detection is 4 and for a miss is 0.5. Compute the belief after three detections in a row, and after a detection followed by a miss. Which representation made it easy?
Explanation
Prior odds = 0.2/0.8 = 0.25. After three detections: 0.25 × 4³ = 16, so p = 16/17 = 0.941. After a detection then a miss: 0.25 × 4 × 0.5 = 0.5, so p = 0.5/1.5 = 0.333. The odds form made it easy: each reading is one multiplication by its likelihood ratio, with no normalization (in log odds: ln 0.25 = −1.386, then add 1.386 per detection and subtract 0.693 per miss).
Question 2
An occupancy grid cell starts at probability 0.5 and every beam that ends in the cell uses the inverse sensor model p = 0.7 for “occupied”; a beam that passes through uses 0.3. Three beams end in the cell, then two pass through it. What are the log odds and probability at the end?
Explanation
The weight of evidence of p = 0.7 is ln(0.7/0.3) = +0.847; of p = 0.3 it is −0.847. Starting at log odds 0: after three ending beams 3 × 0.847 = 2.542 (p = 0.927); after two pass-through beams 2.542 − 1.695 = 0.847, which is p = 0.7. Each hit is cancelled exactly by one pass-through, which is why the grid forgets a moved obstacle only as fast as contrary readings arrive, and why a cap on the log odds is used.
Question 3
A teammate’s update loop reads: for each frame, belief = normalize(prior × likelihood × belief). With a prior of 0.05 for “marker present” and a detector with likelihood ratio 8, what happens to the belief during a run of detections?
Explanation
The prior is multiplied in at every step, so the odds change by LR × prior odds = 8 × 0.0526 = 0.42 per detection, a factor below 1. The belief therefore falls toward zero during a run of detections, the opposite of what the evidence says. The prior must enter only once, as the starting belief; the loop should be belief = normalize(likelihood × belief).
What’s next
Module 3 gave you the rules for updating a belief from evidence. Module 4 looks at the quantities that summarise a distribution: the mean, the variance, and the covariance that describes uncertainty in two or more dimensions at once.
Related content
Nothing below is required to finish this lesson.
- BeforeM3-T3: Independence and Conditional Independence
Test whether two variables are independent, explain conditional independence, and identify when evidence is being counted twice.
- LabM3-L1: Bayesian Landmark Detection
A marker detector fires near the charging dock, but it also fires by mistake. Compute how much each detection should change the belief that the robot is at the dock.
Other courses on this site treat neighbouring topics from their own angle:
Get notified when the next lesson and new labs are released.
One email per new lesson or lab.