Skip to the lesson
FixTheRobot Explore Robotics / Probability for Robotics / M1 Introduction to Probability in Robotics / M1-T1

Probability for Robotics · Theory · M1

M1-T1 — Why Robots Need Probability

A robot never knows where it is. It knows how sure it is, and that is enough to act well.

  • Lesson 1 of 3
  • Beginner
  • Module 1: Introduction to Probability in Robotics
  • Theory
  • About 14 minutes to read

Tell a robot to drive two metres and measure where it stops. Do it ten times and you get ten different answers. Nothing is broken: wheels slip, sensors are noisy and the floor is not the floor of the model. This lesson explains where that uncertainty comes from, what it means to put a number on it, and why a robot that carries only a best guess makes worse decisions than one that also carries its doubt.

Learning objectives

After this lesson, you should be able to:

  • Name the five sources of uncertainty in a robot and give an example of each.
  • Explain what a probability means in two ways: as a long-run frequency and as a degree of belief.
  • Distinguish a state, an estimate, an error and an uncertainty.
  • Show with an expected-cost calculation why the most likely state can lead to the wrong action.

The intuition

Rover, the small two-wheeled robot of this course, is told to drive 2.00 m along a corridor. You mark where it stops and repeat the run ten times. The marks are spread over several centimetres. The command was the same every time, so the spread comes from things the command does not control.

Sources of uncertainty in a robot
SourceWhat happensExample on a mobile robot
ActuationThe robot does not do exactly what it was told.A wheel slips on dust; one motor is slightly stronger; a drone is pushed by a gust.
SensingA measurement differs from the true quantity.A range reading scatters by a few centimetres; an encoder counts in whole ticks; a camera pixel is 3 cm wide at 5 m.
EnvironmentThe world is not what the robot assumes.A door that was open is closed; a person walks through the scan; a glass wall returns no echo.
ModelThe equations are a simplification.The wheel radius is 2% off; the floor is assumed flat; the sensor noise is assumed Gaussian and is not.
ComputationThe algorithm is approximate and late.A map is a grid of 5 cm cells; a filter linearizes a curve; a measurement arrives 40 ms after it was taken.

None of these can be removed completely. A better sensor makes the spread smaller, not zero. So the honest description of what Rover knows after its drive is not “I am at 2.00 m” but “I am probably within a few centimetres of 2.00 m, and almost certainly within ten”. Probability is the language that makes that sentence precise.

What a probability means

A probability is a number between 0 and 1 attached to a statement. There are two ways to read it, and a robotics engineer uses both.

  • Long-run frequency. “The probability that Rover docks is 0.9” means: repeat the drive many times under the same conditions and about 90% of the runs end on the dock. This reading describes the robot and its world. You can measure it with an experiment.
  • Degree of belief. “The probability that Rover is in the kitchen is 0.9” is about one situation, now. Rover either is in the kitchen or is not; nothing is repeated. The number describes what the robot knows: how strongly the evidence it has supports the statement. New evidence changes the number even though the robot has not moved.

The two readings obey exactly the same rules (the next lesson states them), which is why the same mathematics serves for testing a robot over a thousand runs and for running a filter inside it.

Best guess and belief

Suppose Rover's range sensor says the door ahead is 0.60 m away. A program that stores the single number 0.60 has thrown away something it knew: that the sensor is good to about 10 cm, so the door might be at 0.50 m or 0.70 m. A program that stores a belief keeps the whole picture: every possible distance, with a weight that says how plausible it is.

A best guess and a belief about the distance to a doorA bell-shaped curve over distance, centred on 0.60 metres. A vertical line at 0.60 metres marks the best guess. A second vertical line at 0.45 metres marks the stopping distance. The small area of the curve to the left of 0.45 metres is shaded: it is the probability that the robot cannot stop in time.0.20.30.40.50.60.70.80.91true distance to the door (m) best guess 0.60 m stopping distance 0.45 m P = 0.067 belief: how plausibleeach distance is
The same measurement as a best guess (one number) and as a belief (a curve). Only the belief can answer “how likely is it that I am closer than my stopping distance?”

A belief is not vagueness. It is a precise, numeric statement of what the robot does and does not know, and it is the input every decision in this course will use.

Definitions

State xx
The true value of the quantities you care about: here the distance to the door; later a pose (x,y,θ)(x, y, \theta), a velocity, a map. The robot never observes it directly.
Measurement zz
What a sensor reports. It depends on the state, but it is not the state.
Estimate x^\hat{x}
A single number the robot computes as its best guess of the state.
Error e=x^−xe = \hat{x} - x
The difference between the estimate and the truth. It is one unknown number: if the robot knew it, it would subtract it.
Uncertainty
A description of the errors that are possible and how likely each is. It is known even though the error is not. A standard deviation of 0.10 m is an uncertainty.
Probability P(A)P(A)
A number in [0,1][0, 1] attached to a statement AA: 0 means “cannot be true”, 1 means “certainly true”.
Belief bel(x)\mathrm{bel}(x)
The robot's probability for each possible state, given everything it has measured and commanded so far.

Written with the notation used in the rest of the course, the belief at time tt is a conditional probability: the probability of the state given the data.

Belief
bel(xt)=p(xt∣z1:t, u1:t)\mathrm{bel}(x_t) = p(x_t \mid z_{1:t},\, u_{1:t})
z1:tz_{1:t} are all measurements up to now and u1:tu_{1:t} all commands. The bar reads “given”. Module 3 defines conditional probability; module 6 shows how to compute this belief step by step.

Two kinds of uncertainty behave differently, and it is useful to keep them apart:

  • Noise (also called aleatoric uncertainty) is the scatter that remains however much you know: the next range reading will differ from this one. Averaging reduces its effect; nothing removes it.
  • Ignorance (epistemic uncertainty) is what you could know but do not: the wheel radius, where the robot was switched on, whether the door is open. More data shrinks it.

Derivation: when the best guess gives the wrong action

Why carry a belief at all? Because the action that is best for the most likely state is not always the best action. The argument takes four lines.

Rover approaches the door and must choose between two actions: continue at speed, or slow down. There are two possibilities for the world: the door is closer than the stopping distance (call this HH, for hazard), or it is not. Rover's belief gives P(H)=pP(H) = p. Each action has a cost in each case:

Costs of the two actions
Hazard (probability pp)No hazard (probability 1−p1-p)
Continuecollision, cost CcC_cnothing lost, cost 0
Slow downsafe, cost CsC_stime lost, cost CsC_s
  1. E[cost∣continue]=p Cc+(1−p)⋅0=p Cc\mathbb{E}[\text{cost} \mid \text{continue}] = p\,C_c + (1-p)\cdot 0 = p\,C_c

    The expected cost of an action is each cost multiplied by its probability, added up. It is the average cost per approach if the same situation were met many times.

  2. E[cost∣slow down]=p Cs+(1−p) Cs=Cs\mathbb{E}[\text{cost} \mid \text{slow down}] = p\,C_s + (1-p)\,C_s = C_s

    Slowing down costs the same lost time whether or not the hazard was real.

  3. slow down whenp Cc>Cs\text{slow down when}\quad p\,C_c > C_s

    Choose the action with the smaller expected cost.

  4. p>p∗=CsCcp > p^{*} = \frac{C_s}{C_c}

    Divide both sides by CcC_c. The threshold depends only on the ratio of the two costs.

Now compare with a robot that uses only its best guess. If p<0.5p < 0.5 the most likely state is “no hazard”, and for that state the best action is to continue. So the best-guess robot continues whenever p<0.5p < 0.5. The belief robot slows down whenever p>Cs/Ccp > C_s / C_c. If a collision is fifty times worse than a lost second, that threshold is 0.02. For every belief between 2% and 50% the two robots disagree, and the best-guess robot is the one that eventually hits the door.

The best guess answers “what is most likely?”. A decision needs “what could happen, how likely is it, and what would it cost?”. Only a belief can answer that.

A worked example

Put numbers on the figure above. The range sensor reads z=0.60z = 0.60 m and its noise has a standard deviation of σ=0.10\sigma = 0.10 m. At the current speed Rover needs 0.45 m to stop. A collision costs Cc=50C_c = 50 and slowing down costs Cs=1C_s = 1 (in any unit, for example seconds of delay).

  1. Best guess. The estimate is 0.60 m and the stopping distance is 0.45 m, so there is a margin of 0.15 m. The best-guess robot continues.
  2. Belief. Treat the belief about the true distance dd as a bell-shaped (Gaussian) curve centred on 0.60 m with standard deviation 0.10 m. Module 2 studies this curve; here we only need the area of its left tail.
  3. Probability of the hazard. The hazard is d<0.45d < 0.45. That is (0.45−0.60)/0.10=−1.5(0.45 - 0.60)/0.10 = -1.5 standard deviations below the centre. The area of a Gaussian below −1.5 standard deviations is 0.0668, so p=0.067p = 0.067: about one approach in fifteen.
  4. Threshold. p∗=Cs/Cc=1/50=0.02p^{*} = C_s / C_c = 1/50 = 0.02.
  5. Decision. 0.067>0.020.067 > 0.02: slow down. In expected cost, continuing costs 0.067×50=3.340.067 \times 50 = 3.34 per approach and slowing down costs 1.
  6. How close may Rover get at this speed? The hazard probability falls to 0.02 when the reading is 0.45+2.054×0.10=0.6550.45 + 2.054 \times 0.10 = 0.655 m. Below a reading of 0.655 m the robot should already be slowing: a margin of about two standard deviations, not zero.

The same calculation with the course library. Every number above is printed by this program, and the site's tests run it.

from robotprob import gaussian_cdf, gaussian_ppf

z, sigma = 0.60, 0.10          # reading and its standard deviation (m)
stop = 0.45                    # stopping distance (m)
C_c, C_s = 50.0, 1.0           # cost of a collision, cost of slowing down

p = gaussian_cdf(stop, z, sigma)               # P(true distance < stopping distance)
p_star = C_s / C_c
print('P(hazard)          =', round(p, 4))
print('threshold          =', round(p_star, 4))
print('cost if continue   =', round(p * C_c, 2))
print('cost if slow down  =', round(C_s, 2))
print('decision           =', 'slow down' if p > p_star else 'continue')
print('slow below reading =', round(stop - gaussian_ppf(p_star) * sigma, 3), 'm')
P(hazard)          = 0.0668
threshold          = 0.02
cost if continue   = 3.34
cost if slow down  = 1.0
decision           = slow down
slow below reading = 0.655 m
gaussian_cdf(a, mean, std) is the probability that a Gaussian quantity is below a; gaussian_ppf is its inverse.

In robotics

Every part of a robot's software that touches the real world carries uncertainty, and the rest of this course is about the tools each part uses.

Where robots use probability
TaskWhat is uncertainHow probability is usedWhere in this course
LocalizationThe robot's poseA belief over poses, updated by every motion and every measurementModules 6 to 9
Sensor fusionEach sensor's readingReadings are weighted by how certain they are; a noisy sensor counts for lessModules 4 and 7
MappingWhether each piece of space is occupiedA probability of occupancy per cell, raised or lowered by each beamModule 10
SLAMThe trajectory and the map togetherThe most probable trajectory given all measurements, found by optimizationModule 11
Planning and safetyWhere the robot and the obstacles really areMargins sized from the pose uncertainty; actions chosen by expected cost, as aboveModule 12

Three concrete places you will meet it in practice:

  • Messages carry it. In ROS 2 the pose and velocity messages used by localization (geometry_msgs/PoseWithCovariance, inside nav_msgs/Odometry) include a 6 × 6 covariance matrix next to the estimate. A consumer that ignores it is the best-guess robot of this lesson. Module 4 explains how to read that matrix.
  • Flight controllers gate on it. A drone's state estimator compares each new measurement with what it expected and rejects one that is improbably far off, for example a GPS jump. “Improbably far” is defined by the estimator's own uncertainty. The UAV course describes this for PX4 and EKF2; modules 7 and 8 build the mathematics.
  • Humanoids and manipulators need it at contact. Whether a foot is firmly on the ground or a part is seated in a fixture is never observed directly; it is inferred from noisy forces and joint positions, as a probability.

If you have followed the Physical AI lessons, State, observation, belief introduces the same three words without mathematics. This course supplies the mathematics.

Common misconceptions

“A probabilistic robot behaves randomly.”

The robot's software is deterministic: the same data produce the same belief and the same action. Probability describes what the robot knows about a world it cannot observe exactly. It is bookkeeping for doubt, not dice in the controller.

“With good enough sensors you do not need probability.”

Better sensors shrink the uncertainty; they do not remove it, and they do nothing about slip, moving people or a wrong map. Even a centimetre-accurate lidar leaves a robot that must decide how much to trust it against its wheel odometry, which is a probability question.

“Uncertainty is the same thing as error.”

The error is the one unknown number by which this estimate is off. The uncertainty is the known description of how large errors tend to be. A filter can report its uncertainty exactly while its error stays unknown; a filter whose errors are regularly larger than its reported uncertainty is called overconfident, and module 7 shows how to detect it.

“A probability of 0.9 means the statement is 90% true.”

The door is either within stopping distance or it is not. The 0.9 measures the strength of the evidence, and its practical meaning is in the long run: of all the situations in which a well-calibrated robot says 0.9, the statement is true in about nine out of ten.

Key takeaways

  1. Uncertainty enters a robot through actuation, sensing, the environment, the model and the computation. It can be reduced but not removed.
  2. A probability can be read as a long-run frequency (a property of the robot and its world) or as a degree of belief (a property of what the robot knows). Both follow the same rules.
  3. The state is the truth, the estimate is a best guess, the error is their unknown difference, and the uncertainty describes which errors are plausible.
  4. A belief assigns a probability to every possible state, given all the data so far. It is the quantity every filter in this course computes.
  5. Good decisions weigh each possible outcome by its probability and its cost. The most likely state alone can recommend an action that is, on average, much worse.

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.

Knowledge check

Three questions. Write an answer, then reveal the explanation. Your answers stay in your browser.

Question 1

Rover's wheel encoders report 2.00 m after a drive, and a tape measure shows 1.94 m. A teammate says “the uncertainty of the odometry is 6 cm”. What is wrong with that sentence, and what would you need in order to state the uncertainty?

Explanation

The 6 cm is the error of this one run, a single number that happened to be measurable because someone used a tape. The uncertainty describes how errors are distributed over many runs. To state it you need repeated runs (or a model of the slip) and a summary of the spread of their errors, for example a standard deviation. One run with a 6 cm error is compatible with an uncertainty of 3 cm or of 10 cm.

Question 2

A warehouse robot believes there is a 5% probability that a person is behind a shelf corner. Stopping to check costs 4 seconds; a collision is judged 1000 times worse. Should it stop? What is the largest probability at which it may drive on?

Explanation

Stop. The threshold is p* = Cs / Cc = 1/1000 = 0.001. The belief of 0.05 is fifty times above it: the expected cost of driving on is 0.05 × 1000 = 50 units against 1 unit for stopping. The robot may drive on only when its belief is below 0.1%, which in practice means it needs evidence (a mirror, a second sensor, a slower approach that lets it see around the corner), not a more optimistic guess.

Question 3

Give one example of noise and one of ignorance in a drone hovering indoors, and say which of the two more flight time can reduce.

Explanation

Noise: the scatter of successive barometer or range-finder readings around the true height, or the vibration seen by the accelerometer; it is still there after an hour of flight. Ignorance: the accelerometer bias, the exact position where the drone took off, or the height of the ceiling; each is a fixed unknown that measurements gradually pin down. More flight time (more data) reduces ignorance. It only lets the estimator average the noise, which never disappears.

What’s next

You now have the vocabulary. The next lesson gives the three rules that every probability, frequency or belief, must obey.

Practice this lesson

Noisy Robot Motion Simulator

The same command gives a different end position every run. Simulate noisy motion, measure the spread, and predict how often the robot stops inside the docking zone.

Next lesson

M1-T2 — Events, Sample Spaces and the Rules of Probability

Describe an uncertain situation as a sample space and events, and use the three axioms, the complement rule and the addition rule.

Nothing below is required to finish this lesson.

  • Lab
    M1-L1: Noisy Robot Motion Simulator

    The same command gives a different end position every run. Simulate noisy motion, measure the spread, and predict how often the robot stops inside the docking zone.

Other courses on this site treat neighbouring topics from their own angle: