03 BayesCombinatoricsFilled
03 BayesCombinatoricsFilled
P (B|A) P (A)
P (A|B) = .
P (B)
P (A \ B) P (A \ B)
= P (A|B) , and = P (B|A) ,
P (B) P (A)
and so
P (A \ B) = P (A|B) P (B) = P (B|A) P (A) ,
and Bayes’ rule follows immediately.
One of the main applications of Bayes’ rule is for inference from in-
direct observations. The following example is a classic illustration of
this.
39
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Example. The incidence rate for a certain disease is 15/100,000.
There is a test for the disease which is 95% accurate: if a person has
the disease, the test comes back positive with probability 0.95; if a
person does not have the disease, the test comes back negative with
probability 0.95.
Emma goes to the doctor and is given the test as part of a routine
checkup. It comes back positive. What is the probability that Emma
has the disease?
To answer the question, define the events
A = {Emma has the disease}, B = {Emma tested positive}.
We know that
P (A) = 0.00015
P (B|A) = 0.95
P (B c |Ac ) = 0.95, (and so P (B|Ac ) = 1 P (B c |Ac ) = 0.05).
40
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
The preceding example illustrates some general principles that are
valuable to take note of. First, for some probabilities it is some-
times easier to specify conditional probabilities than unconditional
ones (e.g., P (B|A) is easier to specify than P (B)). Second, we often
have easier access to some conditional probabilities than others (e.g.,
P (B|A) is easier to get than P (A|B) because we designed the test
and can evaluate it), but we need Bayes’ rule because the other con-
ditional probability we can’t observe is what we need to answer our
question. Finally, using Bayes’ rule often relies on an unconditional
probability (e.g., P (B)) that we don’t have access to. But, using our
conditional probabilities we can get it by applying the law of total
probability.
Exercise:
Let’s go back to the problem of Robert, the injured star quarterback.
Suppose you could not bear to watch the game, but you find out later
that your team won. What is the probability that Robert played?
Ans. As before we define A to be the event that Robert plays, and
B to be the event that the team wins. We know that P (A) =
0.4, P (Ac ) = 1 P (A) = 0.6, P (B|A) = 0.75 and P (B|Ac ) = 0.35.
Since A and Ac are disjoint sets, we can use the total probability
theorem to write:
41
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Methods for Solving Problems
Let’s take a step back for the moment and review some of the tech-
niques we’ve developed for calculating probabilities.
Enumeration
One technique we have used to compute the probability of an event is
enumerate (i.e., write an explicit list of) all possible outcomes of the
experiment. If the outcomes are equally likely, then the probability
of the event occurring is the ratio of the number of “successes” (i.e.,
the number of outcomes leading to the event) to the total number of
possible outcomes. If the elementary outcomes have di↵erent proba-
bilities, then the probability of the event occurring is the sum of the
probabilities of the outcomes that correspond to a “success”. This is
the method we have used the most so far.
Divide-and-conquer
Another approach (that we discussed at the beginning of this lec-
ture) is the divide-and-conquer approach of splitting up the sample
space into more manageable subsets and calculating the conditional
probabilities for each subset (possibly using Bayes’ rule if necessary),
combining the results using the total probability theorem.
Sequential
When dealing with a sequence of outcomes, it can be useful to break
up the calculation of a particular probability into more manageable
pieces by following along the “history” of the sequence of outcomes.
We have already done this a few times (our use of the multiplication
rule is a prime example), but a couple more examples will hopefully
clarify how this technique can be used to help organize and sometimes
simplify our calculations.
42
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Example. We draw 4 cards from an ordinary 52 card deck. What is
the probability that we draw at four “Aces”?
To answer this, let
A1 = {the 1st card is an Ace}
...
What is the probability that you come out ahead? (That is, what is
the probability that you win at least two of the bets?)
43
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
You can think about this by drawing a tree with 3 levels, where the
edges depict you winning or losing certain bets, and we label the
nodes with the probability that we arrive there.
L W 1/4 WLW
W
1/3
L 1/12 WLL
W 1/8 LWW
1/6
L W
L 1/24 LWL
1/3
W 1/8 LLW
L
1/6
L 1/24 LLL
1 1
Thus, our probability of winning at least two of the bets is: 4 + 12 +
1 1 17
4 + 8 = 24 ⇡ 0.71.
PLWWWUWWLUWLWULWW
Now, what happens if we only have 10 to wager (so that if we lose
the first bet, we no longer have enough money to continue)?
The probability is now 14 + 12 + 14 = 12
7
⇡ 0.58. Note how easy this
I diagram.
calculation was given the tree
44
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
In this example, each outcome is independent of the other, but they
occur with di↵erent probabilities (as opposed to a sequence of fair
coin tosses) and the order in which they occur can be important. In
such cases the sequential method, sometimes with accompanying dia-
grams, can be a useful way to keep track of the relevant probabilities.
Ultimately, this is not really dramatically di↵erent from just enumer-
ating the possible outcomes and adding up the relevant possibilities,
but it often provides a useful way to organize the calculations (and
can also be very useful in situations where direct enumeration is not
possible).
The next example shows that the same approach can also be very
handy when the sequence of outcomes are not independent.
Exercise:
We draw 3 cards from an ordinary 52 card deck. What is the proba-
bility that we draw at least two hearts?
Using a similar tree structure as before one can calculate that the
probability of three hearts is given by
13 12 11
· ·
52 51 50
and the probability for any of the three sequences resulting in exactly
two hearts is
13 12 39
· · .
52 51 50
Adding these up results in a probability of approximately 0.15.
45
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Counting
You may have noticed that all the problems we’ve been talking about
so far have involved experiments with only a small number of out-
comes (e.g., experiments with only two outcomes, repeated only two
or three times). Strategies where we explicitly enumerate all possible
outcomes (or draw a tree showing all possible outcomes) are no longer
feasible when the number of outcomes gets much larger than this. To
handle cases where the number of outcomes is rather large, we typi-
cally have to simplify our calculations carefully counting the number
of ways a certain event can occur without explicitly listing them all.
We’ve already done this a few times (e.g., we have used the fact that
there are 210 possible outcomes if we toss a coin ten times without
ever listing all 210 possibilities) but we haven’t discussed principled
methods for handling more complicated scenarios yet.
There is an entire branch of mathematics — called combinatorics —
that deals with problems of this type. We will of course only scratch
the surface in this course, but we will end up acquiring some powerful
tools.
46
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
The counting principle
Many counting problems can be naturally broken down into multiple
stages. If the outcomes at one stage do not a↵ect the number of
possibilities at the subsequent stages, we can just multiply the number
of possibilities at each stage together. To formalize this, suppose that
our problem has S stages, and that:
1. there are n1 possibilities at stage 1;
2. for every possible result at the first stage, there are n2 possible
results at the second stage;
3. for any sequence of results at the first i 1 stages there are ni
possibilities at stage i;
then the total number of possible results is
n1 · n2 · · · nS
47
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Example. How many three letter strings are there using the letters
“a”–“z”?.
Example. How many three letter strings are there where the second
letter is a vowel?
Ans. 26 · 5 · 26 = 3380.
Example. How many three letter strings are there where the first
letter is a consonant, the second letter is a vowel, and the third letter
is a consonant?
Ans. 21 · 5 · 21 = 2205.
Example. How many three letter strings are there so that no two
consecutive letters are the same?
Example. How many three letter strings are there that do not in-
clude any repeated letters?
Example. How many five letter strings are there that start with a
consonant and end with “y”?
48
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Sometimes we are interested in a sequence of events where the num-
ber of possibilities at the next stage depends on the outcome of the
previous stages. While the goal is still to count the number of leaves,
we now need to enumerate the di↵erent possible paths for getting
from left to right in the tree.
Example. How many three letter strings are there that do not have
consecutive vowels?
Example. How many three letter strings have two or fewer conso-
nants?
Ans. 5 · 26 · 26 + 21 · 5 · 26 + 21 · 21 · 5 = 8315.
Ans. 3 + 3 · 2 + 3 = 12.
Example. How many five letter strings start with “t”, end with “n”,
and have no two consecutive letters the same?
Ans. This one is pretty tricky. There are several way to try to get the
answer, but the easiest way to think about this involves breaking the
problem into three cases: “t” in the middle, “n” in the middle, and
neither “t” nor “n” in the middle. By counting up these possibilities
we get 25 · 24 + 24 · 25 + 243 = 15, 024.
We can use the counting principle to derive expressions for four gen-
eral types of calculations that often come up: permutations, k-
permutations, combinations and partitions.
49
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Permutations
How many ways can I order a set of n objects?
There are n choices for the first position, then n 1 choices for the
second, then n 2 for the third, etc:
Ans. 4! = 4 · 3 · 2 · 1 = 24.
50
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
k-permutations
More generally, we might want to count the number of ways we can
pick an ordered subset of size k from a larger set of size n.
As before, there are n choices for the first stage, n 1 for the second,
and so on, but there are only k stages:
n!
n(n 1)(n 2) · · · (n k + 1) =
(n k)!
Ans. There are 20! ways the horses can be ordered. Given the first
three slots, we do not care about the ordering of the last 17, so we
divide by 17!. This yields
20!
= 20 · 19 · 18 = 6840.
17!
Combinations
We have a set of size n. How many subsets of size k are there?
In this case, the ordering of the subset does not matter. For
example, all of the 2-permutations of the letters A,B,C are
AB, BA, AC, CA, BC, CB (6 total),
while all the 2-letter combinations are
AB, AC, BC (3 total)
51
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
The number of k-combinations is simply the number of k-permutations
divided by the number of “duplicates” ... since we can order a set of
size k in k! di↵erent ways:
✓ ◆
n n!
“n choose k” = =
k (n k)!k!
Ans. ✓ ◆
12 12! 12 · 11 · 10 · 9 · 8
= = = 11 · 9 · 8 = 792.
5 7!5! 5·4·3·2
Ans. You can think of this as the number of ways you can choose the
4 locations (out of 10 possible) for the ones, and
✓ ◆
10 10! 10 · 9 · 8 · 7
= = = 210.
4 6!4! 4·3·2·1
52
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Think of it as many
Partitions combinations
We answer this by forming the subsets in stages. The first subset can
be formed in nn1 ways. For the second, n n1 elements remain, and
so there are n n2n1 possibilities, etc.
n! (n n1 )! (n n1 · · · nr 1 )!
· ···
n!(n n1 )! n2 !(n n1 n2 )! nr !(n n1 · · · nr )!
n!
= .
n1 !n2 ! · · · nr !
This has the special notation
✓ ◆
n n!
= ,
n 1 , n2 , . . . , n r n1 ! · · · nr !
53
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Example (Anagrams). How many di↵erent words can be obtained
by rearranging the letters in the word BANANA?
Ans. We can think of having six slots for letters that we want to
partition into subsets of size 3 (for the As), 2 (for the Ns) and 1 (for
the B). The number of such partitions is
✓ ◆
I
6 6!
= = 60.
3, 2, 1 3!2!1!
Summary
To summarize all in one place, we can use the counting principle to
derive expressions for four types of calculations.
Permutations. How many ways can I order a set of n objects?
Answer: n! = n(n 1)(n 2) · · · 2 · 1
54
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Bernoulli trials
A Bernoulli trial is a random experiment with two outcomes, generi-
cally labeled “success” and “failure” (or “heads”/“tails”, “yes”/“no”,
“1”/“0”, “win”/“loss”, etc.) We will use p to denote the probability
of success:
p = P (success) and so 1 p = P (failure) .
The phrase Bernoulli trials refers to a sequence of independent ex-
periments of this type.
55
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
In general, for any specific sequence with k successes in n trials, the
probability of that sequence is pk (1 p)n k . Moreover, there are nk
possible sequences, and thus
✓ ◆
n k
P (exactly k successes out of n) = p (1 p)n k ,
k
and
n ✓ ◆
X n
P (at least k successes out of n) = pi (1 p)n i .
i
i=k
56
ECE 3077 Notes by M. Davenport, J. Romberg, C. Rozell, and M. Wakin. Last updated 11:55, August 30, 2023
Blue 2 213 7
1167 i
I
1
41