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

Probability for Robotics · Theory · M1

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

Three rules. Everything else in probability, from Bayes’ rule to the Kalman filter, is derived from them.

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

Before a robot can reason about uncertainty it has to say what could happen, and attach numbers to those possibilities in a way that never contradicts itself. This lesson builds that foundation: outcomes, events, and three axioms. From the axioms we derive the handful of rules you will use daily, and we see why “the probabilities must add up to one” is the statement “the robot is somewhere”.

Learning objectives

After this lesson, you should be able to:

  • Describe an uncertain situation with a sample space of mutually exclusive, exhaustive outcomes.
  • Express a question about a robot as an event, a set of outcomes.
  • State the three axioms of probability and say what each means physically.
  • Derive and use the complement rule, the addition rule for overlapping events and the union bound.

The intuition

Think of probability as one unit of belief that has to be shared out among everything that could happen. Nothing can receive a negative share, and the shares must use up exactly the whole unit, because something happens.

Take Rover's drive to the dock from the previous lesson. Watching 200 runs, the team sorted each one into exactly one of five bins:

One unit of probability shared among five outcomesA horizontal bar of total length one, divided into five segments: docked 0.62, left 0.14, right 0.16, short 0.05 and long 0.03. A bracket under left and right marks the event missed sideways with probability 0.30. A bracket under the last four segments marks the event did not dock with probability 0.38.docked0.62left0.14right0.16short0.05long0.03A = missed sideways: 0.14 + 0.16 = 0.30not docked: 1 − 0.62 = 0.38
One unit of probability shared among the five possible outcomes of a run. A question about the run, such as “did it miss sideways?”, selects some of the segments; its probability is their total length.

Three ideas are already in this picture.

  • The five bins are the outcomes. They do not overlap (a run cannot be both “left” and “short” if we define the bins carefully), and together they cover every run. One and only one of them happens.
  • A question with a yes or no answer is an event: a set of outcomes. “Missed sideways” is the set {left, right}. “Did not dock” is {left, right, short, long}.
  • The probability of an event is the total share of its outcomes. That is all “adding probabilities” means, and it is safe exactly when the pieces being added do not overlap.

Most mistakes with probability are mistakes about overlap: adding the probabilities of events that can happen together, or forgetting an outcome so that the shares no longer use up the whole unit.

Definitions

Experiment
Any process whose result is not known in advance: one drive to the dock, one range reading, switching the robot on at an unknown place.
Outcome ω\omega
One complete result of the experiment, at the level of detail you chose to record.
Sample space Ω\Omega
The set of all outcomes. Its members must be mutually exclusive (no two happen together) and exhaustive (one of them always happens).
Event AA
A subset of Ω\Omega. The event “happens” when the outcome is one of its members.
AcA^{c} (complement)
Everything in Ω\Omega that is not in AA: “AA does not happen”.
A∪BA \cup B (union)
Outcomes in AA or in BB or in both: “at least one happens”.
A∩BA \cap B (intersection)
Outcomes in both: “both happen”. If A∩B=∅A \cap B = \varnothing the events are disjoint (mutually exclusive).
Partition
A collection of events that are pairwise disjoint and whose union is Ω\Omega. The outcomes themselves are the finest partition.

A probability PP assigns a number to every event and satisfies three axioms (due to Kolmogorov, 1933):

The axioms of probability
1.   P(A)≥02.   P(Ω)=13.   A∩B=∅  ⇒  P(A∪B)=P(A)+P(B)\textbf{1. }\; P(A) \ge 0 \qquad\quad \textbf{2. }\; P(\Omega) = 1 \qquad\quad \textbf{3. }\; A \cap B = \varnothing \;\Rightarrow\; P(A \cup B) = P(A) + P(B)
Axiom 3 extends to any number of pairwise disjoint events: the probability of their union is the sum of their probabilities.

What each one says about a robot:

The three axioms and their meaning
AxiomIn wordsPhysical meaning
1. Non-negativityNo event has a negative probability.A share of belief cannot be less than nothing. Code that produces a negative probability has a bug, usually a subtraction that went wrong.
2. NormalizationThe whole sample space has probability 1.Something in the list of outcomes happens: the robot is somewhere, the door is open or closed. This holds only if the list is complete.
3. AdditivityProbabilities of events that cannot happen together add.Shares of separate outcomes are separate. It is the only rule for combining probabilities that the axioms give, and it applies only without overlap.

Notice what the axioms do not say: they do not tell you what the numbers are. Whether the probability of docking is 0.62 comes from data (a frequency) or from a model (a belief). The axioms only guarantee that whatever numbers you use are consistent with each other.

Derivation: the rules that follow from the axioms

Four rules are used constantly. None needs to be memorized as a separate fact: each follows from the axioms in a few steps.

The complement rule

  1. A∪Ac=Ω,A∩Ac=∅A \cup A^{c} = \Omega, \qquad A \cap A^{c} = \varnothing

    By definition the complement holds exactly the outcomes that AA does not. Together they are everything, and they share nothing.

  2. P(A)+P(Ac)=P(A∪Ac)P(A) + P(A^{c}) = P(A \cup A^{c})

    Axiom 3, because the two events are disjoint.

  3. P(A)+P(Ac)=P(Ω)=1P(A) + P(A^{c}) = P(\Omega) = 1

    Their union is the sample space, and axiom 2 gives its probability.

  4. P(Ac)=1−P(A)P(A^{c}) = 1 - P(A)

    Rearranged. It is often much easier to compute the probability that something does not happen.

Two quick consequences: taking A=ΩA = \Omega gives P(∅)=0P(\varnothing) = 0, and since P(Ac)≥0P(A^{c}) \ge 0 every probability satisfies P(A)≤1P(A) \le 1.

A larger event is at least as probable

  1. A⊆B  ⇒  B=A∪(B∩Ac)A \subseteq B \;\Rightarrow\; B = A \cup (B \cap A^{c})

    Split BB into the part inside AA and the part outside. The two parts are disjoint.

  2. P(B)=P(A)+P(B∩Ac)≥P(A)P(B) = P(A) + P(B \cap A^{c}) \ge P(A)

    Axiom 3, then axiom 1 for the second term. This property is called monotonicity.

The addition rule for events that may overlap

Two events that overlapA rectangle stands for the whole sample space with probability one. Inside it two circles overlap. The left circle is the event bumper fires, probability 0.08. The right circle is the event cliff sensor fires, probability 0.05. Their overlap, both fire, has probability 0.02. Adding the two circles counts the overlap twice.Ω: every possible run, probability 1 A: bumper0.08 B: cliff0.05 A∩B0.02 neither: 0.89
Adding P(A) and P(B) counts the outcomes in the overlap twice, so the overlap is subtracted once.
  1. A∪B=A ∪ (B∩Ac)A \cup B = A \,\cup\, (B \cap A^{c})

    The union is all of AA plus the part of BB that lies outside AA. These are disjoint.

  2. P(A∪B)=P(A)+P(B∩Ac)P(A \cup B) = P(A) + P(B \cap A^{c})

    Axiom 3, because the two parts are disjoint.

  3. B=(B∩A) ∪ (B∩Ac)  ⇒  P(B∩Ac)=P(B)−P(A∩B)B = (B \cap A) \,\cup\, (B \cap A^{c}) \;\Rightarrow\; P(B \cap A^{c}) = P(B) - P(A \cap B)

    Split BB the same way and apply axiom 3 again.

  4. P(A∪B)=P(A)+P(B)−P(A∩B)P(A \cup B) = P(A) + P(B) - P(A \cap B)

    Substitute. When the events are disjoint the last term is zero and the rule reduces to axiom 3.

The union bound

Since P(A∩B)≥0P(A \cap B) \ge 0, dropping it can only make the right-hand side larger. Repeating the argument for more events gives:

Union bound
P(A1∪A2∪⋯∪An)  ≤  P(A1)+P(A2)+⋯+P(An)P(A_1 \cup A_2 \cup \dots \cup A_n) \;\le\; P(A_1) + P(A_2) + \dots + P(A_n)
The probability that at least one of several things goes wrong is never more than the sum of their probabilities, whatever the overlaps and whether or not the events are related.

Add probabilities only for events that cannot happen together. For events that can, subtract the overlap, or use the sum as a safe upper bound.

A worked example

Part 1: questions about a run. Use the outcome probabilities of the figure: docked 0.62, left 0.14, right 0.16, short 0.05, long 0.03. They are non-negative and sum to 1.00, so they form a valid probability.

  1. Missed sideways. A={left,right}A = \{\text{left}, \text{right}\}. The outcomes are disjoint, so P(A)=0.14+0.16=0.30P(A) = 0.14 + 0.16 = 0.30.
  2. Did not dock. The direct way adds four outcomes. The complement rule is shorter: P(dockedc)=1−0.62=0.38P(\text{docked}^{c}) = 1 - 0.62 = 0.38.
  3. Stopped at the wrong distance. P({short,long})=0.05+0.03=0.08P(\{\text{short}, \text{long}\}) = 0.05 + 0.03 = 0.08. Check: sideways 0.30 plus wrong distance 0.08 is 0.38, the same as “did not dock”, because those two events partition it.

Part 2: two sensors that can fire together. On a test course, in any one minute, Rover's bumper fires with probability 0.08 and its cliff sensor with probability 0.05. When Rover reaches a ledge with a raised lip, both fire: that happens with probability 0.02. The safety logic stops the robot if either fires. How often does it stop?

  1. Wrong. 0.08+0.05=0.130.08 + 0.05 = 0.13. This adds events that are not disjoint and counts the “both” minutes twice.
  2. Right. P(A∪B)=0.08+0.05−0.02=0.11P(A \cup B) = 0.08 + 0.05 - 0.02 = 0.11.
  3. No stop. By the complement rule, P(neither)=1−0.11=0.89P(\text{neither}) = 1 - 0.11 = 0.89.
  4. If the overlap were unknown. The union bound still says the stop probability is at most 0.13, and monotonicity says it is at least 0.08 (the larger single event). The true 0.11 lies between.
from robotprob import Discrete

# Discrete checks the axioms: no negative share, total exactly 1.
runs = Discrete({'docked': 0.62, 'left': 0.14, 'right': 0.16, 'short': 0.05, 'long': 0.03})
print('P(missed sideways) =', round(runs.prob({'left', 'right'}), 2))
print('P(did not dock)    =', round(1 - runs.p('docked'), 2))
print('P(wrong distance)  =', round(runs.prob({'short', 'long'}), 2))
print('P(not long)        =', round(runs.prob(lambda o: o != 'long'), 2))

p_bumper, p_cliff, p_both = 0.08, 0.05, 0.02
p_either = p_bumper + p_cliff - p_both          # addition rule
print('P(bumper or cliff) =', round(p_either, 2))
print('P(neither)         =', round(1 - p_either, 2))
print('union bound        =', round(p_bumper + p_cliff, 2))
P(missed sideways) = 0.3
P(did not dock)    = 0.38
P(wrong distance)  = 0.08
P(not long)        = 0.97
P(bumper or cliff) = 0.11
P(neither)         = 0.89
union bound        = 0.13
An event can be given to prob as a set of outcomes or as a function that answers yes or no for each outcome.

In robotics

A localization grid is a sample space

Divide a corridor into 100 cells of 10 cm. “Rover is in cell ii” for i=1…100i = 1 \dots 100 are mutually exclusive and exhaustive outcomes, provided Rover is in the corridor. A belief is a list of 100 non-negative numbers that sum to 1. Axiom 2 is the reason every filter in this course ends its update with a normalization step: after new evidence is multiplied in, the numbers are rescaled so that they again sum to 1. M6-T2: Histogram Filters and Grid Localization builds this filter.

The same example shows the weak point of axiom 2. If someone carries Rover out of the corridor, the true outcome is not in the sample space, and the filter will still report a confident belief over 100 cells that sums to 1. This is the kidnapped robot problem. The cure is to make the sample space honest, for example by reserving some probability for “somewhere I have no model for” (M9-T4: Monte Carlo Localization in Practice).

Occupancy is a two-outcome sample space

A cell of an occupancy grid map is either occupied or free. By the complement rule only one number has to be stored: P(free)=1−P(occupied)P(\text{free}) = 1 - P(\text{occupied}). M10-T1: Occupancy Grids and the Binary Bayes Filter builds the whole map from that one number per cell.

Safety budgets use the union bound

A hazard analysis lists the ways a system can fail dangerously: the estimator diverges, a sensor freezes, the brake command is late. The failures are not disjoint and their overlaps are rarely known. The union bound gives a guaranteed ceiling: if the three failure modes have probabilities of at most 10−410^{-4}, 2×10−42 \times 10^{-4} and 5×10−55 \times 10^{-5} per hour, the probability of at least one is at most 3.5×10−43.5 \times 10^{-4} per hour. The UAV course applies this in fault tree analysis.

Defining the event is engineering work

“The grasp succeeded”, “the robot is localized”, “the landing was safe” are events only once someone has said precisely which outcomes they contain. Two teams that report a 95% success rate with different definitions of success have measured different events. Write the definition down before you count.

Common misconceptions

“The probability of A or B is P(A) + P(B).”

Only when A and B cannot happen together. In general the overlap P(A and B) must be subtracted. Adding the probabilities of overlapping events is how totals above 1 appear.

“The outcomes are equally likely.”

Nothing in the axioms says so. Dividing 1 by the number of outcomes is a model, appropriate for a fair die or for a robot that truly knows nothing about its starting cell, and wrong for the five outcomes of the docking run.

“The sample space is given by the problem.”

It is a modelling choice, and a different choice gives a different, equally valid description. Five bins, a 10 cm grid and a continuous position are all sample spaces for where Rover stopped. Choose the coarsest one that can still express the events you care about.

“My probabilities sum to 1, so my model is right.”

Summing to 1 shows only that the bookkeeping is consistent. If a real outcome is missing from the sample space, the model will still sum to 1 and still be wrong, confidently.

Key takeaways

  1. A sample space is a list of outcomes that are mutually exclusive and exhaustive. An event is a set of outcomes; a yes-or-no question about the robot is an event.
  2. The three axioms: probabilities are non-negative, the whole sample space has probability 1, and probabilities of disjoint events add.
  3. Complement rule: P(not A) = 1 − P(A). Use it whenever the opposite event is easier to compute.
  4. Addition rule: P(A or B) = P(A) + P(B) − P(A and B). The sum alone is an upper bound (the union bound).
  5. Normalization means “one of the listed outcomes is true”. A filter that normalizes over an incomplete list of outcomes is confidently wrong.

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

A lidar reports, for one beam, one of: a valid range, “no return” or “error”. Over a long log the frequencies are 0.93, 0.05 and 0.04. Can these three numbers be the probabilities of the three outcomes? What are the possible explanations?

Explanation

No: they sum to 1.02, which violates axiom 2 (with axiom 3, since the outcomes are supposed to be disjoint). Either the bins overlap (some beams were logged as both “no return” and “error”, so 0.02 was counted twice) or the frequencies were computed over different numbers of beams, or they were rounded badly. The fix is to define the outcomes so that every beam falls in exactly one bin and recount.

Question 2

A drone’s vision system loses tracking with probability 0.10 on a flight and its GPS drops out with probability 0.04. A report says the probability of losing at least one is 0.14. Under what condition is that exactly right, what can you say without that condition, and what is the probability of losing neither?

Explanation

The 0.14 is exact only if the two losses never occur on the same flight (disjoint events). In general P(either) = 0.10 + 0.04 − P(both). Without knowing the overlap, the union bound gives P(either) ≤ 0.14 and monotonicity gives P(either) ≥ 0.10. So the probability of losing neither is between 0.86 and 0.90. (Both failing together is plausible, for example indoors near windows, so the overlap should be measured.)

Question 3

A grid localizer over a warehouse map reports a belief that sums to 1 and has a sharp peak, yet the robot is in fact in a loading bay that is not on the map. Which axiom is “satisfied but misleading” here, and why?

Explanation

Axiom 2, normalization. It states that one of the outcomes in the sample space is true; the localizer enforces it by rescaling the belief to sum to 1. But the sample space (cells of the map) does not contain the true outcome, so the premise is false. The mathematics is consistent and the result is wrong. Only a sample space that includes “not on the map”, or an external check such as the measurement likelihood being very low everywhere, can reveal it.

What’s next

The axioms say how probabilities must fit together, not how to find them when no formula is at hand. The next lesson finds them by experiment: simulate the robot many times and count.

Next lesson

M1-T3 — Simulating Randomness: Sampling and Monte Carlo

Estimate a probability by repeated simulation with a seeded generator, and say how the error shrinks with the number of runs.

Nothing below is required to finish this lesson.

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