Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

2.3 Bayesian Inference: What Should I Believe Now?

Source

Section 2.2 ended with a gap. A likelihood tells the robot how well each possibility explains a reading, but not how probable each possibility is. To get there, the robot must also use what it believed before the reading arrived. This section shows how.

Which tower am I at?

A delivery robot enters a large gated community with four residential towers. Each tower has a coloured signboard at its entrance:

TowerBlueGreenYellowRed

The robot must deliver to Green Tower. Its GPS is unreliable here: the tall buildings block and reflect satellite signals, so its position estimate can wander by tens of metres. It drives in, stops at an entrance, and its camera reports:

Signboard detected: GREEN

Should the robot now be certain it is at Green Tower? Not quite. The camera is good but not perfect: afternoon glare, a faded board, or a green-painted gate nearby can all fool it. So the robot asks: given everything I knew before, and this new evidence, how strongly should I believe I am at Green Tower?

Step 1 · The prior: what the robot believed before looking

Even before the camera fires, the robot is not completely ignorant. From the complex’s map and its own route, it knows roughly which entrances it could have reached. Green Tower has the widest entrance and sits closest to the main gate, and Red Tower is at the far end. From the map and past deliveries, the robot’s belief before looking is:

TowerBlueGreenYellowRed
Prior P(x)P(x)0.250.350.250.15

This is called the prior probability: the belief prior to the new evidence. It is a PMF over the four towers, exactly like the vessel PMF in Section 2.1.

Step 2 · The evidence: how reliable is “green”?

The robot’s engineers tested the camera at every tower in all kinds of light. They recorded how often it reports “green” at each tower:

If the robot is actually at…BlueGreenYellowRed
P(camera says green∣tower)P(\text{camera says green} \mid \text{tower})0.050.900.040.03

The Green entry, 0.90, is how often the camera correctly recognises the green board. The others are false detections: for example, at Blue Tower the camera wrongly says “green” 5% of the time, perhaps because the blue board looks greenish under a sodium street light. This row is the likelihood of the observation “green” for each possible tower, the idea from Section 2.2.

Step 3 · Combining them: Bayes’ rule

The robot now reasons as follows. For each tower, how likely was it to be there, and how likely is it that the camera would say “green” from there? Multiplying these two numbers gives how strongly each tower is supported by both sources:

TowerPrior× Likelihood= Prior × Likelihood
Blue0.250.050.0125
Green0.350.900.3150
Yellow0.250.040.0100
Red0.150.030.0045
Total0.3420

These products are not yet probabilities, since they add up to 0.342 rather than 1. Dividing each by the total fixes that. The total, 0.342, is the overall probability that the camera would say “green” at all, whatever tower the robot is at.

Written as a formula, this reasoning is Bayes’ rule:

P(x∣z)⏟posterior  =  P(z∣x)⏞likelihood  P(x)⏞priorP(z)⏟evidence,P(z)=∑xP(z∣x) P(x)\underbrace{P(x \mid z)}_{\text{posterior}} \;=\; \frac{\overbrace{P(z \mid x)}^{\text{likelihood}}\;\overbrace{P(x)}^{\text{prior}}}{\underbrace{P(z)}_{\text{evidence}}}, \qquad P(z) = \sum_{x} P(z \mid x)\,P(x)

Here xx is the tower and zz is the observation (“green”). The result P(x∣z)P(x \mid z), the belief after the evidence, is called the posterior. In words: posterior = likelihood × prior, then normalize so it adds up to 1.

It comes directly from the rule for conditional probability, P(A,B)=P(A∣B) P(B)P(A, B) = P(A \mid B)\,P(B). Writing the joint probability P(x,z)P(x, z) both ways, as P(z∣x)P(x)P(z \mid x)P(x) and as P(x∣z)P(z)P(x \mid z)P(z), and solving for P(x∣z)P(x \mid z) gives (1).

P(camera says green) = 0.342

  tower | prior | likelihood | posterior
   Blue | 0.25  | 0.05       | 0.037
  Green | 0.35  | 0.90       | 0.921
 Yellow | 0.25  | 0.04       | 0.029
    Red | 0.15  | 0.03       | 0.013
<Figure size 1210x330 with 3 Axes>

Figure 1:Prior belief, likelihood of the observation “green”, and posterior belief over the four towers. One detection moves the belief in Green Tower from 0.35 to about 0.92.

A single “green” detection raises the robot’s belief in Green Tower from 0.35 to 0.92. Note what drives this. The camera is reliable (0.90 correct), and false “green” reports at the other towers are rare (0.03–0.05). The prior also leaned towards Green. If the prior had strongly favoured Blue, the same detection would have moved the belief less.

The posterior is not 1. There is still about an 8% chance the robot is somewhere else, mostly at Blue Tower, because Blue is both a likely place to be and the tower most prone to a false “green”. A careful robot keeps this doubt in mind.

Step 4 · One answer: MAP estimation

The robot’s navigation software needs a single answer now: should it turn towards the Green Tower lift lobby or not? A natural rule is to choose the tower with the highest posterior probability. This is the maximum a posteriori (MAP) estimate:

x^MAP=arg⁡max⁡x  P(x∣z)\hat{x}_{\text{MAP}} = \arg\max_{x}\; P(x \mid z)

The notation arg⁡max⁡x\arg\max_x means “the value of xx that makes the following expression largest”, and the hat in x^\hat{x} marks an estimate. Here, x^MAP=\hat{x}_{\text{MAP}} = Green.

MAP answers “which is most probable?”, which is not always the same question as “what should I do?”. If a wrong turn were very costly, the robot might first take another look even with 92% confidence. That trade-off between probability and consequences is the subject of Section 2.4.

MAP estimate: Green (posterior 0.921)

Step 5 · Fusing several sources of information

The camera is not the robot’s only source. It also has a GPS estimate, which is weak here but not useless, and the map, which it has already used as its prior. How should it combine them?

“GPS suggests Green Tower with 60% confidence” sounds like a probability, but to use it in Bayes’ rule we must turn it into a likelihood: how often does the GPS point to “Green” when the robot is actually at each tower? From test drives, suppose:

If the robot is actually at…BlueGreenYellowRed
P(GPS says green∣tower)P(\text{GPS says green} \mid \text{tower})0.250.600.100.05

GPS confuses Green with Blue fairly often (25%) because the two towers stand side by side. It rarely confuses Green with the far-away Red Tower.

If the camera’s errors and the GPS errors are independent (knowing that the camera erred tells us nothing about whether the GPS erred), then the two likelihoods simply multiply:

P(x∣zcam,zgps)  ∝  P(zcam∣x)  P(zgps∣x)  P(x)P(x \mid z_{\text{cam}}, z_{\text{gps}}) \;\propto\; P(z_{\text{cam}} \mid x)\;P(z_{\text{gps}} \mid x)\;P(x)

The symbol ∝\propto means “is proportional to”: compute the right-hand side for every tower, then normalize so the results sum to 1.

    map only (prior): Blue 0.250  Green 0.350  Yellow 0.250  Red 0.150
           map + GPS: Blue 0.205  Green 0.689  Yellow 0.082  Red 0.025
        map + camera: Blue 0.037  Green 0.921  Yellow 0.029  Red 0.013
  map + camera + GPS: Blue 0.016  Green 0.978  Yellow 0.005  Red 0.001
<Figure size 880x352 with 1 Axes>

Figure 2:Belief in each tower as sources are added. GPS alone is weak; the camera is strong; the two together push the belief in Green Tower to about 0.98.

Each source adds evidence. The GPS alone raises Green only from 0.35 to about 0.69. The camera alone takes it to 0.92, and the two together reach about 0.98. Neither sensor is trusted blindly; each contributes according to how reliable it has proven to be.

Fusing continuous estimates

The same logic works for continuous quantities, such as the distance to the gate from Section 2.2. Suppose the ultrasonic sensor gives 2.40 m with standard deviation 0.09 m, and the camera, judging the gate’s size in the image, estimates 2.70 m with standard deviation 0.30 m. When both are Gaussian and independent, the fused estimate is also Gaussian, with

μ=σ22 μ1+σ12 μ2σ12+σ22,σ2=σ12 σ22σ12+σ22\mu = \frac{\sigma_2^2\,\mu_1 + \sigma_1^2\,\mu_2}{\sigma_1^2 + \sigma_2^2}, \qquad \sigma^2 = \frac{\sigma_1^2\,\sigma_2^2}{\sigma_1^2 + \sigma_2^2}

The fused mean is a weighted average that trusts the less noisy source more, and the fused variance is smaller than either input. This single formula is the heart of the Kalman filter that the delivery e-cart uses in Chapter 7.

<Figure size 770x396 with 1 Axes>

The fused estimate, about 2.43 m, stays close to the ultrasonic reading because that sensor is more than three times as precise, but it moves slightly towards the camera’s estimate.