Skip to content
BIASED

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 ω\omega is one complete result of the experiment, recorded in full. The sample space Ω\Omega 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

Ω={(1,1),(1,2),…,(6,6)},∣Ω∣=36,\Omega = \{(1,1), (1,2), \dots, (6,6)\}, \qquad |\Omega| = 36,

where ∣⋅∣|\cdot| counts the elements of a set.

An event is a set of outcomes, A⊆ΩA \subseteq \Omega. The event "the sum is 7" is

A={(1,6),(2,5),(3,4),(4,3),(5,2),(6,1)}.A = \{(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)\}.

The experiment produces one outcome ω\omega. The event AA occurs if ω∈A\omega \in A.

The same language fits machine learning. Run a classifier on three test examples and write 11 for an error and 00 for a correct answer. An outcome is the error pattern, a string like 010010, and Ω\Omega holds the 88 strings from 000000 to 111111. "Exactly one error" is the event {100,010,001}\{100, 010, 001\}. 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.

  • "AA or BB" is the union A∪BA \cup B: the outcome lies in at least one of them.
  • "AA and BB" is the intersection A∩BA \cap B: the outcome lies in both.
  • "not AA" is the complement Ac=Ω∖AA^c = \Omega \setminus A.

The whole space Ω\Omega is the event that always occurs, and the empty set ∅\varnothing is the event that never does. Events with A∩B=∅A \cap B = \varnothing are disjoint: they cannot occur together.

Complements of unions and intersections follow De Morgan's laws:

(A∪B)c=Ac∩Bc,(A∩B)c=Ac∪Bc.(A \cup B)^c = A^c \cap B^c, \qquad (A \cap B)^c = A^c \cup B^c.

"Not (A or B)" means "neither A nor B", and that is all the first law says.

Here is why they are useful. Let A1A_1 be "the first die shows a six" and A2A_2 "the second die shows a six". "At least one six" is A1∪A2A_1 \cup A_2. Counting it directly as 6+6=126 + 6 = 12 is wrong: the outcome (6,6)(6,6) lies in both events and gets counted twice. The complement is easier. By De Morgan, (A1∪A2)c=A1c∩A2c(A_1 \cup A_2)^c = A_1^c \cap A_2^c is "no six", and each die then has 5 possible values, so there are 5⋅5=255 \cdot 5 = 25 such outcomes. Hence "at least one six" has 36−25=1136 - 25 = 11 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 Ω\Omega is finite and all its outcomes are equally likely, then

P(A)=∣A∣∣Ω∣.P(A) = \frac{|A|}{|\Omega|}.

For two fair dice, "the sum is 7" gets 6/36=1/66/36 = 1/6, and "at least one six" gets 11/3611/36.

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: Ω={0,1,2}\Omega = \{0, 1, 2\}. These three outcomes are not equally likely. Record the coins in order instead: Ω={HH,HT,TH,TT}\Omega = \{HH, HT, TH, TT\}. Now symmetry does make all four equally likely, and "exactly one head" is {HT,TH}\{HT, TH\}, with probability 2/4=1/22/4 = 1/2, not 1/31/3.

Even d'Alembert slipped here. He argued that "at least one head in two tosses" has probability 2/32/3, treating "heads first", "tails then heads" and "two tails" as equally likely. The ordered space gives 3/43/4.

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 kk stages, with n1n_1 choices at the first stage, n2n_2 at the second, and so on. Then the number of outcomes is

n1⋅n2⋯nk.n_1 \cdot n_2 \cdots n_k.

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: 6⋅6=366 \cdot 6 = 36.
  • An 8-character password over 62 symbols (letters in two cases and digits): 628≈2.2⋅101462^8 \approx 2.2 \cdot 10^{14}.
  • A hyperparameter grid with 4 learning rates, 3 batch sizes and 2 optimizers: 4⋅3⋅2=244 \cdot 3 \cdot 2 = 24 training runs.
  • The orders of nn distinct training examples: nn choices for the first place, n−1n-1 for the second, down to 11. That is n!=n(n−1)⋯1n! = n(n-1)\cdots 1, with 0!=10! = 1 by convention. Ten examples already have 10!=3,628,80010! = 3{,}628{,}800 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 kk items out of nn. 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 n=4n = 4, k=2k = 2.

Order Replacement Count n=4n = 4, k=2k = 2
matters with nkn^k 1616
matters without n(n−1)⋯(n−k+1)=n!(n−k)!n(n-1)\cdots(n-k+1) = \dfrac{n!}{(n-k)!} 1212
does not without (nk)=n!k! (n−k)!\dbinom{n}{k} = \dfrac{n!}{k!\,(n-k)!} 66
does not with (n+k−1k)\dbinom{n+k-1}{k} 1010

The first two rows are the product rule. For the third, each set of kk items appears in the second row in k!k! different orders, so divide by k!k!. This binomial coefficient (nk)\binom{n}{k}, read "nn choose kk", counts subsets: a lottery ticket of 6 numbers out of 49 is one of (496)=13,983,816\binom{49}{6} = 13{,}983{,}816, and a minibatch of kk distinct examples out of nn, taken as a set, is one of (nk)\binom{n}{k}.

The fourth row comes from stars and bars. Write the kk chosen items as stars and separate the nn kinds with n−1n - 1 bars; for example, ⋆⋆∣ ∣⋆∣\star\star|\,|\star| says "two of the first kind, one of the third". Every such row of n+k−1n + k - 1 symbols is one result, and it is fixed by where the kk stars go.

One warning about that row. It counts distinct results, not equally likely outcomes. Two dice have (72)=21\binom{7}{2} = 21 unordered results, but {1,2}\{1, 2\} has probability 2/362/36 and {1,1}\{1, 1\} only 1/361/36. 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 nn birthdays, so ∣Ω∣=365n|\Omega| = 365^n, all equally likely. Lists with all birthdays different are ordered choices without replacement, 365⋅364⋯(365−n+1)365 \cdot 364 \cdots (365 - n + 1) of them. Hence

P(all different)=365⋅364⋯(365−n+1)365n.P(\text{all different}) = \frac{365 \cdot 364 \cdots (365 - n + 1)}{365^n}.

For n=23n = 23 this is 0.49270.4927, so a shared birthday has probability 0.50730.5073. For n=50n = 50 it is already 0.9700.970.

Why so few people? A shared birthday needs only some pair to match, and 23 people form (232)=253\binom{23}{2} = 253 pairs. Intuition counts people; the event is about pairs.

The same calculation appears whenever kk values are drawn uniformly with replacement from NN possibilities:

P(all distinct)=N(N−1)⋯(N−k+1)Nk.P(\text{all distinct}) = \frac{N(N-1)\cdots(N-k+1)}{N^k}.

A minibatch sampled with replacement from the dataset may contain the same example twice. Random hashes of kk items into NN buckets collide. In both cases repeats appear once kk is around N\sqrt N, far earlier than k≈Nk \approx N.

Drawing without replacement

When we draw without replacement and do not care about the order, the outcomes are subsets. All (nk)\binom{n}{k} 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 (525)=2,598,960\binom{52}{5} = 2{,}598{,}960 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,

P(exactly two aces)=(42)(483)(525)=6⋅17,2962,598,960≈0.0399.P(\text{exactly two aces}) = \frac{\binom{4}{2}\binom{48}{3}}{\binom{52}{5}} = \frac{6 \cdot 17{,}296}{2{,}598{,}960} \approx 0.0399.

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:

P(both red)=35⋅24=0.30,with replacement: (35)2=0.36.P(\text{both red}) = \frac{3}{5} \cdot \frac{2}{4} = 0.30, \qquad \text{with replacement: } \left(\frac{3}{5}\right)^2 = 0.36.

With 300 red and 200 blue balls the two answers are 0.35950.3595 and 0.360.36. 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 000000 far more often than 111111. 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 1,2,3,…1, 2, 3, \dots. A random point in [0,1][0, 1], a waiting time, a model weight at initialization: these take infinitely many values, and ∣A∣/∣Ω∣|A|/|\Omega| means nothing there.

Even inside the classical model, most errors are hidden order or hidden identity: counting (a,b)(a, b) and (b,a)(b, a) 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 Ω\Omega, events as subsets, and "or", "and", "not" as union, intersection and complement. What we replace is the recipe P(A)=∣A∣/∣Ω∣P(A) = |A|/|\Omega|. 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.

Full notes

Answers are saved on the server and tied to this browser until you sign in.