Writing

An Introduction to Probability and Random Variables for Pattern Recognition 1

19 January 2018Updated 14 October 20269 min read

An introduction to the probability theory behind statistical pattern recognition. This first part covers the axioms of probability, conditional probability, independence and the law of total probability through worked examples.

Axioms

The theory of probability forms the backbone of learning and research in statistical pattern recognition. Probability theory is one of the most amazing fields of mathematics, and it rests on three simple axioms.

  1. The probability of an event AA, written p(A)p(A), is greater than or equal to zero.

    p(A)≥0p(A) \ge 0
  2. If AA and BB are mutually exclusive, which means they cannot happen together, then the probability of AA or BB is the probability of AA plus the probability of BB.

    p(A∪B)=p(A)+p(B)if A∩B=∅p(A \cup B) = p(A) + p(B) \quad \text{if } A \cap B = \emptyset

    The formal statement of this axiom extends the rule to any countable collection of mutually exclusive events.

  3. The probability of the entire sample space S\mathcal{S} is 11.

    p(S)=1p(\mathcal{S}) = 1

These three axioms make probability theory self-checking. No probability is less than 00, and the probabilities of all the outcomes in a discrete sample space add up to 11. Also observe that the only arithmetic operator in the axioms is the ++ (plus) sign. When we begin to combine and apply the axioms, the other arithmetic operations begin to emerge.

Suppose we have a sample space S\mathcal{S} with six outcomes, 11 to 66, and the probabilities shown in Figure 1 below.

A circle labelled S containing six outcomes: 1 with probability 0.1, 2 with 0.1, 3 with 0.3, 4 with 0.1, 5 with 0.2 and 6 with 0.2
Figure 1: A sample space with six outcomes and their probabilities.

Let us check that this sample space is valid:

  1. Is every probability greater than or equal to zero? Yes.
  2. Do the probabilities add up to 11? Yes. 0.1+0.1+0.3+0.1+0.2+0.2=10.1 + 0.1 + 0.3 + 0.1 + 0.2 + 0.2 = 1.
  3. The outcomes are mutually exclusive. So we can find the probability of any event by adding the probabilities of its outcomes. For example:
p(even)=p({2,4,6})=p(2)+p(4)+p(6)=0.1+0.1+0.2=0.4\begin{aligned} p(\text{even}) &= p(\{2, 4, 6\}) \\ &= p(2) + p(4) + p(6) \\ &= 0.1 + 0.1 + 0.2 = 0.4 \end{aligned}

Dependence: Conditional Probability

The probability of event AA given that event BB has already occurred is written p(A∣B)p(A \mid B). The vertical bar "∣\mid" reads "given". p(A∣B)p(A \mid B) is the probability that both AA and BB occur, p(AB)p(AB), divided by the probability of BB, p(B)p(B). The definition holds when p(B)>0p(B) > 0.

p(A∣B)≜p(AB)p(B)\boxed{p(A \mid B) \triangleq \frac{p(AB)}{p(B)}}

This formula is intuitive. Suppose we want the probability of a 33 given that the outcome is odd, p(3∣odd)p(3 \mid \text{odd}). If we keep only the odd outcomes from the sample space, their probabilities are 0.10.1, 0.30.3 and 0.20.2. These add up to 0.60.6, so they no longer form a valid probability distribution. We normalize them by dividing each probability by their sum, 0.60.6, as shown in Figure 2. We can then read the probability of a 33 from the normalized sample space.

A circle labelled S containing only the odd outcomes: 1 with 0.1/0.6, 3 with 0.3/0.6 and 5 with 0.2/0.6, with a note that 0.6 is the combined probability of the new sample space
Figure 2: The new sample space of odd outcomes, normalized by their total probability of 0.6.

The outcome 33 is odd, so the event "33 and odd" is the event "33". The result is:

p(3∣odd)=p(3)p(odd)=0.30.6=0.5p(3 \mid \text{odd}) = \frac{p(3)}{p(\text{odd})} = \frac{0.3}{0.6} = 0.5

Rearranging the definition gives the product rule:

p(A∣B)=p(AB)p(B)we then derive that:p(AB)=p(A∣B) p(B)(1)\boxed{ \begin{gathered} p(A \mid B) = \frac{p(AB)}{p(B)} \\ \text{we then derive that:} \\ p(AB) = p(A \mid B) \, p(B) \end{gathered} } \tag{1}

Independence

Two events AA and BB are independent if knowing that BB occurred tells us nothing about whether AA occurs. Suppose we are asked for the probability of a 33 given that it snowed in Lagos, p(3∣snowed in Lagos)p(3 \mid \text{snowed in Lagos}). The answer is simply p(3)p(3), because whether it snowed in Lagos has no bearing on the outcome. Formally, AA and BB are independent when p(AB)=p(A) p(B)p(AB) = p(A) \, p(B). When p(B)>0p(B) > 0, this is the same as saying p(A∣B)=p(A)p(A \mid B) = p(A):

p(A∣B)=p(A)and from Equation (1):p(AB)=p(A∣B) p(B)∴  p(AB)=p(A) p(B)(2)\boxed{ \begin{gathered} p(A \mid B) = p(A) \\ \text{and from Equation (1):} \\ p(AB) = p(A \mid B) \, p(B) \\ \therefore \; p(AB) = p(A) \, p(B) \end{gathered} } \tag{2}

Total Probability

Suppose a random variable XX takes the values 11 to 66, and its distribution depends on a second random variable YY. YY has two outcomes, 00 and 11, with p(Y=0)=0.4p(Y = 0) = 0.4 and p(Y=1)=0.6p(Y = 1) = 0.6. When Y=0Y = 0, we draw XX from the distribution on the left of Figure 3. When Y=1Y = 1, we draw XX from the distribution on the right.

Two circles showing p(X). The left circle, used when Y is 0 with probability 0.4, gives outcomes 1 to 6 the probabilities 0.1, 0.3, 0.25, 0.25, 0.05 and 0.05. The right circle, used when Y is 1 with probability 0.6, gives them 0.2, 0.1, 0.2, 0.1, 0.2 and 0.2.
Figure 3: Two distributions for X. The value of Y decides which one we draw from.

Suppose we are asked:

  • What is the probability that X=3X = 3 given Y=0Y = 0, p(X=3∣Y=0)p(X = 3 \mid Y = 0)? We read the answer, 0.250.25, from the distribution of XX when Y=0Y = 0.
  • What is the probability that X=4X = 4 given Y=1Y = 1, p(X=4∣Y=1)p(X = 4 \mid Y = 1)? We read the answer, 0.10.1, from the distribution of XX when Y=1Y = 1.

Now suppose we are asked for the probability that X=3X = 3, p(X=3)p(X = 3). We cannot read this from either distribution because we are not told the value of YY. We can still derive it. The events {X=3,Y=0}\{X = 3, Y = 0\} and {X=3,Y=1}\{X = 3, Y = 1\} are mutually exclusive, and together they make up the event {X=3}\{X = 3\}. The second axiom lets us add their probabilities, and the product rule in Equation (1) gives each of them:

p(X=3)=p(X=3,Y=0)+p(X=3,Y=1)=p(X=3∣Y=0) p(Y=0)+p(X=3∣Y=1) p(Y=1)=(0.25)(0.4)+(0.2)(0.6)=0.1+0.12=0.22\begin{aligned} p(X=3) &= p(X=3, Y=0) + p(X=3, Y=1) \\ &= p(X=3 \mid Y=0) \, p(Y=0) + p(X=3 \mid Y=1) \, p(Y=1) \\ &= (0.25)(0.4) + (0.2)(0.6) \\ &= 0.1 + 0.12 \\ &= 0.22 \end{aligned}

In general, when the outcomes of YY are mutually exclusive and cover every possibility, the law of total probability states:

p(X=x)=∑yp(X=x∣Y=y) p(Y=y)(3)p(X = x) = \sum_{y} p(X = x \mid Y = y) \, p(Y = y) \tag{3}

Ekaba Bisong is a Ph.D. researcher at the University of Victoria and the founder of SiliconBlast. More about me