Phase 03 · Week 11 · 90 minutes

Day 73: Bayes filters and the predict/update cycle

State estimation, SLAM, and localization diagnosis · Reopen the Week 8 first flight to explain what the robot believed, why it changed, and whether the uncertainty was honest.

Chapter 11 · Estimate robot state, localize honestly, and measure uncertainty

Today in the field story

One problem, then the next

Courier-3 moves one metre according to the controller, so its belief shifts and spreads before the next lidar clue arrives. Perform the predict step, score the observation under each candidate location, and normalize the posterior. Then inject the reflective-wall dropout and preserve the broader prediction rather than fabricating certainty. The recursive cycle makes every localization change traceable to prior belief, motion assumption, and measurement evidence.

Why now

The mission needs a repeatable rule for carrying uncertainty through motion and new evidence.

Ignore today

Ignore continuous high-dimensional optimization; execute a small discrete Bayes cycle.

Unlocks next

The conceptual backbone shared by Kalman, particle, and grid-based estimators.

Understand

Build the physical picture first

A Bayes filter repeatedly spreads yesterday's belief through possible motion, scores each new possibility against today's clue, and renormalizes the surviving possibilities.

A Bayes filter stores a belief about current state instead of one unquestioned answer. The prior is the belief before processing the newest observation. In the prediction step, the motion or process model moves probability from old states to possible new states. Because the same command can produce several outcomes, prediction usually spreads belief and increases uncertainty rather than sliding one perfect dot.

The measurement update asks how likely the received observation would be for each proposed state. That score is the likelihood. Multiplying likelihood by predicted belief favours states that were already plausible and also explain the observation. Likelihood is not the probability of the state, and its values do not have to sum to one across states. The products become a posterior only after normalization.

Normalization divides every unnormalized weight by their total so the posterior sums to one. A repeated corridor can retain two strong hypotheses because one clue fits two locations. A later distinctive observation may remove one mode. A filter should not erase ambiguity simply to produce a convenient single pose; navigation may need to wait, seek information, or use a bounded recovery policy.

The algorithm is only as honest as its transition and measurement models. A motion model that ignores wheel slip can push probability too far. A sensor model that claims impossible certainty can delete the true state after one unusual scan. Zero total weight is a model or data failure requiring a defined fallback, not permission to divide by zero or silently reset near the goal.

Words you need

Name each idea precisely

Prior

The state belief available before the newest measurement update.

Physical example:

Before seeing a doorway, a hidden token is believed to be under the middle two of four cups.

Prediction

The process-model step that moves the previous belief through possible motion outcomes.

Physical example:

A one-cell-right command moves most probability right but leaves some in place because wheels can slip.

Likelihood

How compatible an observation is with each proposed state under the sensor model.

Physical example:

A door-detected clue scores cells near mapped doors higher than blank wall cells.

Posterior

The normalized state belief after combining the prediction with the newest observation.

Physical example:

After a noisy door reading, one corridor location holds 83% of the belief but alternatives remain.

Normalization

Dividing weights by their total so all posterior probabilities sum to one.

Physical example:

Weights 0.02, 0.40, and 0.06 are divided by 0.48.

Recursive filter

An estimator that carries the previous belief forward rather than recomputing from the entire history every cycle.

Physical example:

Each corridor update uses yesterday's posterior as today's starting belief.

Math, one line at a time

Work through today’s relationship

Prerequisite rescue · optionalProbability, variance, and Kalman weighting

State estimation combines predictions and measurements according to uncertainty.

μ
best current estimateUnit: state unit
σ²
variance, or squared uncertainty spreadUnit: state unit squared
K
Kalman gain, the measurement weightUnit: unitless
  1. Prediction is 10 m. Measurement is 12 m. Let K = 0.25.

  2. Innovation is 12 − 10 = 2 m.

  3. Updated estimate = 10 + 0.25×2 = 10.5 m; the lower-trust measurement only shifts the estimate partway.

Programmer analogy

It is a weighted merge like resolving two data sources, but the weights come from modeled uncertainty.

Prediction 5 m, measurement 7 m, K = 0.5. What is the update?

5 + 0.5×(7−5) = 6 m.

Discrete Bayes uses

p(xz)p(zx)p(x).p(x\mid z)\propto p(z\mid x)p(x).

The unnormalized weights are 0.8×0.5=0.40.8\times0.5=0.4 and 0.2×0.5=0.10.2\times0.5=0.1; dividing by their sum 0.50.5 gives posterior probabilities 0.80.8 and 0.20.2. Kalman gain is a linear-Gaussian specialization, not the general Bayes rule.

Complete one discrete predict-and-update cycle

After a motion prediction, a robot has belief [0.20, 0.50, 0.30] over corridor cells A, B, and C. A door sensor fires. Its likelihood for that observation is [0.10, 0.80, 0.20].

  1. Confirm both arrays use the same ordered states A, B, C; otherwise element-by-element multiplication would combine unrelated locations.

  2. Multiply cell A: 0.20 × 0.10 = 0.02.

  3. Multiply cell B: 0.50 × 0.80 = 0.40.

  4. Multiply cell C: 0.30 × 0.20 = 0.06.

  5. Add the unnormalized weights: 0.02 + 0.40 + 0.06 = 0.48.

  6. Normalize: [0.02, 0.40, 0.06] / 0.48 ≈ [0.0417, 0.8333, 0.1250], which sums to 1.0000 within rounding.

Result

Cell B becomes the strongest hypothesis at about 83.33%, but cells A and C retain nonzero probability because the sensor is not infallible.

What this proves

A Bayes update combines what was plausible with what explains the clue; it does not replace history with the newest reading.

Physical examples

Where this appears in real life

Noisy clue under three cups

A token may be under one of three cups. A move rule shifts it right with occasional slip, and a helper gives a clue that is usually, but not always, correct.

Look for:

Motion redistributes the prior before the clue is scored; a noisy clue changes weights without making an unsupported probability-one claim.

Two identical corridor doors

A range pattern that means 'doorway on the left' appears at two different places on a long floor plan.

Look for:

The measurement update can strengthen both locations, preserving two modes until motion or a distinctive landmark separates them.

Hands-on exercise

Make the idea observable

Build a five-cell corridor filter in a spreadsheet or short deterministic script. Use only synthetic data and save every belief vector.

  1. Choose an initial normalized belief and write a motion transition that moves right most of the time, sometimes stays, and never creates negative probability.

  2. Implement prediction and assert that its output is nonnegative and sums to one within a small numeric tolerance.

  3. Create door and no-door likelihood arrays for a map with two similar door locations, then implement multiply-and-normalize update.

  4. Run a sequence of two moves and three observations, saving prior, prediction, likelihood, unnormalized weights, normalizer, and posterior at each cycle.

  5. Deliberately use an all-zero likelihood, verify the normalizer becomes zero, and return a structured model-failure result instead of a fake posterior.

  6. Repair the sensor model with defensible nonzero false-positive and false-negative probabilities, rerun, and compare how ambiguity changes.

Observe

Prediction spreads or moves probability, an ambiguous clue preserves two peaks, and an impossible all-zero sensor model makes the update undefined.

Done when

All normal beliefs remain normalized, the all-zero case fails explicitly, and another person can reproduce the [0.0417, 0.8333, 0.1250] posterior.

Build today

Use the frozen Week 8 artifacts to fuse odometry and IMU, explain scan matching, loop closure, and AMCL, then rerun the unchanged scenarios and compare error, uncertainty coverage, transform age, dropout recovery, and navigation success.

Evidence to save

DONE when a deterministic “Bayes filters and the predict/update cycle” failure test reports expected versus actual behavior and passes after the documented fix.

Common mistakes

Catch the wrong mental model

Wrong

Calling likelihood the probability that a state is true.

Better

Likelihood scores how expected the observation is under each proposed state; combine it with the predicted belief to obtain a posterior.

Wrong

Applying the sensor update before the motion prediction for the wrong timestamp.

Better

Order controls and observations by their source time and apply each model to the state time it actually describes.

Wrong

Silently resetting when all unnormalized weights are zero.

Better

Return a visible model or data failure, preserve evidence, and invoke only an explicit, bounded relocalization policy.

Job connection

How this becomes employable evidence

Implement or diagnose a localization update whose motion and sensor models preserve multiple warehouse pose hypotheses instead of snapping an AMR to the newest scan match.

Relevant target roles

  • Robotics Software Engineer — ROS 2 / AMR
  • Robotics Application / ROS 2 Integration Engineer

Chapter 11 interview drill

Interview questions: Bayes filters and the predict/update cycle

Practise a 60–90 second answer: define the idea, connect it to a physical robot, state assumptions, frames, and units when relevant, then finish with the failure signal or evidence you would inspect.

Primary interview scenario

Walk through Bayes prediction, likelihood scoring, normalization, and a zero-normalizer failure for a robot that sees the same doorway pattern at two map locations.

Answer shape: clarify the situation → trace the physical and software path → test the most likely boundaries → name the evidence that would confirm the result.

Technical follow-up questions

Q1Why does prediction often increase uncertainty?
Model interview answer

One prior state and control can lead to several physical outcomes because the process model includes motion noise.

Q2Why normalize after multiplying prior and likelihood?
Model interview answer

The products are relative weights; division by their total turns them into a probability distribution summing to one.

Q3Can a posterior keep two pose hypotheses?
Model interview answer

Yes. If two states were plausible and both explain the observation, a correct belief can remain multimodal.