Outcomes, events and counting
The sample space, events as sets and their operations, the classical model with equally likely outcomes, the product rule, the four ways to choose k out of n, and the birthday problem.
What can happen
The topic What probability is counted outcomes informally: three even faces out of six, nine sick patients among 98 positive tests. It promised to make that counting precise. First we need an exact answer to a simpler question: what exactly receives a probability?
Start with an experiment: anything whose result we cannot predict in advance. Rolling two dice, shuffling a training set, testing a classifier. An outcome is one complete result of the experiment, recorded in full. The sample space is the set of all outcomes.
For two dice, an outcome is an ordered pair: what the first die shows and what the second shows. So
where counts the elements of a set.
An event is a set of outcomes, . The event "the sum is 7" is
The experiment produces one outcome . The event occurs if .
The same language fits machine learning. Run a classifier on three test examples and write for an error and for a correct answer. An outcome is the error pattern, a string like , and holds the strings from to . "Exactly one error" is the event . Any statement you can check from the outcome alone defines an event.
Events as sets
Because events are sets, the words we use about them become set operations.
- " or " is the union : the outcome lies in at least one of them.
- " and " is the intersection : the outcome lies in both.
- "not " is the complement .
The whole space is the event that always occurs, and the empty set is the event that never does. Events with are disjoint: they cannot occur together.
Complements of unions and intersections follow De Morgan's laws:
"Not (A or B)" means "neither A nor B", and that is all the first law says.
Here is why they are useful. Let be "the first die shows a six" and "the second die shows a six". "At least one six" is . Counting it directly as is wrong: the outcome lies in both events and gets counted twice. The complement is easier. By De Morgan, is "no six", and each die then has 5 possible values, so there are such outcomes. Hence "at least one six" has outcomes.
When "at least one" is hard to count, count "none" and subtract.
Equally likely outcomes
The classical reading from What probability is now gets a precise form, the classical model. If is finite and all its outcomes are equally likely, then
For two fair dice, "the sum is 7" gets , and "at least one six" gets .
The formula is only as good as its assumption, and whether outcomes are equally likely depends on how we write them down. Toss two coins and record only the number of heads: . These three outcomes are not equally likely. Record the coins in order instead: . Now symmetry does make all four equally likely, and "exactly one head" is , with probability , not .
Even d'Alembert slipped here. He argued that "at least one head in two tosses" has probability , treating "heads first", "tails then heads" and "two tails" as equally likely. The ordered space gives .
The rule of thumb: keep order and identity. Paint one die red and one blue, number the coins, label the people, even if the question does not care. Coins do not know they look alike. Once the outcomes are symmetric, count the event inside that space.
The product rule
Listing outcomes works for two dice. It does not work for a password or for a shuffled dataset. We need rules that count without listing, and the first one does most of the work.
Product rule. Suppose an outcome is built in stages, with choices at the first stage, at the second, and so on. Then the number of outcomes is
There is one condition: the number of choices at each stage must not depend on what was chosen earlier. Which choices are available may change; how many may not. When the count does change, split into cases, count each case with the rule and add.
Some examples.
- Two dice: .
- An 8-character password over 62 symbols (letters in two cases and digits): .
- A hyperparameter grid with 4 learning rates, 3 batch sizes and 2 optimizers: training runs.
- The orders of distinct training examples: choices for the first place, for the second, down to . That is , with by convention. Ten examples already have orders.
The last line is why "shuffle the data" is a random experiment with an enormous sample space, even for a tiny dataset.
Four ways to choose k out of n
Many counting problems are the same problem: choose items out of . Two questions decide the formula. Does the order matter? Can an item be chosen again (with replacement)? Here are the four answers, with the counts for , .
| Order | Replacement | Count | , |
|---|---|---|---|
| matters | with | ||
| matters | without | ||
| does not | without | ||
| does not | with |
The first two rows are the product rule. For the third, each set of items appears in the second row in different orders, so divide by . This binomial coefficient , read " choose ", counts subsets: a lottery ticket of 6 numbers out of 49 is one of , and a minibatch of distinct examples out of , taken as a set, is one of .
The fourth row comes from stars and bars. Write the chosen items as stars and separate the kinds with bars; for example, says "two of the first kind, one of the third". Every such row of symbols is one result, and it is fixed by where the stars go.
One warning about that row. It counts distinct results, not equally likely outcomes. Two dice have unordered results, but has probability and only . The classical model needs the ordered space underneath.
The birthday problem
Now a famous surprise: in a group of just 23 people, two share a birthday with probability above one half. Counting explains why.
Assume 365 equally likely birthdays and ignore leap years. Keep identity: an outcome is the ordered list of the birthdays, so , all equally likely. Lists with all birthdays different are ordered choices without replacement, of them. Hence
For this is , so a shared birthday has probability . For it is already .
Why so few people? A shared birthday needs only some pair to match, and 23 people form pairs. Intuition counts people; the event is about pairs.
The same calculation appears whenever values are drawn uniformly with replacement from possibilities:
A minibatch sampled with replacement from the dataset may contain the same example twice. Random hashes of items into buckets collide. In both cases repeats appear once is around , far earlier than .
Drawing without replacement
When we draw without replacement and do not care about the order, the outcomes are subsets. All of them are equally likely when the draw is fair, so the classical model applies directly.
Take a five-card hand from a 52-card deck. There are hands. A hand with exactly two aces is built in two stages: choose which 2 of the 4 aces, then which 3 of the 48 other cards. By the product rule,
The recipe is general: split the population into groups and choose the required number from each group.
Does replacement change the answer much? An urn holds 3 red and 2 blue balls, and we draw two. Without replacement the second draw sees one red ball fewer:
With 300 red and 200 blue balls the two answers are and . The gap shrinks as the population grows. That is why a test set drawn without replacement from millions of possible inputs is treated as if every draw were made from the same, unchanged population.
Where counting stops
Counting gave exact answers for dice, cards, passwords, birthdays and minibatches. It rests on two assumptions, and ML breaks both of them all the time.
Equally likely outcomes. A loaded die has six outcomes, but not six equal shares. The error patterns of a classifier from the first block are not equally likely either: a model that is right 90% of the time produces far more often than . A language model's next token is a choice among tens of thousands of tokens with very different probabilities.
A finite sample space. The number of tosses until the first head can be any of . A random point in , a waiting time, a model weight at initialization: these take infinitely many values, and means nothing there.
Even inside the classical model, most errors are hidden order or hidden identity: counting and as one outcome, or as two when they are one. Listing a small case by hand, or a quick simulation as in What probability is, catches most of them.
So we keep what this topic built: the sample space , events as subsets, and "or", "and", "not" as union, intersection and complement. What we replace is the recipe . The next topic, Kolmogorov's axioms, makes probability a function on events that obeys three rules. Counting becomes one special case, and loaded dice and points on a segment fit in as well.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.